@@ -55,7 +55,7 @@ def test_flatten(arr, arr_dtype):
5555 [(), 0 , (0 ,), (2 ), (5 , 2 ), (5 , 0 , 2 ), (5 , 3 , 2 )],
5656 ids = ["()" , "0" , "(0,)" , "(2)" , "(5, 2)" , "(5, 0, 2)" , "(5, 3, 2)" ],
5757)
58- @pytest .mark .parametrize ("order" , ["C" , "F" ], ids = [ "C" , "F" ] )
58+ @pytest .mark .parametrize ("order" , ["C" , "F" ])
5959def test_flags (shape , order ):
6060 usm_array = dpt .usm_ndarray (shape , order = order )
6161 numpy_array = numpy .ndarray (shape , order = order )
@@ -71,7 +71,7 @@ def test_flags(shape, order):
7171 ids = ["complex64" , "float32" , "int64" , "int32" , "bool" ],
7272)
7373@pytest .mark .parametrize ("strides" , [(1 , 4 ), (4 , 1 )], ids = ["(1, 4)" , "(4, 1)" ])
74- @pytest .mark .parametrize ("order" , ["C" , "F" ], ids = [ "C" , "F" ] )
74+ @pytest .mark .parametrize ("order" , ["C" , "F" ])
7575def test_flags_strides (dtype , order , strides ):
7676 itemsize = numpy .dtype (dtype ).itemsize
7777 numpy_strides = tuple ([el * itemsize for el in strides ])
@@ -104,6 +104,32 @@ def test_flags_writable():
104104 assert not a .imag .flags .writable
105105
106106
107+ class TestItem :
108+ @pytest .mark .parametrize ("args" , [2 , 7 , (1 , 2 ), (2 , 0 )])
109+ def test_basic (self , args ):
110+ a = numpy .arange (12 ).reshape (3 , 4 )
111+ ia = dpnp .array (a )
112+
113+ expected = a .item (args )
114+ result = ia .item (args )
115+ assert isinstance (result , int )
116+ assert expected == result
117+
118+ def test_0D (self ):
119+ a = numpy .array (5 )
120+ ia = dpnp .array (a )
121+
122+ expected = a .item ()
123+ result = ia .item ()
124+ assert isinstance (result , int )
125+ assert expected == result
126+
127+ def test_error (self ):
128+ ia = dpnp .arange (12 ).reshape (3 , 4 )
129+ with pytest .raises (ValueError ):
130+ ia .item ()
131+
132+
107133def test_print_dpnp_int ():
108134 result = repr (dpnp .array ([1 , 0 , 2 , - 3 , - 1 , 2 , 21 , - 9 ], dtype = "i4" ))
109135 expected = "array([ 1, 0, 2, -3, -1, 2, 21, -9], dtype=int32)"
@@ -165,9 +191,7 @@ def test_print_dpnp_boolean():
165191 assert result == expected
166192
167193
168- @pytest .mark .parametrize (
169- "character" , [dpnp .nan , dpnp .inf ], ids = ["dpnp.nan" , "dpnp.inf" ]
170- )
194+ @pytest .mark .parametrize ("character" , [dpnp .nan , dpnp .inf ])
171195def test_print_dpnp_special_character (character ):
172196 result = repr (dpnp .array ([1.0 , 0.0 , character , 3.0 ]))
173197 expected = f"array([ 1., 0., { character } , 3.])"
@@ -264,7 +288,7 @@ def test_array_as_index(shape, index_dtype):
264288@pytest .mark .parametrize (
265289 "shape" ,
266290 [(3 , 5 ), (2 , 5 , 2 ), (2 , 3 , 3 , 6 )],
267- ids = ["(3,5)" , "(2,5, 2)" , "(2,3,3, 6)" ],
291+ ids = ["(3, 5)" , "(2, 5, 2)" , "(2, 3, 3, 6)" ],
268292)
269293def test_matrix_transpose (shape ):
270294 a = numpy .arange (numpy .prod (shape )).reshape (shape )
0 commit comments