Reuse reduction/dot buffer as sqrt output in linalg.norm - #3062
Draft
antonwolfy wants to merge 2 commits into
Draft
Reuse reduction/dot buffer as sqrt output in linalg.norm#3062antonwolfy wants to merge 2 commits into
antonwolfy wants to merge 2 commits into
Conversation
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.
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3062/index.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the
dpnp.linalg.normimplementation, the 2-norm and Frobenius-norm branches computedsqrt(sum(...))(orsqrt(dot(...))on theaxis=Nonefast path) allocating a fresh array for thesqrtoutput 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=todpnp.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 thesqrtoutput, so the in-place write is safe. On theaxis=Nonefast 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.