Add try_into_owned_nocopy method#1022
Merged
bluss merged 2 commits intorust-ndarray:masterfrom Nov 7, 2021
Merged
Conversation
Clippy warned that some of the types were too complex, so this commit simplifies those lines and a few others.
Member
|
We want to merge this right? I think the name will be ok |
Member
Author
|
Yes, I still think this is a good idea, and I agree that the name is good enough. |
Member
|
Great, thanks! |
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.
I've been working on improvements to the layout handling in
ndarray-linalgto make the code easier to understand, fix bugs, and avoid unnecessary cloning and by-clone transposes. One of operations I need to implement is, "Convert anArrayBaseinto a LAPACK-compatibleArray(i.e.strides = [1, s], withs >= nrows), while avoiding unnecessary cloning." I don't think it's possible to implement this today without adding more methods toArrayBase. To address this, I propose adding atry_into_owned_nocopymethod which is similar tointo_ownedbut returnsErr(self)if the data would need to be cloned, instead of actually performing the cloning. This way, if the data needs to be cloned, I can clone it into an array of the correct layout, like this:There are other ways this problem could be solved, but
try_into_owned_nocopyis the best I came up with.A couple of notes about the PR:
If we implementEdit: I was wrong; the method is actually useful forDataOwnedforCowReprin another PR, then I'd change the bound ontry_into_owned_nocopyto beS: DataOwned, since there wouldn't be any reason to call it on any non-DataOwnedtypes.S: Dataafter all, and there isn't a strong reason to restrict it toS: DataOwnedanyway.I'm not completely satisfied with the name
try_into_owned_nocopy. Other suggestions would be welcome.