Skip to content

Commit d840cee

Browse files
authored
Changes to logic for determining order of output array in elementwise functions, clip, matmul (#1678)
When multiple input arrays are both C- and F-contiguous and need to be cast, the output defaults to C-contiguous instead of F-contiguous
1 parent 7bc3124 commit d840cee

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

dpctl/tensor/_clip.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,17 +791,17 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
791791

792792
if order == "K":
793793
if (
794-
x.flags.f_contiguous
795-
and a_min.flags.f_contiguous
796-
and a_max.flags.f_contiguous
797-
):
798-
order = "F"
799-
elif (
800794
x.flags.c_contiguous
801795
and a_min.flags.c_contiguous
802796
and a_max.flags.c_contiguous
803797
):
804798
order = "C"
799+
elif (
800+
x.flags.f_contiguous
801+
and a_min.flags.f_contiguous
802+
and a_max.flags.f_contiguous
803+
):
804+
order = "F"
805805
if order == "K":
806806
buf1 = _empty_like_orderK(a_min, buf1_dt)
807807
else:

dpctl/tensor/_elementwise_common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,10 @@ def __call__(self, o1, o2, /, *, out=None, order="K"):
858858
return out
859859

860860
if order == "K":
861-
if src1.flags.f_contiguous and src2.flags.f_contiguous:
862-
order = "F"
863-
elif src1.flags.c_contiguous and src2.flags.c_contiguous:
861+
if src1.flags.c_contiguous and src2.flags.c_contiguous:
864862
order = "C"
863+
elif src1.flags.f_contiguous and src2.flags.f_contiguous:
864+
order = "F"
865865
if order == "K":
866866
buf1 = _empty_like_orderK(src1, buf1_dt)
867867
else:

dpctl/tensor/_linear_algebra_functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,10 @@ def matmul(x1, x2, out=None, dtype=None, order="K"):
942942
return out
943943

944944
if order == "K":
945-
if x1.flags.f_contiguous and x2.flags.f_contiguous:
946-
order = "F"
947-
elif x1.flags.c_contiguous and x2.flags.c_contiguous:
945+
if x1.flags.c_contiguous and x2.flags.c_contiguous:
948946
order = "C"
947+
elif x1.flags.f_contiguous and x2.flags.f_contiguous:
948+
order = "F"
949949
if order == "K":
950950
buf1 = _empty_like_orderK(x1, buf1_dt)
951951
else:

0 commit comments

Comments
 (0)