Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e581faf

Browse files
committed
Updates
1 parent 4d3684f commit e581faf

16 files changed

+42
-14
lines changed

integration_tests/elemental_09.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ def test_numpy_mod():
55
q1: i64[32, 16, 7] = empty((32, 16, 7), dtype=int64)
66
d1: i64[32, 16, 7] = empty((32, 16, 7), dtype=int64)
77
r1: i64[32, 16, 7] = empty((32, 16, 7), dtype=int64)
8+
r1neg: i64[32, 16, 7] = empty((32, 16, 7), dtype=int64)
9+
q2: i64[100] = empty(100, dtype=int64)
810
d2: i64[100] = empty(100, dtype=int64)
911
r2: i64[100] = empty(100, dtype=int64)
1012
i: i32; j: i32; k: i32
13+
rem: i64; q: i64; d: i64
1114

1215
for i in range(32):
1316
for j in range(16):
@@ -16,11 +19,17 @@ def test_numpy_mod():
1619
q1[i, j, k] = (i + j) * (k + 1) + k
1720

1821
r1 = mod(q1, d1)
22+
r1neg = mod(-q1, d1)
1923

2024
for i in range(32):
2125
for j in range(16):
2226
for k in range(7):
2327
assert r1[i, j, k] == k
28+
if k == 0:
29+
rem = 0
30+
else:
31+
rem = d1[i, j, k] - k
32+
assert r1neg[i, j, k] == rem
2433

2534
for i in range(32):
2635
for j in range(16):
@@ -50,5 +59,20 @@ def test_numpy_mod():
5059
for i in range(100):
5160
assert r2[i] == 100 % (i + 1)
5261

62+
for i in range(100):
63+
d2[i] = 50 - i
64+
q2[i] = 39 - i
65+
66+
r2 = mod(q2, d2)
67+
68+
for i in range(100):
69+
d = 50 - i
70+
q = 39 - i
71+
rem = r2[i]
72+
if d == 0:
73+
assert rem == 0
74+
else:
75+
assert int((q - rem)/d) - (q - rem)/d == 0
76+
5377

5478
test_numpy_mod()

src/runtime/lpython_intrinsic_numpy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,13 @@ def radians(x: f32) -> f32:
300300
@overload
301301
@vectorize
302302
def mod(x1: i64, x2: i64) -> i64:
303+
if x2 == 0:
304+
return int(0)
303305
return x1 % x2
304306

305307
@overload
306308
@vectorize
307309
def mod(x1: i32, x2: i32) -> i32:
310+
if x2 == 0:
311+
return 0
308312
return x1 % x2

tests/reference/asr-array_01_decl-39cf894.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-array_01_decl-39cf894.stdout",
9-
"stdout_hash": "10ee8079a365b996b100fabb7eae0db09526cba3fc5d4f6e0adce8bc",
9+
"stdout_hash": "5dbfa7830c3056596fb006d4ce72000c4110ad6ac20fd63b2a37f2d4",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-array_01_decl-39cf894.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/asr-array_02_decl-e8f6874.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-array_02_decl-e8f6874.stdout",
9-
"stdout_hash": "d3f35941edd80d337dacf9e065eefc924d3a76216145e18a9c12ba34",
9+
"stdout_hash": "c727a5665a006349b9b4636b6d63b872693b7045e2fe237903338bec",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-array_02_decl-e8f6874.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/asr-elemental_01-b58df26.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-elemental_01-b58df26.stdout",
9-
"stdout_hash": "bfc4c222e5b551ff211fed8afcb0cd6040ba7ffc51c5a97902ebc5b6",
9+
"stdout_hash": "b440c1ad2402caf7631cdcabb9ab58cd2c5ea0e43f3318f68b0cc522",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-elemental_01-b58df26.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/asr-test_numpy_03-e600a49.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-test_numpy_03-e600a49.stdout",
9-
"stdout_hash": "a768ef3f226aa84ccab6c6e5f6041674690d3cab49206ee21cda93e1",
9+
"stdout_hash": "2f83ebb90ac4c253588a6e51332f01cc3a7da6b26f90d53f6169e36c",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-test_numpy_03-e600a49.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/asr-test_numpy_04-ecbb614.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-test_numpy_04-ecbb614.stdout",
9-
"stdout_hash": "44c4f295662a8d3f905bf93d5e46d3a271c128b61d994ba8f90b86dc",
9+
"stdout_hash": "fd747ab5842e814dfc9488220b313fd4efa43c56fe13b9787ac3322b",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-test_numpy_04-ecbb614.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/asr-vec_01-66ac423.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-vec_01-66ac423.stdout",
9-
"stdout_hash": "711dc7b9b95542bfab629fe75a1d214748937af2b489aab3f15685a9",
9+
"stdout_hash": "a3eabb17c697fd11be32cbb197f603e066e05508bf0d6fc666a86226",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-vec_01-66ac423.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/pass_loop_vectorise-vec_01-be9985e.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "pass_loop_vectorise-vec_01-be9985e.stdout",
9-
"stdout_hash": "8cf21e074991c289af5c44186ef598a5b5c96a471e2f76a77bc8298b",
9+
"stdout_hash": "43a94edc12dc8d4f9c3d5aa2216c001c6f78f8b6a0c334c0921773bf",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/pass_loop_vectorise-vec_01-be9985e.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)