Skip to content

Commit

Permalink
Changes to logic for determining order of output array in elementwi…
Browse files Browse the repository at this point in the history
…se 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
  • Loading branch information
ndgrigorian authored May 15, 2024
1 parent 7bc3124 commit d840cee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions dpctl/tensor/_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,17 +791,17 @@ def clip(x, /, min=None, max=None, out=None, order="K"):

if order == "K":
if (
x.flags.f_contiguous
and a_min.flags.f_contiguous
and a_max.flags.f_contiguous
):
order = "F"
elif (
x.flags.c_contiguous
and a_min.flags.c_contiguous
and a_max.flags.c_contiguous
):
order = "C"
elif (
x.flags.f_contiguous
and a_min.flags.f_contiguous
and a_max.flags.f_contiguous
):
order = "F"
if order == "K":
buf1 = _empty_like_orderK(a_min, buf1_dt)
else:
Expand Down
6 changes: 3 additions & 3 deletions dpctl/tensor/_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,10 @@ def __call__(self, o1, o2, /, *, out=None, order="K"):
return out

if order == "K":
if src1.flags.f_contiguous and src2.flags.f_contiguous:
order = "F"
elif src1.flags.c_contiguous and src2.flags.c_contiguous:
if src1.flags.c_contiguous and src2.flags.c_contiguous:
order = "C"
elif src1.flags.f_contiguous and src2.flags.f_contiguous:
order = "F"
if order == "K":
buf1 = _empty_like_orderK(src1, buf1_dt)
else:
Expand Down
6 changes: 3 additions & 3 deletions dpctl/tensor/_linear_algebra_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,10 +942,10 @@ def matmul(x1, x2, out=None, dtype=None, order="K"):
return out

if order == "K":
if x1.flags.f_contiguous and x2.flags.f_contiguous:
order = "F"
elif x1.flags.c_contiguous and x2.flags.c_contiguous:
if x1.flags.c_contiguous and x2.flags.c_contiguous:
order = "C"
elif x1.flags.f_contiguous and x2.flags.f_contiguous:
order = "F"
if order == "K":
buf1 = _empty_like_orderK(x1, buf1_dt)
else:
Expand Down

0 comments on commit d840cee

Please sign in to comment.