-
Notifications
You must be signed in to change notification settings - Fork 214
[Type Refactor] Merge TType and Tensor instances as a single entity #160
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
[Type Refactor] Merge TType and Tensor instances as a single entity #160
Conversation
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/DataType.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/EagerOperation.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/types/family/TType.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/types/family/TType.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/types/TBool.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're in here, is it worth moving the contents of the types.family
package into the types
package? It seems strange to me to have the interfaces at a lower level than the concrete implementations.
tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/DebuggingOps.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/Ops.java
Show resolved
Hide resolved
* @param tensor a Tensor holding the constant value | ||
* @return a constant of the same data type as `tensor` | ||
*/ | ||
public <T extends TType> Constant<T> capture(T tensor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/capture/copy/ or immutableCopy
? I don't particularly like the name capture here as it doesn't actually change the state of the tensor argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like capture neither. As discussed here, eventually the tensors could be automatically converted to constants so we will not need to call this endpoint anymore. Still, I now think copy
do sound more appropriate as well, I'll make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok as copy
already exist as another primitive op, I've decided to rename capture
by constantOf
, as it is close enough to the original constant
name and will be easier to find by our users on auto-completion.
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/DataType.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/RawTensor.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/types/TBfloat16.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/types/family/TType.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/types/family/TType.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/op/core/GradientsTest.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/utils/ShapeUtils.java
Show resolved
Hide resolved
I'm not opposed to this but let's keep it for another PR, more changes in this package are planned for the refactoring in progress. |
72d0653
to
598fdc3
Compare
598fdc3
to
8773ccc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ensorflow#160) * Merge TType and Tensor instances as a single entity * Rectify documentation based on PR review * Rebase on master
This PR introduces some breaking changes related to
Tensor
and their relationship with theNdArray
data structure, in an effort of simplification and standardization.Instances of
TType
(e.g.TFloat32
,TInt32
, etc.) now implements directlyTensor
, which has been converted to a non-parameterized interface. This allows direct access to the tensor n-dimensional data space from a tensor instance, without the need to dereference to a second object by callingTensor.data()
.An instance of
TType
can now be passed directly to any method accepting aTensor
in input, e.g.Session.Runner.feed
. In addition, it is now possible to cast directly a tensor of an unknown type using standard Java explicit or implicit type casting, instead of the custom methodexpect
.In a nutshell, important and/or breaking changes are:
Tensor
from a parameterized class to an non-parameterized interfaceTensor
fromTType
implementationsRawTensor
implementation ofTensor
that takes care, among other things, of wrapping the native handle of the tensor in a protected wayTensor.data()
,Tensor.expect()
andOperand.data()
methodstf.constant(TType)
has to be renamed totf.capture(TType)
to avoid conflict with otherConstant
endpoints (left untouched).tf.capture
will also become obsolete by implementing directlyOperand
from tensors.CC\ @deansher , @Craigacp , @wmeddie