Skip to content

Commit 9f7fb7c

Browse files
authored
Fix reoccurring overflow errors (pyccel#2037)
The `test_sum_matching_types` often fails due to overflow errors while calling `np.isclose`. This PR decreases the size of the complex values being tested to try and stop these errors occurring.
1 parent eb377ee commit 9f7fb7c

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

tests/epyccel/recognised_functions/test_numpy_types.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,13 @@ def add_numpy_to_numpy_type(np_s_l : 'T', np_s_r : 'D'):
111111
assert pyccel_result == python_result
112112
assert isinstance(pyccel_result, type(python_result))
113113

114-
pyccel_result = epyccel_func(integer64, fl32)
115-
python_result = add_numpy_to_numpy_type(integer64, fl32)
116-
assert pyccel_result == python_result
117-
assert isinstance(pyccel_result, type(python_result))
118-
119-
pyccel_result = epyccel_func(integer64, fl64)
120-
python_result = add_numpy_to_numpy_type(integer64, fl64)
121-
assert pyccel_result == python_result
122-
assert isinstance(pyccel_result, type(python_result))
123-
124-
pyccel_result = epyccel_func(fl64, complex64)
125-
python_result = add_numpy_to_numpy_type(fl64, complex64)
126-
assert pyccel_result == python_result
127-
assert isinstance(pyccel_result, type(python_result))
128-
129-
pyccel_result = epyccel_func(complex128, fl64)
130-
python_result = add_numpy_to_numpy_type(complex128, fl64)
131-
assert pyccel_result == python_result
132-
assert isinstance(pyccel_result, type(python_result))
114+
for type1, type2 in ((integer64, fl32), (integer64, fl64), (fl64, complex64), (complex128, fl64)):
115+
pyccel_result = epyccel_func(type1, type2)
116+
python_result = add_numpy_to_numpy_type(type1, type2)
117+
rtol = RTOL32 if isinstance(python_result, (np.float64, np.complex128)) else RTOL
118+
atol = ATOL32 if isinstance(python_result, (np.float64, np.complex128)) else ATOL
119+
assert np.isclose(pyccel_result, python_result, rtol=rtol, atol=atol)
120+
assert isinstance(pyccel_result, type(python_result))
133121

134122
@pytest.mark.skipif(numpy_basic_types_deprecated, reason="Can't import bool from numpy")
135123
def test_numpy_bool_scalar(language):

tests/epyccel/test_builtins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def f(x : 'T', y : 'T'):
345345

346346
int_args = [randint(min_int//2, max_int//2) for _ in range(2)]
347347
float_args = [uniform(min_float/2, max_float/2) for _ in range(2)]
348-
complex_args = [uniform(min_float/2, max_float/2) + 1j*uniform(min_float/2, max_float/2)
348+
complex_args = [uniform(min_float/4, max_float/4) + 1j*uniform(min_float/4, max_float/4)
349349
for _ in range(2)]
350350

351351
assert epyc_f(*int_args) == f(*int_args)

0 commit comments

Comments
 (0)