@@ -904,7 +904,7 @@ def zeros(
904904 data type of the array. Can be typestring,
905905 a :class:`numpy.dtype` object, :mod:`numpy` char string,
906906 or a NumPy scalar type. Default: ``None``
907- order ("C", or F"):
907+ order ("C", or " F"):
908908 memory layout for the array. Default: ``"C"``
909909 device (optional): array API concept of device where the output array
910910 is created. ``device`` can be ``None``, a oneAPI filter selector
@@ -975,7 +975,7 @@ def ones(
975975 data type of the array. Can be typestring,
976976 a :class:`numpy.dtype` object, :mod:`numpy` char string,
977977 or a NumPy scalar type. Default: ``None``
978- order ("C", or F"): memory layout for the array. Default: ``"C"``
978+ order ("C", or " F"): memory layout for the array. Default: ``"C"``
979979 device (optional): array API concept of device where the output array
980980 is created. ``device`` can be ``None``, a oneAPI filter selector
981981 string, an instance of :class:`dpctl.SyclDevice` corresponding to
@@ -1043,7 +1043,7 @@ def full(
10431043 dtype (optional): data type of the array. Can be typestring,
10441044 a :class:`numpy.dtype` object, :mod:`numpy` char string,
10451045 or a NumPy scalar type. Default: ``None``
1046- order ("C", or F"):
1046+ order ("C", or " F"):
10471047 memory layout for the array. Default: ``"C"``
10481048 device (optional): array API concept of device where the output array
10491049 is created. ``device`` can be ``None``, a oneAPI filter selector
@@ -1121,7 +1121,7 @@ def full(
11211121
11221122
11231123def empty_like (
1124- x , / , * , dtype = None , order = "C " , device = None , usm_type = None , sycl_queue = None
1124+ x , / , * , dtype = None , order = "K " , device = None , usm_type = None , sycl_queue = None
11251125):
11261126 """
11271127 Returns an uninitialized :class:`dpctl.tensor.usm_ndarray` with the
@@ -1134,8 +1134,8 @@ def empty_like(
11341134 data type of the array. Can be a typestring,
11351135 a :class:`numpy.dtype` object, NumPy char string,
11361136 or a NumPy scalar type. Default: ``None``
1137- order ("C", or F "):
1138- memory layout for the array. Default: ``"C "``
1137+ order ("C", "F", "A", or "K "):
1138+ memory layout for the array. Default: ``"K "``
11391139 device (optional): array API concept of device where the output array
11401140 is created. ``device`` can be ``None``, a oneAPI filter selector
11411141 string, an instance of :class:`dpctl.SyclDevice` corresponding to
@@ -1161,11 +1161,8 @@ def empty_like(
11611161 """
11621162 if not isinstance (x , dpt .usm_ndarray ):
11631163 raise TypeError (f"Expected instance of dpt.usm_ndarray, got { type (x )} ." )
1164- if not isinstance (order , str ) or len (order ) == 0 or order [0 ] not in "CcFf" :
1165- raise ValueError (
1166- "Unrecognized order keyword value, expecting 'F' or 'C'."
1167- )
1168- order = order [0 ].upper ()
1164+ if order not in ("K" , "C" , "F" , "A" ):
1165+ order = "K"
11691166 if dtype is None :
11701167 dtype = x .dtype
11711168 if usm_type is None :
@@ -1174,17 +1171,28 @@ def empty_like(
11741171 if device is None and sycl_queue is None :
11751172 device = x .device
11761173 sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
1177- shape = x .shape
11781174 dtype = dpt .dtype (dtype )
1179- _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
1180- res = dpt .usm_ndarray (
1181- shape ,
1182- dtype = dtype ,
1183- buffer = usm_type ,
1184- order = order ,
1185- buffer_ctor_kwargs = {"queue" : sycl_queue },
1186- )
1187- return res
1175+ x_flags = x .flags
1176+ f_contig = x_flags ["F" ]
1177+ c_contig = x_flags ["C" ]
1178+ if order == "A" :
1179+ order = "F" if f_contig and not c_contig else "C"
1180+ if order == "K" and (f_contig or c_contig ):
1181+ order = "C" if c_contig else "F"
1182+ if order == "K" :
1183+ _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
1184+ return _empty_like_orderK (x , dtype , usm_type , sycl_queue )
1185+ else :
1186+ shape = x .shape
1187+ _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
1188+ res = dpt .usm_ndarray (
1189+ shape ,
1190+ dtype = dtype ,
1191+ buffer = usm_type ,
1192+ order = order ,
1193+ buffer_ctor_kwargs = {"queue" : sycl_queue },
1194+ )
1195+ return res
11881196
11891197
11901198def zeros_like (
@@ -1203,7 +1211,7 @@ def zeros_like(
12031211 a :class:`numpy.dtype` object, :mod:`numpy` char string, or a
12041212 NumPy scalar type. If `None`, output array has the same data
12051213 type as the input array. Default: ``None``
1206- order ("C", or F"):
1214+ order ("C", or " F"):
12071215 memory layout for the array. Default: ``"C"``
12081216 device (optional):
12091217 array API concept of device where the output array
@@ -1231,11 +1239,8 @@ def zeros_like(
12311239 """
12321240 if not isinstance (x , dpt .usm_ndarray ):
12331241 raise TypeError (f"Expected instance of dpt.usm_ndarray, got { type (x )} ." )
1234- if not isinstance (order , str ) or len (order ) == 0 or order [0 ] not in "CcFf" :
1235- raise ValueError (
1236- "Unrecognized order keyword value, expecting 'F' or 'C'."
1237- )
1238- order = order [0 ].upper ()
1242+ if order not in ("K" , "C" , "F" , "A" ):
1243+ order = "K"
12391244 if dtype is None :
12401245 dtype = x .dtype
12411246 if usm_type is None :
@@ -1244,20 +1249,37 @@ def zeros_like(
12441249 if device is None and sycl_queue is None :
12451250 device = x .device
12461251 sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
1247- sh = x .shape
12481252 dtype = dpt .dtype (dtype )
1249- return zeros (
1250- sh ,
1251- dtype = dtype ,
1252- order = order ,
1253- device = device ,
1254- usm_type = usm_type ,
1255- sycl_queue = sycl_queue ,
1256- )
1253+ x_flags = x .flags
1254+ f_contig = x_flags ["F" ]
1255+ c_contig = x_flags ["C" ]
1256+ if order == "A" :
1257+ order = "F" if f_contig and not c_contig else "C"
1258+ if order == "K" and (f_contig or c_contig ):
1259+ order = "C" if c_contig else "F"
1260+ if order == "K" :
1261+ _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
1262+ res = _empty_like_orderK (x , dtype , usm_type , sycl_queue )
1263+ _manager = dpctl .utils .SequentialOrderManager [sycl_queue ]
1264+ # populating new allocation, no dependent events
1265+ hev , full_ev = ti ._full_usm_ndarray (0 , res , sycl_queue )
1266+ _manager .add_event_pair (hev , full_ev )
1267+ return res
1268+ else :
1269+ _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
1270+ sh = x .shape
1271+ return zeros (
1272+ sh ,
1273+ dtype = dtype ,
1274+ order = order ,
1275+ device = device ,
1276+ usm_type = usm_type ,
1277+ sycl_queue = sycl_queue ,
1278+ )
12571279
12581280
12591281def ones_like (
1260- x , / , * , dtype = None , order = "C " , device = None , usm_type = None , sycl_queue = None
1282+ x , / , * , dtype = None , order = "K " , device = None , usm_type = None , sycl_queue = None
12611283):
12621284 """
12631285 Returns a new :class:`dpctl.tensor.usm_ndarray` filled with ones and
@@ -1270,7 +1292,7 @@ def ones_like(
12701292 data type of the array. Can be typestring,
12711293 a :class:`numpy.dtype` object, :mod:`numpy` char string,
12721294 or a NumPy scalar type. Default: `None`
1273- order ("C", or F "):
1295+ order ("C", "F", "A", or "K "):
12741296 memory layout for the array. Default: ``"C"``
12751297 device (optional):
12761298 array API concept of device where the output array
@@ -1298,11 +1320,8 @@ def ones_like(
12981320 """
12991321 if not isinstance (x , dpt .usm_ndarray ):
13001322 raise TypeError (f"Expected instance of dpt.usm_ndarray, got { type (x )} ." )
1301- if not isinstance (order , str ) or len (order ) == 0 or order [0 ] not in "CcFf" :
1302- raise ValueError (
1303- "Unrecognized order keyword value, expecting 'F' or 'C'."
1304- )
1305- order = order [0 ].upper ()
1323+ if order not in ("K" , "C" , "F" , "A" ):
1324+ order = "K"
13061325 if dtype is None :
13071326 dtype = x .dtype
13081327 if usm_type is None :
@@ -1311,16 +1330,32 @@ def ones_like(
13111330 if device is None and sycl_queue is None :
13121331 device = x .device
13131332 sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
1314- sh = x .shape
13151333 dtype = dpt .dtype (dtype )
1316- return ones (
1317- sh ,
1318- dtype = dtype ,
1319- order = order ,
1320- device = device ,
1321- usm_type = usm_type ,
1322- sycl_queue = sycl_queue ,
1323- )
1334+ x_flags = x .flags
1335+ f_contig = x_flags ["F" ]
1336+ c_contig = x_flags ["C" ]
1337+ if order == "A" :
1338+ order = "F" if f_contig and not c_contig else "C"
1339+ if order == "K" and (f_contig or c_contig ):
1340+ order = "C" if c_contig else "F"
1341+ if order == "K" :
1342+ _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
1343+ res = _empty_like_orderK (x , dtype , usm_type , sycl_queue )
1344+ _manager = dpctl .utils .SequentialOrderManager [sycl_queue ]
1345+ # populating new allocation, no dependent events
1346+ hev , full_ev = ti ._full_usm_ndarray (1 , res , sycl_queue )
1347+ _manager .add_event_pair (hev , full_ev )
1348+ return res
1349+ else :
1350+ sh = x .shape
1351+ return ones (
1352+ sh ,
1353+ dtype = dtype ,
1354+ order = order ,
1355+ device = device ,
1356+ usm_type = usm_type ,
1357+ sycl_queue = sycl_queue ,
1358+ )
13241359
13251360
13261361def full_like (
@@ -1334,7 +1369,7 @@ def full_like(
13341369 usm_type = None ,
13351370 sycl_queue = None ,
13361371):
1337- """ full_like(x, fill_value, dtype=None, order="C ", \
1372+ """ full_like(x, fill_value, dtype=None, order="K ", \
13381373 device=None, usm_type=None, sycl_queue=None)
13391374
13401375 Returns a new :class:`dpctl.tensor.usm_ndarray` filled with `fill_value`
@@ -1349,8 +1384,8 @@ def full_like(
13491384 a :class:`numpy.dtype` object, :mod:`numpy` char string, or a
13501385 NumPy scalar type. If ``dtype`` is ``None``, the output array data
13511386 type is inferred from ``x``. Default: ``None``
1352- order ("C", or F "):
1353- memory layout for the array. Default: ``"C "``
1387+ order ("C", "F", "A", or "K "):
1388+ memory layout for the array. Default: ``"K "``
13541389 device (optional):
13551390 array API concept of device where the output array
13561391 is created. ``device`` can be ``None``, a oneAPI filter selector
@@ -1377,11 +1412,8 @@ def full_like(
13771412 """
13781413 if not isinstance (x , dpt .usm_ndarray ):
13791414 raise TypeError (f"Expected instance of dpt.usm_ndarray, got { type (x )} ." )
1380- if not isinstance (order , str ) or len (order ) == 0 or order [0 ] not in "CcFf" :
1381- raise ValueError (
1382- "Unrecognized order keyword value, expecting 'F' or 'C'."
1383- )
1384- order = order [0 ].upper ()
1415+ if order not in ("K" , "C" , "F" , "A" ):
1416+ order = "K"
13851417 if dtype is None :
13861418 dtype = x .dtype
13871419 if usm_type is None :
@@ -1392,15 +1424,49 @@ def full_like(
13921424 sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
13931425 sh = x .shape
13941426 dtype = dpt .dtype (dtype )
1395- return full (
1396- sh ,
1397- fill_value ,
1398- dtype = dtype ,
1399- order = order ,
1400- device = device ,
1401- usm_type = usm_type ,
1402- sycl_queue = sycl_queue ,
1403- )
1427+ x_flags = x .flags
1428+ f_contig = x_flags ["F" ]
1429+ c_contig = x_flags ["C" ]
1430+ if order == "A" :
1431+ order = "F" if f_contig and not c_contig else "C"
1432+ if order == "K" and (f_contig or c_contig ):
1433+ order = "C" if c_contig else "F"
1434+ if order == "K" :
1435+ _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
1436+ if isinstance (fill_value , (dpt .usm_ndarray , np .ndarray , tuple , list )):
1437+ X = dpt .asarray (
1438+ fill_value ,
1439+ dtype = dtype ,
1440+ order = order ,
1441+ usm_type = usm_type ,
1442+ sycl_queue = sycl_queue ,
1443+ )
1444+ X = dpt .broadcast_to (X , sh )
1445+ res = _empty_like_orderK (x , dtype , usm_type , sycl_queue )
1446+ _manager = dpctl .utils .SequentialOrderManager [sycl_queue ]
1447+ # populating new allocation, no dependent events
1448+ hev , copy_ev = ti ._copy_usm_ndarray_into_usm_ndarray (
1449+ src = X , dst = res , sycl_queue = sycl_queue
1450+ )
1451+ _manager .add_event_pair (hev , copy_ev )
1452+ return res
1453+ else :
1454+ res = _empty_like_orderK (x , dtype , usm_type , sycl_queue )
1455+ _manager = dpctl .utils .SequentialOrderManager [sycl_queue ]
1456+ # populating new allocation, no dependent events
1457+ hev , full_ev = ti ._full_usm_ndarray (fill_value , res , sycl_queue )
1458+ _manager .add_event_pair (hev , full_ev )
1459+ return res
1460+ else :
1461+ return full (
1462+ sh ,
1463+ fill_value ,
1464+ dtype = dtype ,
1465+ order = order ,
1466+ device = device ,
1467+ usm_type = usm_type ,
1468+ sycl_queue = sycl_queue ,
1469+ )
14041470
14051471
14061472def linspace (
@@ -1536,7 +1602,7 @@ def eye(
15361602 data type of the array. Can be typestring,
15371603 a :class:`numpy.dtype` object, :mod:`numpy` char string, or
15381604 a NumPy scalar type. Default: ``None``
1539- order ("C" or F"):
1605+ order ("C" or " F"):
15401606 memory layout for the array. Default: ``"C"``
15411607 device (optional):
15421608 array API concept of device where the output array
0 commit comments