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-linalg
to 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 anArrayBase
into 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_nocopy
method which is similar tointo_owned
but 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_nocopy
is the best I came up with.A couple of notes about the PR:
If we implementEdit: I was wrong; the method is actually useful forDataOwned
forCowRepr
in another PR, then I'd change the bound ontry_into_owned_nocopy
to beS: DataOwned
, since there wouldn't be any reason to call it on any non-DataOwned
types.S: Data
after all, and there isn't a strong reason to restrict it toS: DataOwned
anyway.I'm not completely satisfied with the name
try_into_owned_nocopy
. Other suggestions would be welcome.