Skip to content
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

into_scalar() for 0-dimensional array views #688

Closed
Palladinium opened this issue Aug 18, 2019 · 3 comments
Closed

into_scalar() for 0-dimensional array views #688

Palladinium opened this issue Aug 18, 2019 · 3 comments
Labels
enhancement good first issue A good issue to start contributing to ndarray!

Comments

@Palladinium
Copy link

Palladinium commented Aug 18, 2019

Array0 has the handy into_scalar() method, which from what I gather roughly equates to calling arr.index(Ix0()).

Unfortunately, this isn't available for array views, so we're stuck using the more obscure and verbose syntax for ArrayView0 and ArrayViewMut0. It looks to me like it'd just be a matter to move the into_scalar() impl up to ArrayBase, letting the view representation choose the return type.

Would it be a breaking change? How difficult would it be to implement?

@bluss
Copy link
Member

bluss commented Sep 1, 2019

arr.index(Ix0()) is the syntax that looks obscure and verbose to me, I'm not sure why you'd use that.

The standard way of accessing an element in a 0-dim array is to use a 0-dim index and using indexing notation:

// Alternative A
let element = array[[]];

// Alternative B
let element = array[()];

@jturner314
Copy link
Member

I think @Palladinium may be referring to the .index() method from the IndexLonger trait. It's currently the best way to get an &'a A from an ArrayView0<'a, A, D>. (Note the matching lifetimes.)

I do think it would make sense to add .into_scalar() methods to ArrayView0 and ArrayViewMut0 for convenience. (Those types specifically, not all of ArrayBase<S, Ix0>.) It would not be a breaking change, and it would be easy to implement.

@LukeMathWalker
Copy link
Member

LukeMathWalker commented Sep 8, 2019

Solved by #700

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue A good issue to start contributing to ndarray!
Projects
None yet
Development

No branches or pull requests

4 participants