public interface TType extends Tensor
Typed tensors wrap a RawTensor
by mapping their native memory
to a n-dimensional data space allowing direct I/O access from the JVM.
Subinterfaces of TType
are propagated as a generic parameter to various entities of
TensorFlow to identify the type of the tensor they carry. For example, a
Operand<TFloat32>
is an operand which outputs a 32-bit floating
point tensor. This parameter ensure type-compatibility between operands of a computation at
compile-time. For example:
Ops tf = Ops.create();
Constant<TFloat32> c1 = tf.array(2.0f, 3.0f, 2.0f);
Constant<TFloat32> c2 = tf.array(1.0f, 2.0f, 3.0f);
Constant<TInt32> c3 = tf.array(2, 3, 2);
tf.math.add(c1, c2); // OK
tf.math.add(c1, c3); // Compilation failure
Even if all typed tensors implements somehow NdArray
to provide access to their data, TType
deliberately does not extend directly from this
interface, for the following reasons:
NdArray
at this level could only expose boxed-type accessors, which
are less performant than their primitive equivalent, only exposed by subinterfaces of
NdArray
(e.g. FloatNdArray
).
TType
would need to carry a new generic parameter for typing the NdArray
,
which will increase the verbosity in the signature of any method accepting or returning
an instance of this interface, which is very common.
TType
in a concrete tensor type before
accessing its data guarantees better performance and improves readability.Modifier and Type | Method and Description |
---|---|
default void |
close()
Release resources associated with the Tensor.
|
default DataType |
dataType()
Returns the
DataType of elements stored in the tensor. |
default long |
numBytes()
Returns the size, in bytes, of the tensor data.
|
Class<? extends TType> |
type()
Returns the type of this tensor as a registered subclass of
TType |
Class<? extends TType> type()
TType
default DataType dataType()
Tensor
DataType
of elements stored in the tensor.default long numBytes()
Tensor
default void close()
Tensor
WARNING:This must be invoked for all tensors that were not been produced by an eager operation or memory will be leaked.
The Tensor object is no longer usable after close
returns.
close
in interface AutoCloseable
close
in interface Tensor
Copyright © 2015–2022. All rights reserved.