@@ -199,7 +199,6 @@ def test_floor_divide(self, dtype, lhs, rhs):
199
199
"floor_divide" , dtype , lhs , rhs , check_type = False
200
200
)
201
201
202
- @pytest .mark .usefixtures ("allow_fall_back_on_numpy" )
203
202
@pytest .mark .parametrize (
204
203
"dtype" , get_all_dtypes (no_bool = True , no_complex = True )
205
204
)
@@ -966,6 +965,90 @@ def test_invalid_out(self, out):
966
965
assert_raises (TypeError , numpy .add , a .asnumpy (), 2 , out )
967
966
968
967
968
+ class TestHypot :
969
+ @pytest .mark .parametrize ("dtype" , get_float_dtypes ())
970
+ def test_hypot (self , dtype ):
971
+ array1_data = numpy .arange (10 )
972
+ array2_data = numpy .arange (5 , 15 )
973
+ out = numpy .empty (10 , dtype = dtype )
974
+
975
+ # DPNP
976
+ dp_array1 = dpnp .array (array1_data , dtype = dtype )
977
+ dp_array2 = dpnp .array (array2_data , dtype = dtype )
978
+ dp_out = dpnp .array (out , dtype = dtype )
979
+ result = dpnp .hypot (dp_array1 , dp_array2 , out = dp_out )
980
+
981
+ # original
982
+ np_array1 = numpy .array (array1_data , dtype = dtype )
983
+ np_array2 = numpy .array (array2_data , dtype = dtype )
984
+ expected = numpy .hypot (np_array1 , np_array2 , out = out )
985
+
986
+ assert_allclose (expected , result )
987
+ assert_allclose (out , dp_out )
988
+
989
+ @pytest .mark .parametrize ("dtype" , get_float_dtypes ())
990
+ def test_out_dtypes (self , dtype ):
991
+ size = 10
992
+
993
+ np_array1 = numpy .arange (size , 2 * size , dtype = dtype )
994
+ np_array2 = numpy .arange (size , dtype = dtype )
995
+ np_out = numpy .empty (size , dtype = numpy .float32 )
996
+ expected = numpy .hypot (np_array1 , np_array2 , out = np_out )
997
+
998
+ dp_array1 = dpnp .arange (size , 2 * size , dtype = dtype )
999
+ dp_array2 = dpnp .arange (size , dtype = dtype )
1000
+
1001
+ dp_out = dpnp .empty (size , dtype = dpnp .float32 )
1002
+ if dtype != dpnp .float32 :
1003
+ # dtype of out mismatches types of input arrays
1004
+ with pytest .raises (TypeError ):
1005
+ dpnp .hypot (dp_array1 , dp_array2 , out = dp_out )
1006
+
1007
+ # allocate new out with expected type
1008
+ dp_out = dpnp .empty (size , dtype = dtype )
1009
+
1010
+ result = dpnp .hypot (dp_array1 , dp_array2 , out = dp_out )
1011
+
1012
+ tol = numpy .finfo (numpy .float32 ).resolution
1013
+ assert_allclose (expected , result , rtol = tol , atol = tol )
1014
+
1015
+ @pytest .mark .parametrize ("dtype" , get_float_dtypes ())
1016
+ def test_out_overlap (self , dtype ):
1017
+ size = 15
1018
+ # DPNP
1019
+ dp_a = dpnp .arange (2 * size , dtype = dtype )
1020
+ dpnp .hypot (dp_a [size ::], dp_a [::2 ], out = dp_a [:size :])
1021
+
1022
+ # original
1023
+ np_a = numpy .arange (2 * size , dtype = dtype )
1024
+ numpy .hypot (np_a [size ::], np_a [::2 ], out = np_a [:size :])
1025
+
1026
+ tol = numpy .finfo (numpy .float32 ).resolution
1027
+ assert_allclose (np_a , dp_a , rtol = tol , atol = tol )
1028
+
1029
+ @pytest .mark .parametrize (
1030
+ "shape" , [(0 ,), (15 ,), (2 , 2 )], ids = ["(0,)" , "(15, )" , "(2,2)" ]
1031
+ )
1032
+ def test_invalid_shape (self , shape ):
1033
+ dp_array1 = dpnp .arange (10 )
1034
+ dp_array2 = dpnp .arange (5 , 15 )
1035
+ dp_out = dpnp .empty (shape )
1036
+
1037
+ with pytest .raises (ValueError ):
1038
+ dpnp .hypot (dp_array1 , dp_array2 , out = dp_out )
1039
+
1040
+ @pytest .mark .parametrize (
1041
+ "out" ,
1042
+ [4 , (), [], (3 , 7 ), [2 , 4 ]],
1043
+ ids = ["4" , "()" , "[]" , "(3, 7)" , "[2, 4]" ],
1044
+ )
1045
+ def test_invalid_out (self , out ):
1046
+ a = dpnp .arange (10 )
1047
+
1048
+ assert_raises (TypeError , dpnp .hypot , a , 2 , out )
1049
+ assert_raises (TypeError , numpy .hypot , a .asnumpy (), 2 , out )
1050
+
1051
+
969
1052
class TestFmax :
970
1053
@pytest .mark .parametrize (
971
1054
"dtype" , get_all_dtypes (no_bool = True , no_complex = True , no_none = True )
0 commit comments