Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ This release is compatible with NumPy 2.5.
* Linked the `dpnp_backend_c` library against only the MKL SYCL domains it uses (`BLAS`, `RNG`, `VM`) [#3012](https://github.com/IntelPython/dpnp/pull/3012)
* `dpnp` uses pybind11 3.1.0 [#3015](https://github.com/IntelPython/dpnp/pull/3015)
* Reworked the ASV benchmarks and added end-to-end workload benchmarks derived from dpBench [#2996](https://github.com/IntelPython/dpnp/pull/2996)
* Reduced allocations in `dpnp.linalg.norm` by reusing the reduction result as the `sqrt` output buffer in the 2-norm and Frobenius-norm branches [#3062](https://github.com/IntelPython/dpnp/pull/3062)

### Deprecated

Expand Down
9 changes: 5 additions & 4 deletions dpnp/linalg/dpnp_utils_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,8 +1162,8 @@ def _norm_int_axis(x, ord, axis, keepdims):
return dpnp.abs(x).sum(axis=axis, keepdims=keepdims)
if ord is None or ord == 2:
# special case for speedup
s = (dpnp.conj(x) * x).real
return dpnp.sqrt(dpnp.sum(s, axis=axis, keepdims=keepdims))
s = dpnp.sum((dpnp.conj(x) * x).real, axis=axis, keepdims=keepdims)
return dpnp.sqrt(s, out=s)
if isinstance(ord, (int, float)):
absx = dpnp.abs(x)
absx **= ord
Expand Down Expand Up @@ -1215,7 +1215,8 @@ def _norm_tuple_axis(x, ord, row_axis, col_axis, keepdims):
row_axis -= 1
ret = dpnp.abs(x).sum(axis=col_axis).min(axis=row_axis)
elif ord in [None, "fro", "f"]:
ret = dpnp.sqrt(dpnp.sum((dpnp.conj(x) * x).real, axis=axis))
ret = dpnp.sum((dpnp.conj(x) * x).real, axis=axis)
ret = dpnp.sqrt(ret, out=ret)
elif ord == "nuc":
ret = _multi_svd_norm(x, row_axis, col_axis, dpnp.sum)
else:
Expand Down Expand Up @@ -2360,7 +2361,7 @@ def dpnp_norm(x, ord=None, axis=None, keepdims=False):
sqnorm = dpnp.dot(x_real, x_real) + dpnp.dot(x_imag, x_imag)
else:
sqnorm = dpnp.dot(x, x)
ret = dpnp.sqrt(sqnorm)
ret = dpnp.sqrt(sqnorm, out=sqnorm)
if keepdims:
ret = ret.reshape((1,) * ndim)
return ret
Expand Down
Loading