Add internal constructors from_data_ptr(...).with_strides_dim(...) and use everywhere#908
Merged
Add internal constructors from_data_ptr(...).with_strides_dim(...) and use everywhere#908
Conversation
…es_dim These methods will be used instead of the ArrayBase struct constructor expression.
0577c31 to
3c84693
Compare
Member
Author
|
It is now using an empty one-dimensional array for the return value from |
jturner314
reviewed
Feb 3, 2021
Member
There was a problem hiding this comment.
I like the new with_strides_dim method. I made a few minor comments.
…sible
This avoids using the naked ArrayBase { .. } and similar struct
constructors, which should make it easier for us to change
representation in the future if needed.
The constructor methods are unsafe since they rely on the caller to
assert certain invariants; this means that this change increases the
number of `unsafe` code blocks in ndarray, but that's only correct since
every ArrayBase construction is safety-critical w.r.t the validity of
the pointer, dimensions and strides taken together.
The resulting code is often easier to read - especially when we are only
updating the strides and dimensions of an existing array or view.
The .with_strides_dim() method requires the Dimension trait so that
appropriate debug assertions can be added in this method if desired.
This precludes us from using this method in the `Clone` impl, but that's
just a minor flaw and the only exception.
Co-authored-by: Jim Turner <github@turner.link>
bf760c6 to
0d4272f
Compare
bluss
commented
Feb 3, 2021
| @@ -1498,22 +1490,15 @@ where | |||
| return Err(error::incompatible_shapes(&self.dim, &shape)); | |||
| } | |||
| // Check if contiguous, if not => copy all, else just adapt strides | |||
Member
Author
There was a problem hiding this comment.
I see this comment is entirely incorrect (copied from reshape?) but the coming change that will fix into_shape should take care of that..
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.
Use array builder from_data_ptr(...).with_strides_dim(...) where possible
This avoids using the naked ArrayBase { .. } and similar struct
constructors, which should make it easier for us to change
representation in the future if needed.
The constructor methods are unsafe since they rely on the caller to
assert certain invariants; this means that this change increases the
number of
unsafecode blocks in ndarray, but that's only correct sinceevery ArrayBase construction is safety-critical w.r.t the validity of
the pointer, dimensions and strides taken together.
The resulting code is often easier to read - especially when we are only
updating the strides and dimensions of an existing array or view.
The .with_strides_dim() method requires the Dimension trait so that
appropriate debug assertions can be added in this method if desired.
This precludes us from using this method in the
Cloneimpl, but that'sjust a minor flaw and the only exception.