@@ -1130,6 +1130,21 @@ def full(
11301130 return res
11311131
11321132
1133+ def _normalize_order (order , arr ):
1134+ """
1135+ Utility function for processing the `order` keyword of array-like
1136+ constructors, which support `"K"` and `"A"` orders.
1137+ """
1138+ arr_flags = arr .flags
1139+ f_contig = arr_flags ["F" ]
1140+ c_contig = arr_flags ["C" ]
1141+ if order == "A" :
1142+ order = "F" if f_contig and not c_contig else "C"
1143+ if order == "K" and (f_contig or c_contig ):
1144+ order = "C" if c_contig else "F"
1145+ return order
1146+
1147+
11331148def empty_like (
11341149 x , / , * , dtype = None , order = "K" , device = None , usm_type = None , sycl_queue = None
11351150):
@@ -1189,13 +1204,7 @@ def empty_like(
11891204 device = x .device
11901205 sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
11911206 dtype = dpt .dtype (dtype )
1192- x_flags = x .flags
1193- f_contig = x_flags ["F" ]
1194- c_contig = x_flags ["C" ]
1195- if order == "A" :
1196- order = "F" if f_contig and not c_contig else "C"
1197- if order == "K" and (f_contig or c_contig ):
1198- order = "C" if c_contig else "F"
1207+ order = _normalize_order (order , x )
11991208 if order == "K" :
12001209 _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
12011210 return _empty_like_orderK (x , dtype , usm_type , sycl_queue )
@@ -1274,13 +1283,7 @@ def zeros_like(
12741283 device = x .device
12751284 sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
12761285 dtype = dpt .dtype (dtype )
1277- x_flags = x .flags
1278- f_contig = x_flags ["F" ]
1279- c_contig = x_flags ["C" ]
1280- if order == "A" :
1281- order = "F" if f_contig and not c_contig else "C"
1282- if order == "K" and (f_contig or c_contig ):
1283- order = "C" if c_contig else "F"
1286+ order = _normalize_order (order , x )
12841287 if order == "K" :
12851288 _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
12861289 res = _empty_like_orderK (x , dtype , usm_type , sycl_queue )
@@ -1362,13 +1365,7 @@ def ones_like(
13621365 device = x .device
13631366 sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
13641367 dtype = dpt .dtype (dtype )
1365- x_flags = x .flags
1366- f_contig = x_flags ["F" ]
1367- c_contig = x_flags ["C" ]
1368- if order == "A" :
1369- order = "F" if f_contig and not c_contig else "C"
1370- if order == "K" and (f_contig or c_contig ):
1371- order = "C" if c_contig else "F"
1368+ order = _normalize_order (order , x )
13721369 if order == "K" :
13731370 _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
13741371 res = _empty_like_orderK (x , dtype , usm_type , sycl_queue )
@@ -1462,13 +1459,7 @@ def full_like(
14621459 sycl_queue = normalize_queue_device (sycl_queue = sycl_queue , device = device )
14631460 sh = x .shape
14641461 dtype = dpt .dtype (dtype )
1465- x_flags = x .flags
1466- f_contig = x_flags ["F" ]
1467- c_contig = x_flags ["C" ]
1468- if order == "A" :
1469- order = "F" if f_contig and not c_contig else "C"
1470- if order == "K" and (f_contig or c_contig ):
1471- order = "C" if c_contig else "F"
1462+ order = _normalize_order (order , x )
14721463 if order == "K" :
14731464 _ensure_native_dtype_device_support (dtype , sycl_queue .sycl_device )
14741465 if isinstance (fill_value , (dpt .usm_ndarray , np .ndarray , tuple , list )):
0 commit comments