-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reserve method for owned arrays #1268
Conversation
Testing when the allocation to first element offset is nonzero.
Rebased, resolved conflict, added test for nonzero alloc to first element pointer |
Thanks a lot for this |
pub fn reserve(&mut self, axis: Axis, additional: usize) -> Result<(), ShapeError> | ||
where D: RemoveAxis | ||
{ | ||
debug_assert!(axis.index() < self.ndim()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the branch that returned early on additional == 0 removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to hold up the PR on this question I think 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 PR adds an
array.reserve(axis, additional)
method for use when appending multiple times to an array.It abstracts over the code in
append
that was callingOwnedRepr::reserve
in 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.