Skip to content

Reuse reduction/dot buffer as sqrt output in linalg.norm - #3062

Draft
antonwolfy wants to merge 2 commits into
masterfrom
norm-sqrt-out
Draft

Reuse reduction/dot buffer as sqrt output in linalg.norm#3062
antonwolfy wants to merge 2 commits into
masterfrom
norm-sqrt-out

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

In the dpnp.linalg.norm implementation, the 2-norm and Frobenius-norm branches computed sqrt(sum(...)) (or sqrt(dot(...)) on the axis=None fast path) allocating a fresh array for the sqrt output on top of the array already produced by the reduction.

These branches now capture the reduction (or dot) result and pass it back as out= to dpnp.sqrt, so the intermediate buffer is reused as the output instead of allocating a new one. The reused buffer is a private, unaliased array in every case, and its dtype matches the sqrt output, so the in-place write is safe. On the axis=None fast path the reused buffer is a scalar, so the change there is for consistency.

This is an allocation saving only; it does not change results or reduce the number of kernel launches.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

Pass out= to dpnp.sqrt in the 2-norm and Frobenius-norm branches so the
existing reduction (or dot) result is reused as the sqrt output buffer
instead of allocating a new array.
@antonwolfy antonwolfy self-assigned this Sep 8, 2026
@antonwolfy antonwolfy added this to the 0.21.0 release milestone Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3062/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant