Skip to content

[TypeRefact] Added Shaped interface shared across different containers #153

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 2 commits into from
Nov 23, 2020

Conversation

karllessard
Copy link
Collaborator

@karllessard karllessard commented Nov 19, 2020

PR related to #139.

It extracts the shape-related operators of the NdArray interface into a separate interface (Shaped) that is shared across the client for each container with a given shape.

I had to rename the output of a few operators as it was conflicting with the size() method of Shaped, which is now inherited by Operand.

CC\ @deansher

@karllessard karllessard requested a review from Craigacp November 20, 2020 02:56
@karllessard karllessard changed the title [TypeRefact #1] Added Shaped interface shared across different containers [TypeRefact] Added Shaped interface shared across different containers Nov 20, 2020
deansher
deansher previously approved these changes Nov 20, 2020
Copy link
Contributor

@deansher deansher left a comment

Choose a reason for hiding this comment

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

To me, this is a clear improvement. It does add a slight hand-wave to code like the following, but I lean toward believing that the previous, more explicit, version required just as much subtle knowledge as the new, more hand-wavy version.

Example of the old:

  public Operand<T> call(Operand<T> input) {
    Shape shape = input.asOutput().shape();

This now becomes:

  public Operand<T> call(Operand<T> input) {
    Shape shape = input.shape();

The old version explicitly showed it was talking about input's shape as an Output rather than as an eagerly evaluated Tensor. Arguably, that was good. But as someone who only recently learned this distinction (and who still feels slightly insecure on this point), I can say that .asOutput() didn't clarify this for me before I understood, and that it seems unnecessary now that I do.

I did suggest retaining overriding-class-specific javadoc in a couple of places that at least hints at this distinction.

@karllessard
Copy link
Collaborator Author

Thanks @deansher , I've updated the sources with your suggestions

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.

LGTM.

However I did go and look at org.tensorflow.ndarray.Shape again. The computation of the size seems racy, and it stores it as a boxed Long rather than a primitive long. At the very least it should store it as a long. It might even be better to compute the shape size eagerly in the constructor, then the whole object becomes immutable.

@karllessard
Copy link
Collaborator Author

It might even be better to compute the shape size eagerly in the constructor, then the whole object becomes immutable.

That was my initial implementation, as it's the most intuitive one as well, but I've rolled back to that lazy-initialization of the size because surprisingly its computation had a bigger impact on my benchmark results that I was expecting.

We can revisit this later if you want but just to let you know that it is not a design mistake but a deliberated choice.

@karllessard karllessard merged commit fc3d960 into tensorflow:master Nov 23, 2020
@karllessard karllessard deleted the type-refactor branch November 23, 2020 14:37
@Craigacp
Copy link
Collaborator

It might even be better to compute the shape size eagerly in the constructor, then the whole object becomes immutable.

That was my initial implementation, as it's the most intuitive one as well, but I've rolled back to that lazy-initialization of the size because surprisingly its computation had a bigger impact on my benchmark results that I was expecting.

We can revisit this later if you want but just to let you know that it is not a design mistake but a deliberated choice.

Ok, do you have the output of that benchmark before and after somewhere or should I run it myself?

@karllessard
Copy link
Collaborator Author

Ok, do you have the output of that benchmark before and after somewhere or should I run it myself?

Yes give it a try and let see what you observe on your side. If I remember correctly, pay more attention on this test

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.

3 participants