7
7
from test_numpy_funcs import (min_int , max_int , min_int8 , max_int8 ,
8
8
min_int16 , max_int16 , min_int32 , max_int32 , max_int64 , min_int64 )
9
9
from test_numpy_funcs import max_float , min_float , max_float32 , min_float32 ,max_float64 , min_float64
10
- from test_numpy_funcs import matching_types
10
+ from test_numpy_funcs import matching_types , RTOL , ATOL , RTOL32 , ATOL32
11
11
12
12
from pyccel .decorators import template
13
13
from pyccel import epyccel
@@ -190,13 +190,11 @@ def get_bool(a : 'T'):
190
190
assert f_integer32_output == test_int32_output
191
191
assert matching_types (f_integer32_output , test_int32_output )
192
192
193
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
194
- if sys .platform != 'win32' :
195
- f_integer64_output = epyccel_func (integer64 )
196
- test_int64_output = get_bool (integer64 )
193
+ f_integer64_output = epyccel_func (integer64 )
194
+ test_int64_output = get_bool (integer64 )
197
195
198
- assert f_integer64_output == test_int64_output
199
- assert matching_types (f_integer64_output , test_int64_output )
196
+ assert f_integer64_output == test_int64_output
197
+ assert matching_types (f_integer64_output , test_int64_output )
200
198
201
199
f_fl_output = epyccel_func (fl )
202
200
test_float_output = get_bool (fl )
@@ -312,31 +310,29 @@ def test_numpy_int_scalar(language, function_boundaries):
312
310
assert f_integer32_output == test_int32_output
313
311
assert matching_types (f_integer32_output , test_int32_output )
314
312
315
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
316
- if sys .platform != 'win32' :
317
- f_integer64_output = epyccel_func (integer64 )
318
- test_int64_output = get_int (integer64 )
313
+ f_integer64_output = epyccel_func (integer64 )
314
+ test_int64_output = get_int (integer64 )
319
315
320
- assert f_integer64_output == test_int64_output
321
- assert matching_types (f_integer64_output , test_int64_output )
316
+ assert f_integer64_output == test_int64_output
317
+ assert matching_types (f_integer64_output , test_int64_output )
322
318
323
- f_fl_output = epyccel_func (fl )
324
- test_float_output = get_int (fl )
319
+ f_fl_output = epyccel_func (fl )
320
+ test_float_output = get_int (fl )
325
321
326
- assert f_fl_output == test_float_output
327
- assert matching_types (f_fl_output , test_float_output )
322
+ assert f_fl_output == test_float_output
323
+ assert matching_types (f_fl_output , test_float_output )
328
324
329
- f_fl64_output = epyccel_func (fl64 )
330
- test_float64_output = get_int (fl64 )
325
+ f_fl64_output = epyccel_func (fl64 )
326
+ test_float64_output = get_int (fl64 )
331
327
332
- assert f_fl64_output == test_float64_output
333
- assert matching_types (f_fl64_output , test_float64_output )
328
+ assert f_fl64_output == test_float64_output
329
+ assert matching_types (f_fl64_output , test_float64_output )
334
330
335
- f_fl32_output = epyccel_func (fl32 )
336
- test_float32_output = get_int (fl32 )
331
+ f_fl32_output = epyccel_func (fl32 )
332
+ test_float32_output = get_int (fl32 )
337
333
338
- assert f_fl32_output == test_float32_output
339
- assert matching_types (f_fl32_output , test_float32_output )
334
+ assert f_fl32_output == test_float32_output
335
+ assert matching_types (f_fl32_output , test_float32_output )
340
336
341
337
@template ('T' , ['bool[:]' , 'int[:]' , 'int8[:]' , 'int16[:]' , 'int32[:]' , 'int64[:]' , 'float[:]' , 'float32[:]' , 'float64[:]' ])
342
338
def get_int64_arr_1d (arr : 'T' ):
@@ -399,12 +395,10 @@ def test_numpy_int_array_like_1d(language, function_boundaries):
399
395
assert epyccel_func (integer16 ) == get_int (integer16 )
400
396
assert epyccel_func (integer ) == get_int (integer )
401
397
assert epyccel_func (integer32 ) == get_int (integer32 )
402
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
403
- if sys .platform != 'win32' :
404
- assert epyccel_func (integer64 ) == get_int (integer64 )
405
- assert epyccel_func (fl ) == get_int (fl )
406
- assert epyccel_func (fl64 ) == get_int (fl64 )
407
- assert epyccel_func (fl32 ) == get_int (fl32 )
398
+ assert epyccel_func (integer64 ) == get_int (integer64 )
399
+ assert epyccel_func (fl ) == get_int (fl )
400
+ assert epyccel_func (fl64 ) == get_int (fl64 )
401
+ assert epyccel_func (fl32 ) == get_int (fl32 )
408
402
409
403
@template ('T' , ['bool[:,:]' , 'int[:,:]' , 'int8[:,:]' , 'int16[:,:]' , 'int32[:,:]' , 'int64[:,:]' , 'float[:,:]' , 'float32[:,:]' , 'float64[:,:]' ])
410
404
def get_int64_arr_2d (arr : 'T' ):
@@ -467,12 +461,10 @@ def test_numpy_int_array_like_2d(language, function_boundaries):
467
461
assert epyccel_func (integer16 ) == get_int (integer16 )
468
462
assert epyccel_func (integer ) == get_int (integer )
469
463
assert epyccel_func (integer32 ) == get_int (integer32 )
470
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
471
- if sys .platform != 'win32' :
472
- assert epyccel_func (integer64 ) == get_int (integer64 )
473
- assert epyccel_func (fl ) == get_int (fl )
474
- assert epyccel_func (fl64 ) == get_int (fl64 )
475
- assert epyccel_func (fl32 ) == get_int (fl32 )
464
+ assert epyccel_func (integer64 ) == get_int (integer64 )
465
+ assert epyccel_func (fl ) == get_int (fl )
466
+ assert epyccel_func (fl64 ) == get_int (fl64 )
467
+ assert epyccel_func (fl32 ) == get_int (fl32 )
476
468
477
469
@template ('T' , ['bool' , 'int' , 'int8' , 'int16' , 'int32' , 'int64' , 'float' , 'float32' , 'float64' ])
478
470
def get_float (a : 'T' ):
@@ -550,13 +542,11 @@ def test_numpy_float_scalar(language, get_float):
550
542
assert f_integer32_output == test_int32_output
551
543
assert matching_types (f_integer32_output , test_int32_output )
552
544
553
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
554
- if sys .platform != 'win32' :
555
- f_integer64_output = epyccel_func (integer64 )
556
- test_int64_output = get_float (integer64 )
545
+ f_integer64_output = epyccel_func (integer64 )
546
+ test_int64_output = get_float (integer64 )
557
547
558
- assert f_integer64_output == test_int64_output
559
- assert matching_types (f_integer64_output , test_int64_output )
548
+ assert f_integer64_output == test_int64_output
549
+ assert matching_types (f_integer64_output , test_int64_output )
560
550
561
551
f_fl_output = epyccel_func (fl )
562
552
test_float_output = get_float (fl )
@@ -616,11 +606,9 @@ def test_numpy_float_array_like_1d(language, get_float):
616
606
assert epyccel_func (integer16 ) == get_float (integer16 )
617
607
assert epyccel_func (integer ) == get_float (integer )
618
608
assert epyccel_func (integer32 ) == get_float (integer32 )
619
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
620
- if sys .platform != 'win32' :
621
- assert epyccel_func (integer64 ) == get_float (integer64 )
622
- assert epyccel_func (fl ) == get_float (fl )
623
- assert epyccel_func (fl64 ) == get_float (fl64 )
609
+ assert epyccel_func (integer64 ) == get_float (integer64 )
610
+ assert epyccel_func (fl ) == get_float (fl )
611
+ assert epyccel_func (fl64 ) == get_float (fl64 )
624
612
assert epyccel_func (fl32 ) == get_float (fl32 )
625
613
626
614
@template ('T' , ['bool[:,:]' , 'int[:,:]' , 'int8[:,:]' , 'int16[:,:]' , 'int32[:,:]' , 'int64[:,:]' , 'float[:,:]' , 'float32[:,:]' , 'float64[:,:]' ])
@@ -662,11 +650,9 @@ def test_numpy_float_array_like_2d(language, get_float):
662
650
assert epyccel_func (integer16 ) == get_float (integer16 )
663
651
assert epyccel_func (integer ) == get_float (integer )
664
652
assert epyccel_func (integer32 ) == get_float (integer32 )
665
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
666
- if sys .platform != 'win32' :
667
- assert epyccel_func (integer64 ) == get_float (integer64 )
668
- assert epyccel_func (fl ) == get_float (fl )
669
- assert epyccel_func (fl64 ) == get_float (fl64 )
653
+ assert epyccel_func (integer64 ) == get_float (integer64 )
654
+ assert epyccel_func (fl ) == get_float (fl )
655
+ assert epyccel_func (fl64 ) == get_float (fl64 )
670
656
assert epyccel_func (fl32 ) == get_float (fl32 )
671
657
672
658
def test_numpy_double_scalar (language ):
@@ -727,13 +713,11 @@ def get_double(a : 'T'):
727
713
assert f_integer32_output == test_int32_output
728
714
assert matching_types (f_integer32_output , test_int32_output )
729
715
730
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
731
- if sys .platform != 'win32' :
732
- f_integer64_output = epyccel_func (integer64 )
733
- test_int64_output = get_double (integer64 )
716
+ f_integer64_output = epyccel_func (integer64 )
717
+ test_int64_output = get_double (integer64 )
734
718
735
- assert f_integer64_output == test_int64_output
736
- assert matching_types (f_integer64_output , test_int64_output )
719
+ assert f_integer64_output == test_int64_output
720
+ assert matching_types (f_integer64_output , test_int64_output )
737
721
738
722
f_fl_output = epyccel_func (fl )
739
723
test_float_output = get_double (fl )
@@ -785,11 +769,9 @@ def get_double(arr : 'T'):
785
769
assert epyccel_func (integer16 ) == get_double (integer16 )
786
770
assert epyccel_func (integer ) == get_double (integer )
787
771
assert epyccel_func (integer32 ) == get_double (integer32 )
788
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
789
- if sys .platform != 'win32' :
790
- assert epyccel_func (integer64 ) == get_double (integer64 )
791
- assert epyccel_func (fl ) == get_double (fl )
792
- assert epyccel_func (fl64 ) == get_double (fl64 )
772
+ assert epyccel_func (integer64 ) == get_double (integer64 )
773
+ assert epyccel_func (fl ) == get_double (fl )
774
+ assert epyccel_func (fl64 ) == get_double (fl64 )
793
775
assert epyccel_func (fl32 ) == get_double (fl32 )
794
776
795
777
def test_numpy_double_array_like_2d (language ):
@@ -823,11 +805,9 @@ def get_double(arr : 'T'):
823
805
assert epyccel_func (integer16 ) == get_double (integer16 )
824
806
assert epyccel_func (integer ) == get_double (integer )
825
807
assert epyccel_func (integer32 ) == get_double (integer32 )
826
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
827
- if sys .platform != 'win32' :
828
- assert epyccel_func (integer64 ) == get_double (integer64 )
829
- assert epyccel_func (fl ) == get_double (fl )
830
- assert epyccel_func (fl64 ) == get_double (fl64 )
808
+ assert epyccel_func (integer64 ) == get_double (integer64 )
809
+ assert epyccel_func (fl ) == get_double (fl )
810
+ assert epyccel_func (fl64 ) == get_double (fl64 )
831
811
assert epyccel_func (fl32 ) == get_double (fl32 )
832
812
833
813
@@ -906,13 +886,11 @@ def test_numpy_complex_scalar(language, get_complex):
906
886
assert f_integer32_output == test_int32_output
907
887
assert matching_types (f_integer32_output , test_int32_output )
908
888
909
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
910
- if sys .platform != 'win32' :
911
- f_integer64_output = epyccel_func (integer64 )
912
- test_int64_output = get_complex (integer64 )
889
+ f_integer64_output = epyccel_func (integer64 )
890
+ test_int64_output = get_complex (integer64 )
913
891
914
- assert f_integer64_output == test_int64_output
915
- assert matching_types (f_integer64_output , test_int64_output )
892
+ assert f_integer64_output == test_int64_output
893
+ assert matching_types (f_integer64_output , test_int64_output )
916
894
917
895
f_fl_output = epyccel_func (fl )
918
896
test_float_output = get_complex (fl )
@@ -986,24 +964,27 @@ def test_numpy_complex_array_like_1d(language, get_complex):
986
964
integer32 = randint (min_int32 , max_int32 , size = size , dtype = np .int32 )
987
965
integer64 = randint (min_int64 , max_int64 , size = size , dtype = np .int64 )
988
966
989
- fl = uniform (min_float / 2 , max_float / 2 , size = size )
967
+ # float32 is used as the maximum for all float types to avoid overflow errors
968
+ fl = uniform (min_float32 / 2 , max_float32 / 2 , size = size )
990
969
fl32 = uniform (min_float32 / 2 , max_float32 / 2 , size = size )
991
970
fl32 = np .float32 (fl32 )
992
- fl64 = uniform (min_float64 / 2 , max_float64 / 2 , size = size )
971
+ fl64 = uniform (min_float32 / 2 , max_float32 / 2 , size = size )
993
972
994
973
epyccel_func = epyccel (get_complex , language = language )
995
974
996
- assert epyccel_func (bl ) == get_complex (bl )
997
- assert epyccel_func (integer8 ) == get_complex (integer8 )
998
- assert epyccel_func (integer16 ) == get_complex (integer16 )
999
- assert epyccel_func (integer ) == get_complex (integer )
1000
- assert epyccel_func (integer32 ) == get_complex (integer32 )
1001
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
1002
- if sys .platform != 'win32' :
1003
- assert epyccel_func (integer64 ) == get_complex (integer64 )
1004
- assert epyccel_func (fl ) == get_complex (fl )
1005
- assert epyccel_func (fl64 ) == get_complex (fl64 )
1006
- assert epyccel_func (fl32 ) == get_complex (fl32 )
975
+ is_complex64 = get_complex (bl )[- 1 ].dtype == np .complex64
976
+ rtol = RTOL32 if is_complex64 else RTOL
977
+ atol = ATOL32 if is_complex64 else ATOL
978
+
979
+ assert np .allclose (epyccel_func (bl ), get_complex (bl ), rtol = rtol , atol = atol )
980
+ assert np .allclose (epyccel_func (integer8 ), get_complex (integer8 ), rtol = rtol , atol = atol )
981
+ assert np .allclose (epyccel_func (integer16 ), get_complex (integer16 ), rtol = rtol , atol = atol )
982
+ assert np .allclose (epyccel_func (integer ), get_complex (integer ), rtol = rtol , atol = atol )
983
+ assert np .allclose (epyccel_func (integer32 ), get_complex (integer32 ), rtol = rtol , atol = atol )
984
+ assert np .allclose (epyccel_func (integer64 ), get_complex (integer64 ), rtol = rtol , atol = atol )
985
+ assert np .allclose (epyccel_func (fl ), get_complex (fl ), rtol = rtol , atol = atol )
986
+ assert np .allclose (epyccel_func (fl64 ), get_complex (fl64 ), rtol = rtol , atol = atol )
987
+ assert np .allclose (epyccel_func (fl32 ), get_complex (fl32 ), rtol = rtol , atol = atol )
1007
988
1008
989
@pytest .mark .parametrize ( 'language' , (
1009
990
pytest .param ("fortran" , marks = [pytest .mark .fortran ]),
@@ -1028,24 +1009,27 @@ def test_numpy_complex_array_like_2d(language, get_complex):
1028
1009
integer32 = randint (min_int32 , max_int32 , size = size , dtype = np .int32 )
1029
1010
integer64 = randint (min_int64 , max_int64 , size = size , dtype = np .int64 )
1030
1011
1031
- fl = uniform (min_float / 2 , max_float / 2 , size = size )
1012
+ # float32 is used as the maximum for all float types to avoid overflow errors
1013
+ fl = uniform (min_float32 / 2 , max_float32 / 2 , size = size )
1032
1014
fl32 = uniform (min_float32 / 2 , max_float32 / 2 , size = size )
1033
1015
fl32 = np .float32 (fl32 )
1034
- fl64 = uniform (min_float64 / 2 , max_float64 / 2 , size = size )
1016
+ fl64 = uniform (min_float32 / 2 , max_float32 / 2 , size = size )
1035
1017
1036
1018
epyccel_func = epyccel (get_complex , language = language )
1037
1019
1038
- assert epyccel_func (bl ) == get_complex (bl )
1039
- assert epyccel_func (integer8 ) == get_complex (integer8 )
1040
- assert epyccel_func (integer16 ) == get_complex (integer16 )
1041
- assert epyccel_func (integer ) == get_complex (integer )
1042
- assert epyccel_func (integer32 ) == get_complex (integer32 )
1043
- # the if block should be removed after resolving (https://github.com/pyccel/pyccel/issues/735).
1044
- if sys .platform != 'win32' :
1045
- assert epyccel_func (integer64 ) == get_complex (integer64 )
1046
- assert epyccel_func (fl ) == get_complex (fl )
1047
- assert epyccel_func (fl64 ) == get_complex (fl64 )
1048
- assert epyccel_func (fl32 ) == get_complex (fl32 )
1020
+ is_complex64 = get_complex (bl )[- 1 ].dtype == np .complex64
1021
+ rtol = RTOL32 if is_complex64 else RTOL
1022
+ atol = ATOL32 if is_complex64 else ATOL
1023
+
1024
+ assert np .allclose (epyccel_func (bl ), get_complex (bl ), rtol = rtol , atol = atol )
1025
+ assert np .allclose (epyccel_func (integer8 ), get_complex (integer8 ), rtol = rtol , atol = atol )
1026
+ assert np .allclose (epyccel_func (integer16 ), get_complex (integer16 ), rtol = rtol , atol = atol )
1027
+ assert np .allclose (epyccel_func (integer ), get_complex (integer ), rtol = rtol , atol = atol )
1028
+ assert np .allclose (epyccel_func (integer32 ), get_complex (integer32 ), rtol = rtol , atol = atol )
1029
+ assert np .allclose (epyccel_func (integer64 ), get_complex (integer64 ), rtol = rtol , atol = atol )
1030
+ assert np .allclose (epyccel_func (fl ), get_complex (fl ), rtol = rtol , atol = atol )
1031
+ assert np .allclose (epyccel_func (fl64 ), get_complex (fl64 ), rtol = rtol , atol = atol )
1032
+ assert np .allclose (epyccel_func (fl32 ), get_complex (fl32 ), rtol = rtol , atol = atol )
1049
1033
1050
1034
def test_literal_complex64 (language ):
1051
1035
def get_complex64 ():
0 commit comments