Package deepboof.misc

Class TensorOps

java.lang.Object
deepboof.misc.TensorOps

public class TensorOps
extends java.lang.Object
  • Constructor Summary

    Constructors 
    Constructor Description
    TensorOps()  
  • Method Summary

    Modifier and Type Method Description
    static <T extends Tensor>
    T
    AD​(T input)
    Adds a dimension to the input tensor.
    static void boundSpatial​(int[] bounds, int rows, int cols)  
    static void checkShape​(Tensor_F32 a, Tensor_F32 b)
    Checks to see if the two tensors have the same shape
    static void checkShape​(Tensor_F64 a, Tensor_F64 b)
    Checks to see if the two tensors have the same shape
    static void checkShape​(java.lang.String which, int tensor, int[] expected, int[] actual, boolean ignoreAxis0)
    Checks to see if the two tensors have the same shape, with the option to ignore the first axis for the 'actual' shape.
    static void checkShape​(java.lang.String which, java.util.List<int[]> expected, java.util.List<Tensor<?>> actual, boolean ignoreAxis0)
    Compares a list of tensors shape's against each other.
    static double elementSum​(Tensor tensor)
    Computes the sum of all the elements in the tensor
    static void fill​(Tensor t, double value)  
    static int outerLength​(int[] shape, int startDimen)
    Computes the number of elements for an inner portion of the tensor starting at the specified index and going outside
    static java.io.File pathToRoot()  
    static int sumTensorLength​(java.util.List<int[]> shapes)
    Returns the total length of all the tensors in the list summed together
    static int tensorLength​(int... shape)
    Returns the total length of one tensor
    static int[] TH​(int[] elements)
    Truncates the head (element 0) from the array
    static java.lang.String toStringShape​(int[] shape)  
    static java.lang.String toStringShapeA​(int[] shape)  
    static int[] WI​(int... elements)
    Convenience function for making it easy to create an array of ints
    static int[] WI​(int[] elements, int a)
    Convenience function for making it easy to create an array of ints
    static int[] WI​(int a, int[] elements)
    Convenience function for making it easy to create an array of ints
    static java.util.List<int[]> WI​(int a, java.util.List<int[]> list)  
    static <T> java.util.List<T> WT​(T... elements)
    Convenience function for wrapping passed in elements into a list

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • WT

      public static <T> java.util.List<T> WT​(T... elements)
      Convenience function for wrapping passed in elements into a list
    • WI

      public static int[] WI​(int... elements)
      Convenience function for making it easy to create an array of ints
    • WI

      public static int[] WI​(int a, int[] elements)
      Convenience function for making it easy to create an array of ints
      Returns:
      [ a , elements[0] , ..., elements[N-1] ]
    • WI

      public static int[] WI​(int[] elements, int a)
      Convenience function for making it easy to create an array of ints
      Returns:
      [ elements[0] , ..., elements[N-1], a ]
    • TH

      public static int[] TH​(int[] elements)
      Truncates the head (element 0) from the array
    • WI

      public static java.util.List<int[]> WI​(int a, java.util.List<int[]> list)
    • AD

      public static <T extends Tensor> T AD​(T input)
      Adds a dimension to the input tensor. Returns a new tensor which references the same data as the original. Input Shape = [5 4 3] Output Shape = [1 5 4 3]
    • sumTensorLength

      public static int sumTensorLength​(java.util.List<int[]> shapes)
      Returns the total length of all the tensors in the list summed together
      Parameters:
      shapes - List of tensor shapes
      Returns:
      Sum of tensor lengths
    • tensorLength

      public static int tensorLength​(int... shape)
      Returns the total length of one tensor
      Parameters:
      shape - shape of a tensor
      Returns:
      length of the Tensor's data arrayn
    • checkShape

      public static void checkShape​(java.lang.String which, java.util.List<int[]> expected, java.util.List<Tensor<?>> actual, boolean ignoreAxis0)
      Compares a list of tensors shape's against each other. This simply invokes checkShape(String, int, int[], int[], boolean)
      Parameters:
      which - String describing which variables are being checked
      expected - List of expected tensors
      actual - List of actual tensors. Axis 0 is optionally ignored here, see ignoreAxis0
      ignoreAxis0 - true to ignore axis 0
    • checkShape

      public static void checkShape​(Tensor_F64 a, Tensor_F64 b)
      Checks to see if the two tensors have the same shape
      Parameters:
      a - tensor
      b - tensor
    • checkShape

      public static void checkShape​(Tensor_F32 a, Tensor_F32 b)
      Checks to see if the two tensors have the same shape
      Parameters:
      a - tensor
      b - tensor
    • checkShape

      public static void checkShape​(java.lang.String which, int tensor, int[] expected, int[] actual, boolean ignoreAxis0)
      Checks to see if the two tensors have the same shape, with the option to ignore the first axis for the 'actual' shape. The first axis is typically the mini-batch, but the expected value might not include the mini-batch since the size of the mini-batch is determined later on. Throws an IllegalArgumentException if they don't match.
      Parameters:
      which - String describing which variable is being checked
      tensor - Index of the tensor in a tensor list. Used to provide a more detailed error message. If < 0 then this is ignored
      expected - Expected shape.
      actual - Actual shape. Axis 0 is optionally ignored.
      ignoreAxis0 - If true it will ignore the first dimension in expected
    • toStringShapeA

      public static java.lang.String toStringShapeA​(int[] shape)
    • toStringShape

      public static java.lang.String toStringShape​(int[] shape)
    • outerLength

      public static int outerLength​(int[] shape, int startDimen)

      Computes the number of elements for an inner portion of the tensor starting at the specified index and going outside

      Example:
      Tensor shape = (d[0], ... , d[K-1]). Then if start dimen is 2, the output will be the product of d[2] to d[K-1].
    • pathToRoot

      public static java.io.File pathToRoot()
    • elementSum

      public static double elementSum​(Tensor tensor)
      Computes the sum of all the elements in the tensor
      Parameters:
      tensor - Tensor
    • fill

      public static void fill​(Tensor t, double value)
    • boundSpatial

      public static void boundSpatial​(int[] bounds, int rows, int cols)