Add reserve method for owned arrays#1268
Merged
bluss merged 9 commits intorust-ndarray:masterfrom Apr 6, 2024
Merged
Conversation
bluss
reviewed
May 6, 2023
bluss
reviewed
Mar 10, 2024
Testing when the allocation to first element offset is nonzero.
Member
|
Rebased, resolved conflict, added test for nonzero alloc to first element pointer |
Member
|
Thanks a lot for this |
bluss
approved these changes
Apr 6, 2024
bluss
reviewed
Apr 6, 2024
| pub fn reserve(&mut self, axis: Axis, additional: usize) -> Result<(), ShapeError> | ||
| where D: RemoveAxis | ||
| { | ||
| debug_assert!(axis.index() < self.ndim()); |
Member
There was a problem hiding this comment.
Why was the branch that returned early on additional == 0 removed?
Member
There was a problem hiding this comment.
No reason to hold up the PR on this question I think 🙂
Contributor
Author
There was a problem hiding this comment.
Why was the branch that returned early on additional == 0 removed?
I think that was because it was faster (at least on my machine) without it, but it's been a while so could be worth re-testing with it in.
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.
This PR adds an
array.reserve(axis, additional)method for use when appending multiple times to an array.It abstracts over the code in
appendthat was callingOwnedRepr::reservein order to expose it.Benchmark results (appending 100 times to an empty array):
Note I'm new to the crate so I may have missed something, but happy to iterate if there's more to do.