From 1531a63f2361ad22ef0aae658445631b5abd38cb Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 7 Feb 2024 20:12:27 +0000 Subject: [PATCH 1/2] Coverity report fix for _linear_agebra_functions Made changes similar to those made in _elementwise_common.py file, where processing of order="A" keyword is done based on flags of both src1 and src2 irrespective of type promotion steps necessary. --- dpctl/tensor/_linear_algebra_functions.py | 33 ++++++++++------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/dpctl/tensor/_linear_algebra_functions.py b/dpctl/tensor/_linear_algebra_functions.py index 9f8aef8a48..48829a8418 100644 --- a/dpctl/tensor/_linear_algebra_functions.py +++ b/dpctl/tensor/_linear_algebra_functions.py @@ -765,6 +765,19 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): # after being checked against x1 out = dpt.empty_like(out) + if order == "A": + order = ( + "F" + if all( + arr.flags.f_contiguous + for arr in ( + x1, + x2, + ) + ) + else "C" + ) + if buf1_dt is None and buf2_dt is None: if out is None: if order == "K": @@ -772,18 +785,6 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): x1, x2, res_dt, res_shape, res_usm_type, exec_q ) else: - if order == "A": - order = ( - "F" - if all( - arr.flags.f_contiguous - for arr in ( - x1, - x2, - ) - ) - else "C" - ) out = dpt.empty( res_shape, dtype=res_dt, @@ -823,8 +824,6 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): if order == "K": buf2 = _empty_like_orderK(x2, buf2_dt) else: - if order == "A": - order = "F" if x1.flags.f_contiguous else "C" buf2 = dpt.empty_like(x2, dtype=buf2_dt, order=order) ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x2, dst=buf2, sycl_queue=exec_q @@ -878,8 +877,6 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): if order == "K": buf1 = _empty_like_orderK(x1, buf1_dt) else: - if order == "A": - order = "F" if x1.flags.f_contiguous else "C" buf1 = dpt.empty_like(x1, dtype=buf1_dt, order=order) ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x1, dst=buf1, sycl_queue=exec_q @@ -929,13 +926,11 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): out = dpt.squeeze(out, tuple(appended_axes)) return out - if order in ["K", "A"]: + 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: order = "C" - else: - order = "C" if order == "A" else "K" if order == "K": buf1 = _empty_like_orderK(x1, buf1_dt) else: From 1db33c66105676744853a6e5bd724f2186496558 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 7 Feb 2024 20:18:44 +0000 Subject: [PATCH 2/2] Coverity report fix for _clip Made changes similar to those made in _elementwise_common.py file, where processing of order="A" keyword is done based on flags of all arguments irrespective of type promotion steps necessary. --- dpctl/tensor/_clip.py | 82 ++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 56 deletions(-) diff --git a/dpctl/tensor/_clip.py b/dpctl/tensor/_clip.py index 9a310df618..08ce97f476 100644 --- a/dpctl/tensor/_clip.py +++ b/dpctl/tensor/_clip.py @@ -298,6 +298,18 @@ def _clip_none(x, val, out, order, _binary_fn): else: val_ary = dpt.asarray(val, dtype=val_dtype, sycl_queue=exec_q) + if order == "A": + order = ( + "F" + if all( + arr.flags.f_contiguous + for arr in ( + x, + val_ary, + ) + ) + else "C" + ) if val_dtype == res_dt: if out is None: if order == "K": @@ -305,18 +317,6 @@ def _clip_none(x, val, out, order, _binary_fn): x, val_ary, res_dt, res_shape, res_usm_type, exec_q ) else: - if order == "A": - order = ( - "F" - if all( - arr.flags.f_contiguous - for arr in ( - x, - val_ary, - ) - ) - else "C" - ) out = dpt.empty( res_shape, dtype=res_dt, @@ -347,8 +347,6 @@ def _clip_none(x, val, out, order, _binary_fn): if order == "K": buf = _empty_like_orderK(val_ary, res_dt) else: - if order == "A": - order = "F" if x.flags.f_contiguous else "C" buf = dpt.empty_like(val_ary, dtype=res_dt, order=order) ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=val_ary, dst=buf, sycl_queue=exec_q @@ -473,8 +471,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"): if order == "K": out = _empty_like_orderK(x, x.dtype) else: - if order == "A": - order = "F" if x.flags.f_contiguous else "C" out = dpt.empty_like(x, order=order) 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"): else: a_max = dpt.asarray(max, dtype=max_dtype, sycl_queue=exec_q) + if order == "A": + order = ( + "F" + if all( + arr.flags.f_contiguous + for arr in ( + x, + a_min, + a_max, + ) + ) + else "C" + ) if buf1_dt is None and buf2_dt is None: if out is None: if order == "K": @@ -672,19 +681,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"): exec_q, ) else: - if order == "A": - order = ( - "F" - if all( - arr.flags.f_contiguous - for arr in ( - x, - a_min, - a_max, - ) - ) - else "C" - ) out = dpt.empty( res_shape, dtype=res_dt, @@ -718,18 +714,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"): if order == "K": buf2 = _empty_like_orderK(a_max, buf2_dt) else: - if order == "A": - order = ( - "F" - if all( - arr.flags.f_contiguous - for arr in ( - x, - a_min, - ) - ) - else "C" - ) buf2 = dpt.empty_like(a_max, dtype=buf2_dt, order=order) ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=a_max, dst=buf2, sycl_queue=exec_q @@ -784,18 +768,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"): if order == "K": buf1 = _empty_like_orderK(a_min, buf1_dt) else: - if order == "A": - order = ( - "F" - if all( - arr.flags.f_contiguous - for arr in ( - x, - a_max, - ) - ) - else "C" - ) buf1 = dpt.empty_like(a_min, dtype=buf1_dt, order=order) ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=a_min, dst=buf1, sycl_queue=exec_q @@ -846,7 +818,7 @@ def clip(x, /, min=None, max=None, out=None, order="K"): ht_binary_ev.wait() return out - if order in ["K", "A"]: + if order == "K": if ( x.flags.f_contiguous and a_min.flags.f_contiguous @@ -859,8 +831,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"): and a_max.flags.c_contiguous ): order = "C" - else: - order = "C" if order == "A" else "K" if order == "K": buf1 = _empty_like_orderK(a_min, buf1_dt) else: