Skip to content

Ranges (signed ranges) as axis extents in dimensions #152

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

Closed
Luthaf opened this issue Mar 14, 2016 · 4 comments
Closed

Ranges (signed ranges) as axis extents in dimensions #152

Luthaf opened this issue Mar 14, 2016 · 4 comments

Comments

@Luthaf
Copy link

Luthaf commented Mar 14, 2016

Do you have plans for negative indexing in arrays? Or is it even already possible? I did not found documentation about it.

I like the capacities of Fortran here, where you can write

! 3D Array with two range-based dimensions and one dimension going from 1 to 120
real :: array(-42:42, -42:42, 120) 
real :: b

b = array(-6, 18, 22)

It make expressing some algorithms much easier.

Rust support could look something like

let array = OwnedArray::from_elem((-42..42, -42..42, 120), 1.);
let b = array[(-6, 18, 22)];

That would require allowing Range as dimensions, and isize as indexes.

Edit: I just found a mention to Ixs for signed dimensions, but nothing about Range size. Is it related to that feature or not?

@bluss
Copy link
Member

bluss commented Mar 14, 2016

Using signed ranges as the size of axes is not something we are going to do. Negative indices can be used with slicing right now, negative indices count from the back of the axis, so .slice(s![..-1, ..-1]) is an array slice of everything except the last row & last column.

@bluss
Copy link
Member

bluss commented Mar 14, 2016

In python, that would be [:-1, :-1].

@Luthaf
Copy link
Author

Luthaf commented Mar 14, 2016

Ok, so this is more about Python style multi-dimensional arrays. I'll see if I can work around and express my algorithms differently, or if I need to implement my own multi-dimensional array. Thank you for the quick answer !

@bluss
Copy link
Member

bluss commented Apr 6, 2017

The previous No was certainly the most productive answer, and honest too, because it's the easiest to deliver on 😉.

Either way, no promises, just some notes about what separates ndarray from being able to support it. If we make some changes incrementally, we might be able to generalize it enough to support it down the line.

  • Split Dimension trait. Need to separate the notion of the extent of each axis from the notion of a set of indices.

Links:

@bluss bluss changed the title Negative indexing Ranges (signed ranges) as axis extents in dimensions Apr 6, 2017
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

No branches or pull requests

2 participants