Shapes

public abstract class Shapes

An operator providing methods on org.tensorflow.op.core.Shape tensors and 1d operands that represent the dimensions of a shape.

Ops tf = Ops.create();
 Operand<TFloat32> yPred = tf.constant(new float[][][] { { {0f, 0.5f, {0.3f, 0.9f} } });
 Shape predShape = tf.shape(yPred);
 Operand numLabels =
     tf.reduceProd(tf.shape.takeLast(predShape, // take all but the first dimension
         tf.math.sub(  // by subtract 1 from the total dimensions represent by  predShape
             tf.shape.numDimensions(predShape),
             tf.constant(1))),
         tf.constant(0));

 Operand numPred = tf.shape.size(predShape, tf.constant(0));
 Operand predFlat = tf.shape.flatten(yPred);

 Shape predShape64 = tf.shape(yPred, TInt64.class);
 Operand predSqueezed = tf.shape.squeeze(predShape64, TInt64.class);
 }

Public Constructors

Shapes()

Public Methods

static Operand<TInt64>
append(Scope scope, Shape<TInt64> shape, long lastDimension)
Creates a 1-dimensional operand containing the dimensions of a shape followed by the last dimension.
static Operand<TInt32>
append(Scope scope, Shape<TInt32> shape, int lastDimension)
Creates a 1-dimensional operand containing the dimensions of a shape followed by the last dimension.
static <T extends TNumber> Operand<T>
append(Scope scope, Operand<T> shape, Operand<T> shapeToAppend)
Creates a 1-dimensional operand that represents a new shape containing the dimensions of the operand representing a shape, followed by the dimensions of an operand representing a shape to append.
static <T extends TType, U extends TNumber> Operand<T>
flatten(Scope scope, Operand<T> operand, Class<U> type)
Flatten the operand to 1 dimension
static <U extends TNumber> Operand<U>
flatten(Scope scope, Shape<U> shape, Class<U> type)
Flatten the shape to 1 dimension.
static <T extends TType> Operand<T>
flatten(Scope scope, Operand<T> operand)
Flatten the operand to 1 dimension.
static Operand<TInt32>
flatten(Scope scope, Shape<TInt32> shape)
Flatten the shape to 1 dimension.
static <U extends TNumber> Operand<U>
head(Scope scope, Shape<U> shape, Class<U> type)
Creates a 1-dimensional Operand containing the Shape's first dimension.
static Operand<TInt32>
head(Scope scope, Shape<TInt32> shape)
Creates a 1-dimensional Operand containing the Shape's first dimension.
static Operand<TInt32>
numDimensions(Scope scope, Shape<TInt32> shape)
Get the number of dimensions of the shape object.
static <U extends TNumber> Operand<U>
numDimensions(Scope scope, Shape<U> shape, Class<U> type)
Get the number of dimensions of the shape object.
static Operand<TInt64>
prepend(Scope scope, Shape<TInt64> shape, long firstDimension)
Creates a 1-dimensional operand containing the first dimension followed by the dimensions of the shape.
static <T extends TNumber> Operand<T>
prepend(Scope scope, Operand<T> shape, Operand<T> shapeToPrepend)
Creates a 1-dimensional operand that represents a new shape containing the dimensions of an operand representing the shape to prepend, followed by the dimensions of an operand representing a shape.
static Operand<TInt32>
prepend(Scope scope, Shape<TInt32> shape, int firstDimension)
Creates a 1-dimensional operand containing the first dimension followed by the dimensions of the shape.
static <U extends TNumber> Operand<U>
reduceDims(Scope scope, Shape<U> shape, Operand<U> axis, Class<U> type)
Reduces the shape to the specified axis.
static Operand<TInt32>
reduceDims(Scope scope, Shape<TInt32> shape, Operand<TInt32> axis)
Reduces the shape to the specified axis.
static <T extends TType> Operand<T>
reduceDims(Scope scope, Operand<T> operand, Operand<TInt32> axis)
Reshapes the operand by reducing the shape to the specified axis.
static <T extends TType, U extends TNumber> Operand<T>
reduceDims(Scope scope, Operand<T> operand, Operand<U> axis, Class<U> type)
Reshapes the operand by reducing the shape to the specified axis.
static <U extends TNumber> Operand<U>
size(Scope scope, Shape<U> shape, Class<U> type)
Get the size represented by the TensorFlow shape.
static <T extends TType> Operand<TInt32>
size(Scope scope, Operand<T> input, Operand<TInt32> dim)
Get the size of the specified dimension for the shape of the tensor.
static Operand<TInt32>
size(Scope scope, Shape<TInt32> shape)
Get the size represented by the TensorFlow shape.
static Operand<TInt32>
size(Scope scope, Shape<TInt32> shape, Operand<TInt32> dim)
Get the size of the specified dimension in the shape.
static <U extends TNumber> Operand<U>
size(Scope scope, Shape<U> shape, Operand<U> dim, Class<U> type)
Get the size of the specified dimension in the shape.
static <T extends TType, U extends TNumber> Operand<U>
size(Scope scope, Operand<T> input, Operand<U> dim, Class<U> type)
Get the size of the specified dimension for the shape of the tensor.
static Operand<TInt32>
squeeze(Scope scope, Shape<TInt32> shape)
Removes dimensions of size 1 from the shape.
static <U extends TNumber> Operand<U>
squeeze(Scope scope, Shape<U> shape, Class<U> type)
Removes dimensions of size 1 from the shape.
static Operand<TInt32>
tail(Scope scope, Shape<TInt32> shape)
Creates a 1-dimensional Operand that contains the dimension matching the last dimension of the Shape.
static <U extends TNumber> Operand<U>
tail(Scope scope, Shape<U> shape, Class<U> type)
Creates a 1-dimensional Operand that contains the dimension matching the last dimension of * the Shape.
static Operand<TInt32>
take(Scope scope, Shape<TInt32> shape, Operand<TInt32> n)
Creates a 1-dimensional operand with the dimensions matching the first n dimensions of the shape.
static <U extends TNumber> Operand<U>
take(Scope scope, Shape<U> shape, Operand<U> n, Class<U> type)
Creates a 1-dimensional operand containin the dimensions matching the first n dimensions of the shape.
static <U extends TNumber> Operand<U>
takeLast(Scope scope, Shape<U> shape, Operand<U> n, Class<U> type)
Creates a 1-dimensional operand containing the dimensions matching the last n dimensions of the shape.
static <U extends TNumber> Operand<TInt32>
takeLast(Scope scope, Shape<TInt32> shape, Operand<TInt32> n)
Creates a 1-dimensional operand containing the dimensions matching the last n dimensions of the shape.

Inherited Methods

Public Constructors

public Shapes ()

Public Methods

public static Operand<TInt64> append (Scope scope, Shape<TInt64> shape, long lastDimension)

Creates a 1-dimensional operand containing the dimensions of a shape followed by the last dimension.

Parameters
scope current scope
shape the TensorFlow shape
lastDimension the dimension(s) to append
Returns
  • a 1-dimensional operand containing the dimensions of a shape followed by the last dimension

public static Operand<TInt32> append (Scope scope, Shape<TInt32> shape, int lastDimension)

Creates a 1-dimensional operand containing the dimensions of a shape followed by the last dimension.

Parameters
scope current scope
shape the TensorFlow shape
lastDimension the dimension(s) to append
Returns
  • a 1-dimensional operand containing the dimensions of a shape followed by the last dimension

public static Operand<T> append (Scope scope, Operand<T> shape, Operand<T> shapeToAppend)

Creates a 1-dimensional operand that represents a new shape containing the dimensions of the operand representing a shape, followed by the dimensions of an operand representing a shape to append.

Parameters
scope current scope
shape the TensorFlow shape
shapeToAppend the other shape to append
Returns
  • a 1-dimensional operand that represents a new shape containing the dimensions of the operand representing a shape, followed by the dimensions of an operand representing a shape to append

public static Operand<T> flatten (Scope scope, Operand<T> operand, Class<U> type)

Flatten the operand to 1 dimension

Parameters
scope current scope
operand the operand to flatten
type the shape datatype
Returns
  • the reshaped operand

public static Operand<U> flatten (Scope scope, Shape<U> shape, Class<U> type)

Flatten the shape to 1 dimension.

Parameters
scope current scope
shape the TensorFlow shape
type the shape datatype
Returns
  • the flattened shape

public static Operand<T> flatten (Scope scope, Operand<T> operand)

Flatten the operand to 1 dimension.

Parameters
scope current scope
operand the operand to flatten
Returns
  • the reshaped operand

public static Operand<TInt32> flatten (Scope scope, Shape<TInt32> shape)

Flatten the shape to 1 dimension.

Parameters
scope current scope
shape the TensorFlow shape
Returns
  • the flattened shape

public static Operand<U> head (Scope scope, Shape<U> shape, Class<U> type)

Creates a 1-dimensional Operand containing the Shape's first dimension.

Parameters
scope current scope
shape the TensorFlow shape
type the shape datatype.
Returns
  • a 1-dimensional Operand containing the Shape's first dimension

public static Operand<TInt32> head (Scope scope, Shape<TInt32> shape)

Creates a 1-dimensional Operand containing the Shape's first dimension.

Parameters
scope current scope
shape the TensorFlow shape
Returns
  • a 1-dimensional Operand containing the Shape's first dimension

public static Operand<TInt32> numDimensions (Scope scope, Shape<TInt32> shape)

Get the number of dimensions of the shape object.

Parameters
scope current scope
shape the shape
Returns
  • the number of dimensions

public static Operand<U> numDimensions (Scope scope, Shape<U> shape, Class<U> type)

Get the number of dimensions of the shape object.

Parameters
scope the curren scope
shape the shape
type the shape datatype
Returns
  • the number of dimensions

public static Operand<TInt64> prepend (Scope scope, Shape<TInt64> shape, long firstDimension)

Creates a 1-dimensional operand containing the first dimension followed by the dimensions of the shape.

Parameters
scope current scope
shape the TensorFlow shape
firstDimension the dimension to prepend
Returns
  • a 1-dimensional operand containing the first dimension followed by the dimensions of the shape

public static Operand<T> prepend (Scope scope, Operand<T> shape, Operand<T> shapeToPrepend)

Creates a 1-dimensional operand that represents a new shape containing the dimensions of an operand representing the shape to prepend, followed by the dimensions of an operand representing a shape.

Parameters
scope current scope
shape an operand containing the dimensions of a shape
shapeToPrepend an operand containing the dimensions of the shape to prepend
Returns
  • a 1-dimensional operand that represents a new shape containing the dimensions of an operand representing the shape to prepend, followed by the dimensions of an operand representing the shape

public static Operand<TInt32> prepend (Scope scope, Shape<TInt32> shape, int firstDimension)

Creates a 1-dimensional operand containing the first dimension followed by the dimensions of the shape.

Parameters
scope current scope
shape the TensorFlow shape
firstDimension the dimension to prepend
Returns
  • a 1-dimensional operand containing the first dimension followed by the dimensions of the shape

public static Operand<U> reduceDims (Scope scope, Shape<U> shape, Operand<U> axis, Class<U> type)

Reduces the shape to the specified axis.

Parameters
scope current scope
shape the TensorFlow shape
axis the axis
type the shape datatype
Returns
  • the reduced shape

public static Operand<TInt32> reduceDims (Scope scope, Shape<TInt32> shape, Operand<TInt32> axis)

Reduces the shape to the specified axis.

Parameters
scope current scope
shape the TensorFlow shape
axis the axis
Returns
  • an operand containing the dimensions for the reduced shape

public static Operand<T> reduceDims (Scope scope, Operand<T> operand, Operand<TInt32> axis)

Reshapes the operand by reducing the shape to the specified axis.

Parameters
scope current scope
operand the operand
axis the axis
Returns
  • the reshaped operand

public static Operand<T> reduceDims (Scope scope, Operand<T> operand, Operand<U> axis, Class<U> type)

Reshapes the operand by reducing the shape to the specified axis.

Parameters
scope current scope
operand the operand
axis the axis
type the shape datatype
Returns
  • the reshaped operand

public static Operand<U> size (Scope scope, Shape<U> shape, Class<U> type)

Get the size represented by the TensorFlow shape.

Parameters
scope current scope
shape the TensorFlow shape
type the shape datatype
Returns
  • the size

public static Operand<TInt32> size (Scope scope, Operand<T> input, Operand<TInt32> dim)

Get the size of the specified dimension for the shape of the tensor.

Parameters
scope current scope
input the operand
dim the dimension
Returns
  • the size of the specified dimension

public static Operand<TInt32> size (Scope scope, Shape<TInt32> shape)

Get the size represented by the TensorFlow shape.

Parameters
scope current scope
shape the TensorFlow shape
Returns
  • the size

public static Operand<TInt32> size (Scope scope, Shape<TInt32> shape, Operand<TInt32> dim)

Get the size of the specified dimension in the shape.

Parameters
scope current scope
shape the TensorFlow shape
dim the dimension
Returns
  • the size of the specified dimension

public static Operand<U> size (Scope scope, Shape<U> shape, Operand<U> dim, Class<U> type)

Get the size of the specified dimension in the shape.

Parameters
scope current scope
shape the TensorFlow shape
dim the dimension
type the shape datatype
Returns
  • the size of the specified dimension

public static Operand<U> size (Scope scope, Operand<T> input, Operand<U> dim, Class<U> type)

Get the size of the specified dimension for the shape of the tensor.

Parameters
scope current scope
input the operand
dim the dimension
type the shape datatype
Returns
  • the size of the specified dimension

public static Operand<TInt32> squeeze (Scope scope, Shape<TInt32> shape)

Removes dimensions of size 1 from the shape.

Parameters
scope current scope
shape the TensorFlow shape
Returns
  • the squeezed shape

public static Operand<U> squeeze (Scope scope, Shape<U> shape, Class<U> type)

Removes dimensions of size 1 from the shape.

Parameters
scope current scope
shape the TensorFlow shape
type the shape datatype.
Returns
  • the squeezed shape

public static Operand<TInt32> tail (Scope scope, Shape<TInt32> shape)

Creates a 1-dimensional Operand that contains the dimension matching the last dimension of the Shape.

Parameters
scope current scope
shape the TensorFlow shape
Returns
  • a 1-dimensional Operand that contains the dimension matching the last dimension of the Shape

public static Operand<U> tail (Scope scope, Shape<U> shape, Class<U> type)

Creates a 1-dimensional Operand that contains the dimension matching the last dimension of * the Shape.

Parameters
scope current scope
shape the TensorFlow shape
type the shape datatype.
Returns
  • a 1-dimensional Operand that contains the dimension matching the last dimension of the Shape

public static Operand<TInt32> take (Scope scope, Shape<TInt32> shape, Operand<TInt32> n)

Creates a 1-dimensional operand with the dimensions matching the first n dimensions of the shape.

Parameters
scope current scope
shape the TensorFlow shape
n the number of leading dimensions to get, must be <= than the shape's numDimensions()
Returns
  • a 1-dimensional operand with the dimensions matching the first n dimensions of the shape

public static Operand<U> take (Scope scope, Shape<U> shape, Operand<U> n, Class<U> type)

Creates a 1-dimensional operand containin the dimensions matching the first n dimensions of the shape.

Parameters
scope current scope
shape the TensorFlow shape
n the number of leading dimensions to get, must be <= than the shape's numDimensions()
type the shape datatype.
Returns
  • a 1-dimensional operand with the dimensions matching * the first n dimensions of the shape

public static Operand<U> takeLast (Scope scope, Shape<U> shape, Operand<U> n, Class<U> type)

Creates a 1-dimensional operand containing the dimensions matching the last n dimensions of the shape.

Parameters
scope current scope
shape the TensorFlow shape
n the number of leading dimensions to get, must be <= than the shape's numDimensions()
type the shape datatype.
Returns
  • a 1-dimensional operand containing the dimensions matching the last n dimensions of the shape

public static Operand<TInt32> takeLast (Scope scope, Shape<TInt32> shape, Operand<TInt32> n)

Creates a 1-dimensional operand containing the dimensions matching the last n dimensions of the shape.

Parameters
scope current scope
shape the TensorFlow shape
n the number of leading dimensions to get, must be <= than the shape's numDimensions()
Returns
  • a 1-dimensional operand containing the dimensions matching the last n dimensions of the shape