Skip to content

Indexing API #166

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 24 commits into from
Feb 11, 2021
Merged

Indexing API #166

merged 24 commits into from
Feb 11, 2021

Conversation

rnett
Copy link
Contributor

@rnett rnett commented Dec 7, 2020

Fixes #164.

One question: Should I also make endpoints named get and set? It's more discoverable to people coming from Python (who usually use [] rather than the stridedSlice op).

There's examples in the Index javadoc.

Copy link
Collaborator

@Craigacp Craigacp left a comment

Choose a reason for hiding this comment

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

More generally these indices don't seem to link up with the indexing operations already available in ndarray, which might prove more confusing as the ndarrays move closer to Tensors given Karl's current refactorings.

@rnett
Copy link
Contributor Author

rnett commented Dec 9, 2020

I looked at that, there's a few concepts that are impossible to map into stridedSlice, which as far as I know is the only Op we could use for this. In particular, seq and hyperslab. The ndarray API also has no ellipses or newaxis.

If we do want to unify APIs, I think it would be easier to map this API onto the current ndarray one the visa versa. To map the ndarray indices onto Operands we'd either have to remove index options, throw runtime exceptions for unsupported ones, or have a TensorIndex or similar sub-interface. If I was doing it I'd probably have a shared Index interface with TensorIndex and NDArrayIndex for the unsupported ones. Although it seems like you could add operations to the ndarray indexing.

@Craigacp
Copy link
Collaborator

Craigacp commented Dec 9, 2020

I think extending the ndarray API to cover the gaps would be worthwhile, and then we can throw exceptions for things which fail to map from ndarray into TF ops.

@rnett
Copy link
Contributor Author

rnett commented Dec 9, 2020

There's some odd things in the ndarray API like At not supporting negative indices, Range not having a stride or supporting negative indices, and having flip, even, and odd separate from [::-1], [::2], and [1::2] (although I like having functions for them, I don't think they need to be their own classes). Do you think I should bring the ndarray indexing a bit closer to Numpy? It would make the differences between the ndarray indexing and the tensor indexing less confusing.

@karllessard
Copy link
Collaborator

karllessard commented Dec 9, 2020

Do you think I should bring the ndarray indexing a bit closer to Numpy? It would make the differences between the ndarray indexing and the tensor indexing less confusing.

Yes, if something is lacking in the NdArray API, it should be added instead of trying to fill the gaps from TensorFlow Java core instead.

If we do want to unify APIs, I think it would be easier to map this API onto the current ndarray one the visa versa. To map the ndarray indices onto Operands...

That was the original intent, we are just not there yet. Again (sorry for that), the tensor type refactoring currently in progress might be helpful to achieve this. I also thing that TType should extend from Operand at some point, so we can pass a tensor directly to an op without converting it to a constant explicitly. I did something like that in a previous draft for the same refactoring here.

Should we also put this PR on hold for now and continue that discussion in #164 ?

@rnett
Copy link
Contributor Author

rnett commented Dec 9, 2020

I also think that TType should extend from Operand at some point

That would be very nice, especially for eager mode, although I'd have to be careful w/ the names for indexing functions (Operand will always be stridedSlice, but NDArray should be something that makes it obvious it's on the NDArray).

I pushed what I have as far as adding to the ndarray API (it's WIP), it doesn't seem that bad, just newaxis, ellipsis, and strided slice. My impression from the refactoring is that Operand indexing will still have to use StridedSlice? If so most of this PR is still fine, I just need to move the builders to the NDArray builders and unify the APIs (which is mostly done as of the latest commit, just needs cleanup). I'll add a comment to #164 about the API unification changes I would like to make.

Depending on the type refactorings you are working on, it seems like once the APIs are merged, we could merge this without running afoul of the upcoming changes.

@google-cla
Copy link

google-cla bot commented Dec 28, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

2 similar comments
@google-cla
Copy link

google-cla bot commented Dec 28, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Dec 28, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@karllessard
Copy link
Collaborator

Idem than #167 (comment)

@rnett rnett marked this pull request as draft December 28, 2020 21:27
@rnett rnett changed the base branch from master to type-refactor December 28, 2020 21:28
@google-cla
Copy link

google-cla bot commented Dec 28, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@karllessard karllessard deleted the branch tensorflow:master December 29, 2020 17:17
@rnett
Copy link
Contributor Author

rnett commented Dec 29, 2020

@karllessard can you re-open this PR too? I don't have the permissions to.

@karllessard
Copy link
Collaborator

I'm really sorry, I don't know why but it does not allow me to do it neither, though I was able to do it with #167 ...

image

@karllessard
Copy link
Collaborator

@rnett
Copy link
Contributor Author

rnett commented Dec 30, 2020

@karllessard I still have no re-open option, but I did the steps there. Can you do it now? I never had the option, even greyed out, I suspect it's permissions in addition to the force push.

@karllessard karllessard reopened this Dec 30, 2020
@rnett rnett changed the base branch from type-refactor to master December 30, 2020 22:58
@rnett rnett marked this pull request as ready for review January 5, 2021 05:12
@rnett
Copy link
Contributor Author

rnett commented Jan 5, 2021

Ok, this is ready for review. One last thing: I'd like to move the builders from Indices to Index, it reads better to me (kind of like if they were nested classes) and is shorter. Thoughts?

@rnett rnett requested a review from Craigacp January 6, 2021 21:12
rnett added 21 commits January 8, 2021 14:10
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
rnett added 2 commits January 24, 2021 14:49
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
@rnett
Copy link
Contributor Author

rnett commented Jan 25, 2021

Before you merge, any more thoughts on Indices vs Index?

@karllessard
Copy link
Collaborator

Yeah I was thinking about that... while I do prefer to move static creators to Index, it is less coherent with the rest of the API like I've explained earlier.

I always had in mind that Indices.* are good candidates to be imported statically. I know that most IDE might complain unless configuring it otherwise, but in Kotlin static imports like these are more frequent. Meaning that whether they are under Index or Indices is less important.

Why not doing it in a seperate PR? That one is fully backward compatible, which I like.

@rnett
Copy link
Contributor Author

rnett commented Jan 25, 2021

Another PR is fine, although I don't know that there will be enough impetus to make one, it's a pretty tiny change. I'd like to have infix or .. style creators for most these in Kotlin, anyways.

@karllessard karllessard merged commit 61b9165 into tensorflow:master Feb 11, 2021
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 this pull request may close these issues.

Indexing/slicing API
3 participants