Skip to content

Indexing/slicing API #164

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
rnett opened this issue Dec 5, 2020 · 1 comment · Fixed by #166
Closed

Indexing/slicing API #164

rnett opened this issue Dec 5, 2020 · 1 comment · Fixed by #166

Comments

@rnett
Copy link
Contributor

rnett commented Dec 5, 2020

If you want to index a tensor currently your only choice is strided_slice or slice, neither of which have good APIs.

I'd like to create an indexing API that supports point indices, slices, strided slices, ellipses, all, and newaxis. This isn't particularly hard to do by using strided_slice, I already have a similar Kotlin API I can port. This will also port well to the Kotlin API, especially with the rangeTo operator.

I'd like the usage to look something like:

tf.slice(x, Index.point(0), Index.all, Index.slice(0, 5, 2) // [0, :, 0:5::2]

tf.slice(x, Index.newaxis, Index.point(10, true), Index.elipses) // [tf.newaxis, 10:11, ...]

This would cover the assign variants, too.

@rnett rnett mentioned this issue Dec 7, 2020
@rnett
Copy link
Contributor Author

rnett commented Dec 9, 2020

I'm now trying to unify the Operand indexing with ndarray indexing. The basic differences and what I'd like to do to resolve them are:

  • Operand doesn't (and can't) support hyperslab or seq. It's easy enough to keep them and use types to forbid using them on tensors. How useful are they though? They don't match Python slicing and it would make things a little cleaner to remove them.
  • NDArray indexing needs to support newaxis, ellipsis, and strided slice. None of this is particularly hard, as of the lasted commit to my PR it's there, if untested and probably buggy.
  • There's lots of NDArray index classes that can be done using the new strided slice. Even, Flip, Odd, From, To, Range, Step, and All are all doable as strided slices (::2, ::-1, 1::2, n:, :n, n:m, ::k, :). I don't see any reason to keep them, their methods in Indices could just use slice (I'd add checks for performance).

More minor changes:
I'd like to rename the builder class to Index. Imo Index.point() reads better than Indices.point().
The StridedSlice op supports a point index without removing the dimension, NDArray should as well.

cc @karllessard

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 a pull request may close this issue.

1 participant