Skip to content

Add into_scalar method for Array0 #535

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

Merged
merged 1 commit into from
Nov 14, 2018

Conversation

jturner314
Copy link
Member

@jturner314 jturner314 commented Nov 11, 2018

Other possible names: into_first, into_inner, unwrap.

Edit: I just realized the implementation is broken and I need to fix it. Don't merge this yet!

Edit2: Fixed now! (See the first part of the array0_into_scalar test for the case where my original implementation was broken.)

@jturner314 jturner314 force-pushed the array0-into-scalar branch 2 times, most recently from 356204b to d859202 Compare November 12, 2018 03:58
@LukeMathWalker
Copy link
Member

This would avoid using the [()] which I think is quite confusing/difficult to find out. Good addition!

let index = (first - base) / size;
debug_assert_eq!((first - base) % size, 0);
// Remove the element at that index and return it.
self.data.0.remove(index)
Copy link
Member

Choose a reason for hiding this comment

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

Gnarly but it works fine. Maybe a comment to explain that the len of the Vec might be bigger than the array's current len

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I've added a explanatory comment. If someone changes the implementation in the future, the test will also help catch this edge case.

@jturner314
Copy link
Member Author

Do you think it would make sense to add .into_first() for all Arrays (since we have .first() and .first_mut() methods), or should we just have .into_scalar() for Array0?

@jturner314
Copy link
Member Author

Never mind. I think .into_scalar() for Array0 makes sense because .into_first() for general Arrays would have to return an Option.

@jturner314 jturner314 merged commit 245cfbb into rust-ndarray:master Nov 14, 2018
@jturner314 jturner314 deleted the array0-into-scalar branch November 14, 2018 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants