Skip to content

Commit 4e95dc3

Browse files
Merge pull request #1535 from IntelPython/fix-coverity-issue-in-linalg-dispatcher
Fix coverity issue in linalg and clip dispatchers
2 parents 004614e + 1db33c6 commit 4e95dc3

File tree

2 files changed

+40
-75
lines changed

2 files changed

+40
-75
lines changed

dpctl/tensor/_clip.py

+26-56
Original file line numberDiff line numberDiff line change
@@ -298,25 +298,25 @@ def _clip_none(x, val, out, order, _binary_fn):
298298
else:
299299
val_ary = dpt.asarray(val, dtype=val_dtype, sycl_queue=exec_q)
300300

301+
if order == "A":
302+
order = (
303+
"F"
304+
if all(
305+
arr.flags.f_contiguous
306+
for arr in (
307+
x,
308+
val_ary,
309+
)
310+
)
311+
else "C"
312+
)
301313
if val_dtype == res_dt:
302314
if out is None:
303315
if order == "K":
304316
out = _empty_like_pair_orderK(
305317
x, val_ary, res_dt, res_shape, res_usm_type, exec_q
306318
)
307319
else:
308-
if order == "A":
309-
order = (
310-
"F"
311-
if all(
312-
arr.flags.f_contiguous
313-
for arr in (
314-
x,
315-
val_ary,
316-
)
317-
)
318-
else "C"
319-
)
320320
out = dpt.empty(
321321
res_shape,
322322
dtype=res_dt,
@@ -347,8 +347,6 @@ def _clip_none(x, val, out, order, _binary_fn):
347347
if order == "K":
348348
buf = _empty_like_orderK(val_ary, res_dt)
349349
else:
350-
if order == "A":
351-
order = "F" if x.flags.f_contiguous else "C"
352350
buf = dpt.empty_like(val_ary, dtype=res_dt, order=order)
353351
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
354352
src=val_ary, dst=buf, sycl_queue=exec_q
@@ -473,8 +471,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
473471
if order == "K":
474472
out = _empty_like_orderK(x, x.dtype)
475473
else:
476-
if order == "A":
477-
order = "F" if x.flags.f_contiguous else "C"
478474
out = dpt.empty_like(x, order=order)
479475

480476
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
@@ -659,6 +655,19 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
659655
else:
660656
a_max = dpt.asarray(max, dtype=max_dtype, sycl_queue=exec_q)
661657

658+
if order == "A":
659+
order = (
660+
"F"
661+
if all(
662+
arr.flags.f_contiguous
663+
for arr in (
664+
x,
665+
a_min,
666+
a_max,
667+
)
668+
)
669+
else "C"
670+
)
662671
if buf1_dt is None and buf2_dt is None:
663672
if out is None:
664673
if order == "K":
@@ -672,19 +681,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
672681
exec_q,
673682
)
674683
else:
675-
if order == "A":
676-
order = (
677-
"F"
678-
if all(
679-
arr.flags.f_contiguous
680-
for arr in (
681-
x,
682-
a_min,
683-
a_max,
684-
)
685-
)
686-
else "C"
687-
)
688684
out = dpt.empty(
689685
res_shape,
690686
dtype=res_dt,
@@ -718,18 +714,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
718714
if order == "K":
719715
buf2 = _empty_like_orderK(a_max, buf2_dt)
720716
else:
721-
if order == "A":
722-
order = (
723-
"F"
724-
if all(
725-
arr.flags.f_contiguous
726-
for arr in (
727-
x,
728-
a_min,
729-
)
730-
)
731-
else "C"
732-
)
733717
buf2 = dpt.empty_like(a_max, dtype=buf2_dt, order=order)
734718
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
735719
src=a_max, dst=buf2, sycl_queue=exec_q
@@ -784,18 +768,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
784768
if order == "K":
785769
buf1 = _empty_like_orderK(a_min, buf1_dt)
786770
else:
787-
if order == "A":
788-
order = (
789-
"F"
790-
if all(
791-
arr.flags.f_contiguous
792-
for arr in (
793-
x,
794-
a_max,
795-
)
796-
)
797-
else "C"
798-
)
799771
buf1 = dpt.empty_like(a_min, dtype=buf1_dt, order=order)
800772
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
801773
src=a_min, dst=buf1, sycl_queue=exec_q
@@ -846,7 +818,7 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
846818
ht_binary_ev.wait()
847819
return out
848820

849-
if order in ["K", "A"]:
821+
if order == "K":
850822
if (
851823
x.flags.f_contiguous
852824
and a_min.flags.f_contiguous
@@ -859,8 +831,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
859831
and a_max.flags.c_contiguous
860832
):
861833
order = "C"
862-
else:
863-
order = "C" if order == "A" else "K"
864834
if order == "K":
865835
buf1 = _empty_like_orderK(a_min, buf1_dt)
866836
else:

dpctl/tensor/_linear_algebra_functions.py

+14-19
Original file line numberDiff line numberDiff line change
@@ -765,25 +765,26 @@ def matmul(x1, x2, out=None, dtype=None, order="K"):
765765
# after being checked against x1
766766
out = dpt.empty_like(out)
767767

768+
if order == "A":
769+
order = (
770+
"F"
771+
if all(
772+
arr.flags.f_contiguous
773+
for arr in (
774+
x1,
775+
x2,
776+
)
777+
)
778+
else "C"
779+
)
780+
768781
if buf1_dt is None and buf2_dt is None:
769782
if out is None:
770783
if order == "K":
771784
out = _empty_like_pair_orderK(
772785
x1, x2, res_dt, res_shape, res_usm_type, exec_q
773786
)
774787
else:
775-
if order == "A":
776-
order = (
777-
"F"
778-
if all(
779-
arr.flags.f_contiguous
780-
for arr in (
781-
x1,
782-
x2,
783-
)
784-
)
785-
else "C"
786-
)
787788
out = dpt.empty(
788789
res_shape,
789790
dtype=res_dt,
@@ -823,8 +824,6 @@ def matmul(x1, x2, out=None, dtype=None, order="K"):
823824
if order == "K":
824825
buf2 = _empty_like_orderK(x2, buf2_dt)
825826
else:
826-
if order == "A":
827-
order = "F" if x1.flags.f_contiguous else "C"
828827
buf2 = dpt.empty_like(x2, dtype=buf2_dt, order=order)
829828
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
830829
src=x2, dst=buf2, sycl_queue=exec_q
@@ -878,8 +877,6 @@ def matmul(x1, x2, out=None, dtype=None, order="K"):
878877
if order == "K":
879878
buf1 = _empty_like_orderK(x1, buf1_dt)
880879
else:
881-
if order == "A":
882-
order = "F" if x1.flags.f_contiguous else "C"
883880
buf1 = dpt.empty_like(x1, dtype=buf1_dt, order=order)
884881
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
885882
src=x1, dst=buf1, sycl_queue=exec_q
@@ -929,13 +926,11 @@ def matmul(x1, x2, out=None, dtype=None, order="K"):
929926
out = dpt.squeeze(out, tuple(appended_axes))
930927
return out
931928

932-
if order in ["K", "A"]:
929+
if order == "K":
933930
if x1.flags.f_contiguous and x2.flags.f_contiguous:
934931
order = "F"
935932
elif x1.flags.c_contiguous and x2.flags.c_contiguous:
936933
order = "C"
937-
else:
938-
order = "C" if order == "A" else "K"
939934
if order == "K":
940935
buf1 = _empty_like_orderK(x1, buf1_dt)
941936
else:

0 commit comments

Comments
 (0)