TType

public interface TType
Known Indirect Subclasses

Common interface for all typed tensors.

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:

  • Implementing 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.
Therefore, enforcing the user to cast a reference of TType in a concrete tensor type before accessing its data guarantees better performance and improves readability.

Public Methods

abstract void
close()
Release resources associated with the Tensor.
abstract DataType
dataType()
Returns the DataType of elements stored in the tensor.
abstract long
numBytes()
Returns the size, in bytes, of the tensor data.
abstract Class<? extends TType>
type()
Returns the type of this tensor as a registered subclass of TType

Inherited Methods

Public Methods

public abstract void close ()

Release resources associated with the 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.

public abstract DataType dataType ()

Returns the DataType of elements stored in the tensor.

public abstract long numBytes ()

Returns the size, in bytes, of the tensor data.

public abstract Class<? extends TType> type ()

Returns the type of this tensor as a registered subclass of TType