FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add reserve method for owned arrays by ssande7 · Pull Request #1268 · rust-ndarray/ndarray · GitHub

Add reserve method for owned arrays - #1268

Merged
bluss merged 9 commits into
rust-ndarray:masterfrom
ssande7:reserve
Apr 6, 2024
Merged

Add reserve method for owned arrays#1268
bluss merged 9 commits into
rust-ndarray:masterfrom
ssande7:reserve

Conversation

ssande7 commented Mar 11, 2023

Copy link
Copy Markdown
Contributor

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 calling OwnedRepr::reserve in order to expose it.

Benchmark results (appending 100 times to an empty array):

test push_no_reserve ... bench:         900 ns/iter (+/- 52)                                                                                                                          
test push_reserve    ... bench:         739 ns/iter (+/- 50) 

Note I'm new to the crate so I may have missed something, but happy to iterate if there's more to do.

Comment thread src/impl_owned_array.rs
Comment thread src/impl_owned_array.rs

bluss commented Apr 6, 2024

Copy link
Copy Markdown
Member

Rebased, resolved conflict, added test for nonzero alloc to first element pointer

bluss commented Apr 6, 2024

Copy link
Copy Markdown
Member

Thanks a lot for this

Comment thread src/impl_owned_array.rs
pub fn reserve(&mut self, axis: Axis, additional: usize) -> Result<(), ShapeError>
where D: RemoveAxis
{
debug_assert!(axis.index() < self.ndim());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why was the branch that returned early on additional == 0 removed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No reason to hold up the PR on this question I think 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

bluss added this pull request to the merge queue Apr 6, 2024
Merged via the queue into rust-ndarray:master with commit d664f3d Apr 6, 2024
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL