@@ -194,189 +194,189 @@ def test_array_creation_from_2d_array(func, args, usm_type_x, usm_type_y):
194
194
assert y .usm_type == usm_type_y
195
195
196
196
197
- # @pytest.mark.parametrize(
198
- # "func, arg, kwargs",
199
- # [
200
- # pytest.param("arange", [-25.7], {"stop": 10**8, "step": 15}),
201
- # pytest.param("frombuffer", [b"\x01\x02\x03\x04"], {"dtype": dp.int32}),
202
- # pytest.param(
203
- # "fromfunction", [(lambda i, j: i + j), (3, 3)], {"dtype": dp.int32}
204
- # ),
205
- # pytest.param("fromiter", [[1, 2, 3, 4]], {"dtype": dp.int64}),
206
- # pytest.param("fromstring", ["1 2"], {"dtype": int, "sep": " "}),
207
- # pytest.param("full", [(2, 2)], {"fill_value": 5}),
208
- # pytest.param("eye", [4, 2], {}),
209
- # pytest.param("geomspace", [1, 4, 8], {}),
210
- # pytest.param("identity", [4], {}),
211
- # pytest.param("linspace", [0, 4, 8], {}),
212
- # pytest.param("logspace", [0, 4, 8], {}),
213
- # pytest.param("ones", [(2, 2)], {}),
214
- # pytest.param("tri", [3, 5, 2], {}),
215
- # pytest.param("zeros", [(2, 2)], {}),
216
- # ],
217
- # )
218
- # @pytest.mark.parametrize("usm_type", list_of_usm_types + [None])
219
- # def test_array_creation_from_scratch(func, arg, kwargs, usm_type):
220
- # dpnp_kwargs = dict(kwargs)
221
- # dpnp_kwargs["usm_type"] = usm_type
222
- # dpnp_array = getattr(dp, func)(*arg, **dpnp_kwargs)
197
+ @pytest .mark .parametrize (
198
+ "func, arg, kwargs" ,
199
+ [
200
+ pytest .param ("arange" , [- 25.7 ], {"stop" : 10 ** 8 , "step" : 15 }),
201
+ pytest .param ("frombuffer" , [b"\x01 \x02 \x03 \x04 " ], {"dtype" : dp .int32 }),
202
+ pytest .param (
203
+ "fromfunction" , [(lambda i , j : i + j ), (3 , 3 )], {"dtype" : dp .int32 }
204
+ ),
205
+ pytest .param ("fromiter" , [[1 , 2 , 3 , 4 ]], {"dtype" : dp .int64 }),
206
+ pytest .param ("fromstring" , ["1 2" ], {"dtype" : int , "sep" : " " }),
207
+ pytest .param ("full" , [(2 , 2 )], {"fill_value" : 5 }),
208
+ pytest .param ("eye" , [4 , 2 ], {}),
209
+ pytest .param ("geomspace" , [1 , 4 , 8 ], {}),
210
+ pytest .param ("identity" , [4 ], {}),
211
+ pytest .param ("linspace" , [0 , 4 , 8 ], {}),
212
+ pytest .param ("logspace" , [0 , 4 , 8 ], {}),
213
+ pytest .param ("ones" , [(2 , 2 )], {}),
214
+ pytest .param ("tri" , [3 , 5 , 2 ], {}),
215
+ pytest .param ("zeros" , [(2 , 2 )], {}),
216
+ ],
217
+ )
218
+ @pytest .mark .parametrize ("usm_type" , list_of_usm_types + [None ])
219
+ def test_array_creation_from_scratch (func , arg , kwargs , usm_type ):
220
+ dpnp_kwargs = dict (kwargs )
221
+ dpnp_kwargs ["usm_type" ] = usm_type
222
+ dpnp_array = getattr (dp , func )(* arg , ** dpnp_kwargs )
223
223
224
- # numpy_kwargs = dict(kwargs)
225
- # numpy_kwargs["dtype"] = dpnp_array.dtype
226
- # numpy_array = getattr(numpy, func)(*arg, **numpy_kwargs)
224
+ numpy_kwargs = dict (kwargs )
225
+ numpy_kwargs ["dtype" ] = dpnp_array .dtype
226
+ numpy_array = getattr (numpy , func )(* arg , ** numpy_kwargs )
227
227
228
- # if usm_type is None:
229
- # # assert against default USM type
230
- # usm_type = "device"
228
+ if usm_type is None :
229
+ # assert against default USM type
230
+ usm_type = "device"
231
231
232
- # assert_dtype_allclose(dpnp_array, numpy_array)
233
- # assert dpnp_array.shape == numpy_array.shape
234
- # assert dpnp_array.usm_type == usm_type
232
+ assert_dtype_allclose (dpnp_array , numpy_array )
233
+ assert dpnp_array .shape == numpy_array .shape
234
+ assert dpnp_array .usm_type == usm_type
235
235
236
236
237
- # @pytest.mark.parametrize("usm_type", list_of_usm_types + [None])
238
- # def test_array_creation_empty(usm_type):
239
- # dpnp_array = dp.empty((3, 4), usm_type=usm_type)
240
- # numpy_array = numpy.empty((3, 4))
237
+ @pytest .mark .parametrize ("usm_type" , list_of_usm_types + [None ])
238
+ def test_array_creation_empty (usm_type ):
239
+ dpnp_array = dp .empty ((3 , 4 ), usm_type = usm_type )
240
+ numpy_array = numpy .empty ((3 , 4 ))
241
241
242
- # if usm_type is None:
243
- # # assert against default USM type
244
- # usm_type = "device"
242
+ if usm_type is None :
243
+ # assert against default USM type
244
+ usm_type = "device"
245
245
246
- # assert dpnp_array.shape == numpy_array.shape
247
- # assert dpnp_array.usm_type == usm_type
246
+ assert dpnp_array .shape == numpy_array .shape
247
+ assert dpnp_array .usm_type == usm_type
248
248
249
249
250
- # @pytest.mark.parametrize("usm_type", list_of_usm_types + [None])
251
- # def test_array_creation_from_file(usm_type):
252
- # with tempfile.TemporaryFile() as fh:
253
- # fh.write(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08")
254
- # fh.flush()
250
+ @pytest .mark .parametrize ("usm_type" , list_of_usm_types + [None ])
251
+ def test_array_creation_from_file (usm_type ):
252
+ with tempfile .TemporaryFile () as fh :
253
+ fh .write (b"\x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 " )
254
+ fh .flush ()
255
255
256
- # fh.seek(0)
257
- # numpy_array = numpy.fromfile(fh)
256
+ fh .seek (0 )
257
+ numpy_array = numpy .fromfile (fh )
258
258
259
- # fh.seek(0)
260
- # dpnp_array = dp.fromfile(fh, usm_type=usm_type)
259
+ fh .seek (0 )
260
+ dpnp_array = dp .fromfile (fh , usm_type = usm_type )
261
261
262
- # if usm_type is None:
263
- # # assert against default USM type
264
- # usm_type = "device"
262
+ if usm_type is None :
263
+ # assert against default USM type
264
+ usm_type = "device"
265
265
266
- # assert_dtype_allclose(dpnp_array, numpy_array)
267
- # assert dpnp_array.shape == numpy_array.shape
268
- # assert dpnp_array.usm_type == usm_type
266
+ assert_dtype_allclose (dpnp_array , numpy_array )
267
+ assert dpnp_array .shape == numpy_array .shape
268
+ assert dpnp_array .usm_type == usm_type
269
269
270
270
271
- # @pytest.mark.parametrize("usm_type", list_of_usm_types + [None])
272
- # def test_array_creation_load_txt(usm_type):
273
- # with tempfile.TemporaryFile() as fh:
274
- # fh.write(b"1 2 3 4")
275
- # fh.flush()
271
+ @pytest .mark .parametrize ("usm_type" , list_of_usm_types + [None ])
272
+ def test_array_creation_load_txt (usm_type ):
273
+ with tempfile .TemporaryFile () as fh :
274
+ fh .write (b"1 2 3 4" )
275
+ fh .flush ()
276
276
277
- # fh.seek(0)
278
- # numpy_array = numpy.loadtxt(fh)
277
+ fh .seek (0 )
278
+ numpy_array = numpy .loadtxt (fh )
279
279
280
- # fh.seek(0)
281
- # dpnp_array = dp.loadtxt(fh, usm_type=usm_type)
280
+ fh .seek (0 )
281
+ dpnp_array = dp .loadtxt (fh , usm_type = usm_type )
282
282
283
- # if usm_type is None:
284
- # # assert against default USM type
285
- # usm_type = "device"
283
+ if usm_type is None :
284
+ # assert against default USM type
285
+ usm_type = "device"
286
286
287
- # assert_dtype_allclose(dpnp_array, numpy_array)
288
- # assert dpnp_array.shape == numpy_array.shape
289
- # assert dpnp_array.usm_type == usm_type
287
+ assert_dtype_allclose (dpnp_array , numpy_array )
288
+ assert dpnp_array .shape == numpy_array .shape
289
+ assert dpnp_array .usm_type == usm_type
290
290
291
291
292
- # @pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
293
- # @pytest.mark.parametrize("usm_type_y", list_of_usm_types, ids=list_of_usm_types)
294
- # def test_copy_method(usm_type_x, usm_type_y):
295
- # x = dp.array([[1, 2, 3], [4, 5, 6]], usm_type=usm_type_x)
296
-
297
- # y = x.copy()
298
- # assert x.usm_type == y.usm_type == usm_type_x
299
-
300
- # y = x.copy(usm_type=usm_type_y)
301
- # assert y.usm_type == usm_type_y
292
+ @pytest .mark .parametrize ("usm_type_x" , list_of_usm_types , ids = list_of_usm_types )
293
+ @pytest .mark .parametrize ("usm_type_y" , list_of_usm_types , ids = list_of_usm_types )
294
+ def test_copy_method (usm_type_x , usm_type_y ):
295
+ x = dp .array ([[1 , 2 , 3 ], [4 , 5 , 6 ]], usm_type = usm_type_x )
302
296
297
+ y = x .copy ()
298
+ assert x .usm_type == y .usm_type == usm_type_x
303
299
304
- # @pytest.mark.parametrize("usm_type", list_of_usm_types, ids=list_of_usm_types)
305
- # def test_copy_operation(usm_type):
306
- # x = dp.array([[1, 2, 3], [4, 5, 6]], usm_type=usm_type)
307
- # y = copy.copy(x)
308
- # assert x.usm_type == y.usm_type == usm_type
300
+ y = x .copy (usm_type = usm_type_y )
301
+ assert y .usm_type == usm_type_y
309
302
310
303
311
- # @pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
312
- # @pytest.mark.parametrize("usm_type_y", list_of_usm_types, ids=list_of_usm_types)
313
- # def test_logspace_base(usm_type_x, usm_type_y):
314
- # x0 = dp.full(10, 2, usm_type=usm_type_x)
304
+ @pytest .mark .parametrize ("usm_type" , list_of_usm_types , ids = list_of_usm_types )
305
+ def test_copy_operation (usm_type ):
306
+ x = dp .array ([[1 , 2 , 3 ], [4 , 5 , 6 ]], usm_type = usm_type )
307
+ y = copy .copy (x )
308
+ assert x .usm_type == y .usm_type == usm_type
315
309
316
- # x = dp.logspace([2, 2], 8, 4, base=x0[3:5])
317
- # y = dp.logspace([2, 2], 8, 4, base=x0[3:5], usm_type=usm_type_y)
318
310
319
- # assert x.usm_type == usm_type_x
320
- # assert y.usm_type == usm_type_y
311
+ @pytest .mark .parametrize ("usm_type_x" , list_of_usm_types , ids = list_of_usm_types )
312
+ @pytest .mark .parametrize ("usm_type_y" , list_of_usm_types , ids = list_of_usm_types )
313
+ def test_logspace_base (usm_type_x , usm_type_y ):
314
+ x0 = dp .full (10 , 2 , usm_type = usm_type_x )
321
315
316
+ x = dp .logspace ([2 , 2 ], 8 , 4 , base = x0 [3 :5 ])
317
+ y = dp .logspace ([2 , 2 ], 8 , 4 , base = x0 [3 :5 ], usm_type = usm_type_y )
322
318
323
- # @pytest.mark.parametrize(
324
- # "func",
325
- # [
326
- # "array",
327
- # "asarray",
328
- # "asarray_chkfinite",
329
- # "asanyarray",
330
- # "ascontiguousarray",
331
- # "asfarray",
332
- # "asfortranarray",
333
- # ],
334
- # )
335
- # @pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
336
- # @pytest.mark.parametrize("usm_type_y", list_of_usm_types, ids=list_of_usm_types)
337
- # def test_array_copy(func, usm_type_x, usm_type_y):
338
- # if numpy.lib.NumpyVersion(numpy.__version__) >= "2.0.0":
339
- # pytest.skip("numpy.asfarray was removed")
319
+ assert x .usm_type == usm_type_x
320
+ assert y .usm_type == usm_type_y
340
321
341
- # sh = (3, 7, 5)
342
- # x = dp.arange(1, prod(sh) + 1, 1, usm_type=usm_type_x).reshape(sh)
343
322
344
- # y = getattr(dp, func)(x, usm_type=usm_type_y)
323
+ @pytest .mark .parametrize (
324
+ "func" ,
325
+ [
326
+ "array" ,
327
+ "asarray" ,
328
+ "asarray_chkfinite" ,
329
+ "asanyarray" ,
330
+ "ascontiguousarray" ,
331
+ "asfarray" ,
332
+ "asfortranarray" ,
333
+ ],
334
+ )
335
+ @pytest .mark .parametrize ("usm_type_x" , list_of_usm_types , ids = list_of_usm_types )
336
+ @pytest .mark .parametrize ("usm_type_y" , list_of_usm_types , ids = list_of_usm_types )
337
+ def test_array_copy (func , usm_type_x , usm_type_y ):
338
+ if numpy .lib .NumpyVersion (numpy .__version__ ) >= "2.0.0" :
339
+ pytest .skip ("numpy.asfarray was removed" )
345
340
346
- # assert x.usm_type == usm_type_x
347
- # assert y.usm_type == usm_type_y
341
+ sh = ( 3 , 7 , 5 )
342
+ x = dp . arange ( 1 , prod ( sh ) + 1 , 1 , usm_type = usm_type_x ). reshape ( sh )
348
343
344
+ y = getattr (dp , func )(x , usm_type = usm_type_y )
349
345
350
- # @pytest.mark.parametrize("copy", [True, False, None])
351
- # @pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
352
- # def test_array_creation_from_dpctl(copy, usm_type_x):
353
- # x = dpt.ones((3, 3), usm_type=usm_type_x)
354
- # y = dp.array(x, copy=copy)
346
+ assert x .usm_type == usm_type_x
347
+ assert y .usm_type == usm_type_y
355
348
356
- # assert y.usm_type == usm_type_x
357
349
350
+ @pytest .mark .parametrize ("copy" , [True , False , None ])
351
+ @pytest .mark .parametrize ("usm_type_x" , list_of_usm_types , ids = list_of_usm_types )
352
+ def test_array_creation_from_dpctl (copy , usm_type_x ):
353
+ x = dpt .ones ((3 , 3 ), usm_type = usm_type_x )
354
+ y = dp .array (x , copy = copy )
358
355
359
- # @pytest.mark.parametrize(
360
- # "usm_type_start", list_of_usm_types, ids=list_of_usm_types
361
- # )
362
- # @pytest.mark.parametrize(
363
- # "usm_type_stop", list_of_usm_types, ids=list_of_usm_types
364
- # )
365
- # def test_linspace_arrays(usm_type_start, usm_type_stop):
366
- # start = dp.asarray([0, 0], usm_type=usm_type_start)
367
- # stop = dp.asarray([2, 4], usm_type=usm_type_stop)
368
- # res = dp.linspace(start, stop, 4)
369
- # assert res.usm_type == du.get_coerced_usm_type(
370
- # [usm_type_start, usm_type_stop]
371
- # )
356
+ assert y .usm_type == usm_type_x
372
357
373
358
374
- # @pytest.mark.parametrize("func", ["tril", "triu"], ids=["tril", "triu"])
375
- # @pytest.mark.parametrize("usm_type", list_of_usm_types, ids=list_of_usm_types)
376
- # def test_tril_triu(func, usm_type):
377
- # x0 = dp.ones((3, 3), usm_type=usm_type)
378
- # x = getattr(dp, func)(x0)
379
- # assert x.usm_type == usm_type
359
+ @pytest .mark .parametrize (
360
+ "usm_type_start" , list_of_usm_types , ids = list_of_usm_types
361
+ )
362
+ @pytest .mark .parametrize (
363
+ "usm_type_stop" , list_of_usm_types , ids = list_of_usm_types
364
+ )
365
+ def test_linspace_arrays (usm_type_start , usm_type_stop ):
366
+ start = dp .asarray ([0 , 0 ], usm_type = usm_type_start )
367
+ stop = dp .asarray ([2 , 4 ], usm_type = usm_type_stop )
368
+ res = dp .linspace (start , stop , 4 )
369
+ assert res .usm_type == du .get_coerced_usm_type (
370
+ [usm_type_start , usm_type_stop ]
371
+ )
372
+
373
+
374
+ @pytest .mark .parametrize ("func" , ["tril" , "triu" ], ids = ["tril" , "triu" ])
375
+ @pytest .mark .parametrize ("usm_type" , list_of_usm_types , ids = list_of_usm_types )
376
+ def test_tril_triu (func , usm_type ):
377
+ x0 = dp .ones ((3 , 3 ), usm_type = usm_type )
378
+ x = getattr (dp , func )(x0 )
379
+ assert x .usm_type == usm_type
380
380
381
381
382
382
# @pytest.mark.parametrize(
0 commit comments