Class ShapeUtils

java.lang.Object
org.tensorflow.framework.utils.ShapeUtils

public class ShapeUtils extends Object
Various methods for processing with Shapes and Operands
  • Constructor Details

    • ShapeUtils

      public ShapeUtils()
  • Method Details

    • toShape

      public static <T extends TIntegral> Shape toShape(Scope scope, Operand<T> dims)
      Converts a shape operand to a Shape object
      Type Parameters:
      T - the date type for the shape dimensions.
      Parameters:
      scope - the TensorFlow scope
      dims - the Operand containing the shape values
      Returns:
      a new Shape based on an Operand that contains dimensions
    • getIntArray

      public static int[] getIntArray(Scope scope, Operand<TInt32> dims)
      Converts a TInt32 type Operand to a Java int array
      Parameters:
      scope - the TensorFlow scope
      dims - the shape dimensions operand
      Returns:
      the int array of the dimensions
    • getLongArray

      public static <T extends TIntegral> long[] getLongArray(Scope scope, Operand<T> dims)
      Converts a TInt32 or TInt64 Operand to a java long array
      Type Parameters:
      T - the type of the dimensions, must either be TInt32 or TInt64 type
      Parameters:
      scope - the TensorFlow scope
      dims - the Operand
      Returns:
      the long array
      Throws:
      IllegalArgumentException - if the dims type is not an integer
    • getLongArray

      public static <T extends TIntegral> long[] getLongArray(T dims)
      Converts a TInt32 or TInt64 to a java long array
      Type Parameters:
      T - the type of the dimensions, must either be TInt32 or TInt64 type
      Parameters:
      dims - the dimension tensor
      Returns:
      the long array
      Throws:
      IllegalArgumentException - if the dims type is not an integer
    • reduce

      public static Shape reduce(Shape shape, int axis)
      Reduces the shape by eliminating trailing Dimensions.

      The last dimension, specified by axis, will be a product of all remaining dimensions

      Parameters:
      shape - the shape to squeeze
      axis - the axis to squeeze
      Returns:
      the new shape