@@ -349,36 +349,19 @@ def _copy_from_usm_ndarray_to_usm_ndarray(dst, src):
349349 _copy_same_shape (dst , src_same_shape )
350350
351351
352- def _empty_like_orderK (X , dt , usm_type = None , dev = None ):
353- """Returns empty array like `x`, using order='K'
354-
355- For an array `x` that was obtained by permutation of a contiguous
356- array the returned array will have the same shape and the same
357- strides as `x`.
352+ def _make_empty_like_orderK (x , dt , usm_type , dev ):
358353 """
359- if not isinstance (X , dpt .usm_ndarray ):
360- raise TypeError (f"Expected usm_ndarray, got { type (X )} " )
361- if usm_type is None :
362- usm_type = X .usm_type
363- if dev is None :
364- dev = X .device
365- fl = X .flags
366- if fl ["C" ] or X .size <= 1 :
367- return dpt .empty_like (
368- X , dtype = dt , usm_type = usm_type , device = dev , order = "C"
369- )
370- elif fl ["F" ]:
371- return dpt .empty_like (
372- X , dtype = dt , usm_type = usm_type , device = dev , order = "F"
373- )
374- st = list (X .strides )
354+ Returns empty array with shape and strides like `x`, with dtype `dt`,
355+ USM type `usm_type`, on device `dev`.
356+ """
357+ st = list (x .strides )
375358 perm = sorted (
376- range (X .ndim ),
377- key = lambda d : builtins .abs (st [d ]) if X .shape [d ] > 1 else 0 ,
359+ range (x .ndim ),
360+ key = lambda d : builtins .abs (st [d ]) if x .shape [d ] > 1 else 0 ,
378361 reverse = True ,
379362 )
380- inv_perm = sorted (range (X .ndim ), key = lambda i : perm [i ])
381- sh = X .shape
363+ inv_perm = sorted (range (x .ndim ), key = lambda i : perm [i ])
364+ sh = x .shape
382365 sh_sorted = tuple (sh [i ] for i in perm )
383366 R = dpt .empty (sh_sorted , dtype = dt , usm_type = usm_type , device = dev , order = "C" )
384367 if min (st ) < 0 :
@@ -389,12 +372,60 @@ def _empty_like_orderK(X, dt, usm_type=None, dev=None):
389372 if st_sorted [i ] < 0
390373 else slice (None , None , None )
391374 )
392- for i in range (X .ndim )
375+ for i in range (x .ndim )
393376 )
394377 R = R [sl ]
395378 return dpt .permute_dims (R , inv_perm )
396379
397380
381+ def _empty_like_orderK (x , dt , usm_type = None , dev = None ):
382+ """
383+ Returns empty array like `x`, using order='K'
384+
385+ For an array `x` that was obtained by permutation of a contiguous
386+ array the returned array will have the same shape and the same
387+ strides as `x`.
388+ """
389+ if not isinstance (x , dpt .usm_ndarray ):
390+ raise TypeError (f"Expected usm_ndarray, got { type (x )} " )
391+ if usm_type is None :
392+ usm_type = x .usm_type
393+ if dev is None :
394+ dev = x .device
395+ fl = x .flags
396+ if fl ["C" ] or x .size <= 1 :
397+ return dpt .empty_like (
398+ x , dtype = dt , usm_type = usm_type , device = dev , order = "C"
399+ )
400+ elif fl ["F" ]:
401+ return dpt .empty_like (
402+ x , dtype = dt , usm_type = usm_type , device = dev , order = "F"
403+ )
404+ return _make_empty_like_orderK (x , dt , usm_type , dev )
405+
406+
407+ def _from_numpy_empty_like_orderK (x , dt , usm_type , dev ):
408+ """
409+ Returns empty usm_ndarray like NumPy array `x`, using order='K'
410+
411+ For an array `x` that was obtained by permutation of a contiguous
412+ array the returned array will have the same shape and the same
413+ strides as `x`.
414+ """
415+ if not isinstance (x , np .ndarray ):
416+ raise TypeError (f"Expected numpy.ndarray, got { type (x )} " )
417+ fl = x .flags
418+ if fl ["C" ] or x .size <= 1 :
419+ return dpt .empty (
420+ x .shape , dtype = dt , usm_type = usm_type , device = dev , order = "C"
421+ )
422+ elif fl ["F" ]:
423+ return dpt .empty (
424+ x .shape , dtype = dt , usm_type = usm_type , device = dev , order = "F"
425+ )
426+ return _make_empty_like_orderK (x , dt , usm_type , dev )
427+
428+
398429def _empty_like_pair_orderK (X1 , X2 , dt , res_shape , usm_type , dev ):
399430 if not isinstance (X1 , dpt .usm_ndarray ):
400431 raise TypeError (f"Expected usm_ndarray, got { type (X1 )} " )
@@ -732,7 +763,7 @@ def _extract_impl(ary, ary_mask, axis=0):
732763 if exec_q is None :
733764 raise dpctl .utils .ExecutionPlacementError (
734765 "arrays have different associated queues. "
735- "Use `Y .to_device(X .device)` to migrate."
766+ "Use `y .to_device(x .device)` to migrate."
736767 )
737768 ary_nd = ary .ndim
738769 pp = normalize_axis_index (operator .index (axis ), ary_nd )
0 commit comments