Skip to content

Indexing with negative step sizes #24

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
FilipeMaia opened this issue Aug 28, 2015 · 10 comments
Closed

Indexing with negative step sizes #24

FilipeMaia opened this issue Aug 28, 2015 · 10 comments
Milestone

Comments

@FilipeMaia
Copy link
Contributor

Currently arrays cannot be indexed with negative step sizes.

@FilipeMaia FilipeMaia changed the title Indexing with negative steps sizes Indexing with negative step sizes Aug 28, 2015
@FilipeMaia
Copy link
Contributor Author

The C++ side can almost handle negative step sizes, the only obvious roadblock I see is there being no way to specify seq.begin at the end of the array. calcDims() needs a few changes to take the negative steps into account, in particular in the case when the begin and end are not specified.

@pavanky
Copy link
Member

pavanky commented Aug 28, 2015

Can this be closed after the PR ?

@FilipeMaia
Copy link
Contributor Author

I'm afraid not, the issue is deeper. There's no easy way to do array[::-1] because there's no way (that I know) to specify that seq.begin corresponds to the end of the array in the C/C++ API. The fixes I did only handle cases where the begin and end are specified.

@pavanky
Copy link
Member

pavanky commented Aug 28, 2015

af::seq(end,0, -1) does not work ?

@FilipeMaia
Copy link
Contributor Author

Nope it gives:

af::exception: ArrayFire Exception(203): Invalid input size
In /Users/filipe/src/arrayfire/src/api/cpp/array.cpp:725

Code:

#include <arrayfire.h>

int main(){
  af::array a = af::randu(3);
  af_print(a);
  af_print(a(af::seq(af::end,0,-1)));
}

@pavanky
Copy link
Member

pavanky commented Aug 28, 2015

OK, I think I can still handle this in python itself. If you are not working on this and #26 I will give a shot at fixing them.

@FilipeMaia
Copy link
Contributor Author

If you look at calcDims when end is 0 you end up on:
DIM_ASSERT(1, seq.begin >= -DBL_MIN && seq.begin < parentDim);

which will fail as af::end is smaller than -DBL_MIN

@FilipeMaia
Copy link
Contributor Author

I'm not working on it, I have workarounds for my code.

@pavanky
Copy link
Member

pavanky commented Aug 28, 2015

Ok, I think I am going to handle this upstream. The workarounds are ugly.

@pavanky
Copy link
Member

pavanky commented Sep 16, 2015

This is fixed in 3.1.1 release. I think we can safely close this.

@pavanky pavanky closed this as completed Sep 16, 2015
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