@@ -906,70 +906,141 @@ def test_signbit(data, dtype):
906
906
assert_dtype_allclose (result , expected )
907
907
908
908
909
- @pytest .mark .parametrize (
910
- "func" ,
911
- ["real" , "imag" , "conj" ],
912
- ids = ["real" , "imag" , "conj" ],
913
- )
914
- @pytest .mark .parametrize (
915
- "data" ,
916
- [complex (- 1 , - 4 ), complex (- 1 , 2 ), complex (3 , - 7 ), complex (4 , 12 )],
917
- ids = [
918
- "complex(-1, -4)" ,
919
- "complex(-1, 2)" ,
920
- "complex(3, -7)" ,
921
- "complex(4, 12)" ,
922
- ],
923
- )
924
- @pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
925
- def test_complex_funcs (func , data , dtype ):
926
- np_a = numpy .array (data , dtype = dtype )
927
- dpnp_a = dpnp .array (data , dtype = dtype )
909
+ class TestConj :
910
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_complex = True ))
911
+ def test_conj (self , dtype ):
912
+ a = numpy .array (numpy .random .uniform (- 5 , 5 , 20 ), dtype = dtype )
913
+ ia = dpnp .array (a )
928
914
929
- result = getattr ( dpnp , func )( dpnp_a )
930
- expected = getattr ( numpy , func )( np_a )
931
- assert_dtype_allclose (result , expected )
915
+ result = dpnp . conj ( ia )
916
+ expected = numpy . conj ( a )
917
+ assert_dtype_allclose (result , expected )
932
918
933
- # out keyword
934
- if func == "conj" :
935
- dp_out = dpnp .empty (expected .shape , dtype = expected .dtype )
936
- result = getattr (dpnp , func )(dpnp_a , out = dp_out )
919
+ @pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
920
+ def test_conj_complex (self , dtype ):
921
+ x1 = numpy .random .uniform (- 5 , 5 , 20 )
922
+ x2 = numpy .random .uniform (- 5 , 5 , 20 )
923
+ a = numpy .array (x1 + 1j * x2 , dtype = dtype )
924
+ ia = dpnp .array (a )
925
+
926
+ result = dpnp .conj (ia )
927
+ expected = numpy .conj (a )
928
+ assert_dtype_allclose (result , expected )
929
+
930
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_complex = True ))
931
+ def test_conj_ndarray (self , dtype ):
932
+ a = numpy .array (numpy .random .uniform (- 5 , 5 , 20 ), dtype = dtype )
933
+ ia = dpnp .array (a )
934
+
935
+ result = ia .conj ()
936
+ assert result is ia
937
+ assert_dtype_allclose (result , a .conj ())
938
+
939
+ @pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
940
+ def test_conj_complex_ndarray (self , dtype ):
941
+ x1 = numpy .random .uniform (- 5 , 5 , 20 )
942
+ x2 = numpy .random .uniform (- 5 , 5 , 20 )
943
+ a = numpy .array (x1 + 1j * x2 , dtype = dtype )
944
+ ia = dpnp .array (a )
945
+
946
+ assert_dtype_allclose (ia .conj (), a .conj ())
947
+
948
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_bool = True ))
949
+ def test_conj_out (self , dtype ):
950
+ a = numpy .array (numpy .random .uniform (- 5 , 5 , 20 ), dtype = dtype )
951
+ ia = dpnp .array (a )
952
+
953
+ expected = numpy .conj (a )
954
+ dp_out = dpnp .empty (ia .shape , dtype = dtype )
955
+ result = dpnp .conj (ia , out = dp_out )
937
956
assert dp_out is result
938
957
assert_dtype_allclose (result , expected )
939
958
940
959
941
- @pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
942
- def test_projection_infinity (dtype ):
943
- X = [
944
- complex (1 , 2 ),
945
- complex (dpnp .inf , - 1 ),
946
- complex (0 , - dpnp .inf ),
947
- complex (- dpnp .inf , dpnp .nan ),
948
- ]
949
- Y = [
950
- complex (1 , 2 ),
951
- complex (dpnp .inf , - 0.0 ),
952
- complex (dpnp .inf , - 0.0 ),
953
- complex (dpnp .inf , 0.0 ),
954
- ]
955
-
956
- a = dpnp .array (X , dtype = dtype )
957
- result = dpnp .proj (a )
958
- expected = dpnp .array (Y , dtype = dtype )
959
- assert_dtype_allclose (result , expected )
960
+ class TestRealImag :
961
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_complex = True ))
962
+ def test_real_imag (self , dtype ):
963
+ a = numpy .array (numpy .random .uniform (- 5 , 5 , 20 ), dtype = dtype )
964
+ ia = dpnp .array (a )
960
965
961
- # out keyword
962
- dp_out = dpnp . empty ( expected . shape , dtype = expected . dtype )
963
- result = dpnp . proj ( a , out = dp_out )
964
- assert dp_out is result
965
- assert_dtype_allclose (result , expected )
966
+ result = dpnp . real ( ia )
967
+ assert result is ia
968
+ expected = numpy . real ( a )
969
+ assert expected is a
970
+ assert_dtype_allclose (result , expected )
966
971
972
+ result = dpnp .imag (ia )
973
+ expected = numpy .imag (a )
974
+ assert_dtype_allclose (result , expected )
967
975
968
- @pytest .mark .parametrize ("dtype" , get_all_dtypes ())
969
- def test_projection (dtype ):
970
- result = dpnp .proj (dpnp .array (1 , dtype = dtype ))
971
- expected = dpnp .array (complex (1 , 0 ))
972
- assert_allclose (result , expected )
976
+ @pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
977
+ def test_real_imag_complex (self , dtype ):
978
+ x1 = numpy .random .uniform (- 5 , 5 , 20 )
979
+ x2 = numpy .random .uniform (- 5 , 5 , 20 )
980
+ a = numpy .array (x1 + 1j * x2 , dtype = dtype )
981
+ ia = dpnp .array (a )
982
+
983
+ result = dpnp .real (ia )
984
+ expected = numpy .real (a )
985
+ assert_dtype_allclose (result , expected )
986
+
987
+ result = dpnp .imag (ia )
988
+ expected = numpy .imag (a )
989
+ assert_dtype_allclose (result , expected )
990
+
991
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_complex = True ))
992
+ def test_real_imag_ndarray (self , dtype ):
993
+ a = numpy .array (numpy .random .uniform (- 5 , 5 , 20 ), dtype = dtype )
994
+ ia = dpnp .array (a )
995
+
996
+ result = ia .real
997
+ assert result is ia
998
+ assert_dtype_allclose (result , a .real )
999
+ assert_dtype_allclose (ia .imag , a .imag )
1000
+
1001
+ @pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
1002
+ def test_real_imag_complex_ndarray (self , dtype ):
1003
+ x1 = numpy .random .uniform (- 5 , 5 , 20 )
1004
+ x2 = numpy .random .uniform (- 5 , 5 , 20 )
1005
+ a = numpy .array (x1 + 1j * x2 , dtype = dtype )
1006
+ ia = dpnp .array (a )
1007
+
1008
+ assert_dtype_allclose (ia .real , a .real )
1009
+ assert_dtype_allclose (ia .imag , a .imag )
1010
+
1011
+
1012
+ class TestProjection :
1013
+ @pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
1014
+ def test_projection_infinity (self , dtype ):
1015
+ X = [
1016
+ complex (1 , 2 ),
1017
+ complex (dpnp .inf , - 1 ),
1018
+ complex (0 , - dpnp .inf ),
1019
+ complex (- dpnp .inf , dpnp .nan ),
1020
+ ]
1021
+ Y = [
1022
+ complex (1 , 2 ),
1023
+ complex (dpnp .inf , - 0.0 ),
1024
+ complex (dpnp .inf , - 0.0 ),
1025
+ complex (dpnp .inf , 0.0 ),
1026
+ ]
1027
+
1028
+ a = dpnp .array (X , dtype = dtype )
1029
+ result = dpnp .proj (a )
1030
+ expected = dpnp .array (Y , dtype = dtype )
1031
+ assert_dtype_allclose (result , expected )
1032
+
1033
+ # out keyword
1034
+ dp_out = dpnp .empty (expected .shape , dtype = expected .dtype )
1035
+ result = dpnp .proj (a , out = dp_out )
1036
+ assert dp_out is result
1037
+ assert_dtype_allclose (result , expected )
1038
+
1039
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes ())
1040
+ def test_projection (self , dtype ):
1041
+ result = dpnp .proj (dpnp .array (1 , dtype = dtype ))
1042
+ expected = dpnp .array (complex (1 , 0 ))
1043
+ assert_allclose (result , expected )
973
1044
974
1045
975
1046
@pytest .mark .parametrize ("val_type" , get_all_dtypes (no_none = True ))
0 commit comments