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>
TAD(T input)Adds a dimension to the input tensor.static voidboundSpatial(int[] bounds, int rows, int cols)static voidcheckShape(Tensor_F32 a, Tensor_F32 b)Checks to see if the two tensors have the same shapestatic voidcheckShape(Tensor_F64 a, Tensor_F64 b)Checks to see if the two tensors have the same shapestatic voidcheckShape(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 voidcheckShape(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 doubleelementSum(Tensor tensor)Computes the sum of all the elements in the tensorstatic voidfill(Tensor t, double value)static intouterLength(int[] shape, int startDimen)Computes the number of elements for an inner portion of the tensor starting at the specified index and going outsidestatic java.io.FilepathToRoot()static intsumTensorLength(java.util.List<int[]> shapes)Returns the total length of all the tensors in the list summed togetherstatic inttensorLength(int... shape)Returns the total length of one tensorstatic int[]TH(int[] elements)Truncates the head (element 0) from the arraystatic java.lang.StringtoStringShape(int[] shape)static java.lang.StringtoStringShapeA(int[] shape)static int[]WI(int... elements)Convenience function for making it easy to create an array of intsstatic int[]WI(int[] elements, int a)Convenience function for making it easy to create an array of intsstatic int[]WI(int a, int[] elements)Convenience function for making it easy to create an array of intsstatic 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
-
Constructor Details
-
TensorOps
public TensorOps()
-
-
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
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 invokescheckShape(String, int, int[], int[], boolean)- Parameters:
which- String describing which variables are being checkedexpected- List of expected tensorsactual- List of actual tensors. Axis 0 is optionally ignored here, see ignoreAxis0ignoreAxis0- true to ignore axis 0
-
checkShape
Checks to see if the two tensors have the same shape- Parameters:
a- tensorb- tensor
-
checkShape
Checks to see if the two tensors have the same shape- Parameters:
a- tensorb- 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 anIllegalArgumentExceptionif they don't match.- Parameters:
which- String describing which variable is being checkedtensor- Index of the tensor in a tensor list. Used to provide a more detailed error message. If < 0 then this is ignoredexpected- 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
Computes the sum of all the elements in the tensor- Parameters:
tensor- Tensor
-
fill
-
boundSpatial
public static void boundSpatial(int[] bounds, int rows, int cols)
-