Class Shape


  • public class Shape
    extends Object
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static boolean areShapesBroadcastable​(@lombok.NonNull int[] x, @lombok.NonNull int[] y)  
      static boolean areShapesBroadcastable​(@lombok.NonNull long[] left, @lombok.NonNull long[] right)  
      static void assertBroadcastable​(@lombok.NonNull int[] x, @lombok.NonNull int[] y)  
      static void assertBroadcastable​(@lombok.NonNull long[] x, @lombok.NonNull long[] y)  
      static void assertBroadcastable​(@lombok.NonNull long[] x, @lombok.NonNull long[] y, Class<?> opClass)  
      static void assertBroadcastable​(@NonNull INDArray x, @NonNull INDArray y)  
      static void assertBroadcastable​(String op, INDArray first, INDArray second, INDArray result)
      Assert that the broadcast operation result = first.op(second) is valid, given the shapes of first, second, and result.
      Throws an exception otherwise
      static void assertShapeLessThan​(int[] shape, int[] lessThan)
      Assert the both shapes are the same length and shape[i] < lessThan[i]
      static void assertShapeLessThan​(long[] shape, long[] lessThan)  
      static void assertValidOrder​(char order)  
      static int[] broadcastOutputShape​(int[] left, int[] right)
      Get the broadcast output shape based on the 2 input shapes Result output shape based on: https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html
      static long[] broadcastOutputShape​(long[] left, long[] right)  
      static String bufferToString​(IntBuffer buffer)
      Prints the IntBuffer
      static boolean containsZeros​(long[] shapeOnly)  
      static boolean contentEquals​(int[] arr, IntBuffer other)
      Compare the contents of a buffer and an array for equals
      static boolean contentEquals​(int[] arr, DataBuffer other)
      Compare the contents of a buffer and an array for equals
      static boolean contentEquals​(long[] arr, long[] other)  
      static boolean contentEquals​(long[] arr, IntBuffer other)  
      static boolean contentEquals​(long[] arr, LongBuffer other)  
      static boolean contentEquals​(long[] arr, DataBuffer other)  
      static boolean cOrFortranOrder​(int[] shape, int[] stride, int elementStride)
      Deprecated.
      static boolean cOrFortranOrder​(long[] shape, long[] stride, long elementStride)
      Infer order from
      static DataBuffer createShapeInformation​(long[] shape, long[] stride, long elementWiseStride, char order, long extras)  
      static DataBuffer createShapeInformation​(long[] shape, long[] stride, long elementWiseStride, char order, DataType dataType, boolean empty)  
      static DataBuffer createSparseInformation​(int[] flags, long[] sparseOffsets, int[] hiddenDimensions, int underlyingRank)  
      static int elementWiseStride​(int[] shape, int[] stride, boolean isFOrder)  
      static long elementWiseStride​(long[] buffer)
      Get the element wise stride for the shape info buffer
      static long elementWiseStride​(long[] shape, long[] stride, boolean isFOrder)  
      static int elementWiseStride​(IntBuffer buffer)
      Get the element wise stride for the shape info buffer
      static long elementWiseStride​(LongBuffer buffer)  
      static int elementWiseStride​(DataBuffer buffer)
      Get the element wise stride for the shape info buffer
      static int[] ensureAtMinRowVector​(int... shape)
      If a shape array is ony 1 in length it returns a row vector
      static long extras​(long[] buffer)  
      static int[] flags​(DataBuffer buffer)  
      static int[] getBroadcastDimensions​(int[] left, int[] right)
      Compute the broadcast rules according to: https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html Note that the array can be null if the arrays are already equal in shape.
      static int[] getBroadcastDimensions​(long[] left, long[] right)  
      static double getDouble​(INDArray arr, int[] indices)
      Get a double based on the array and given indices
      static double getDouble​(INDArray arr, long... indices)  
      static long getLong​(INDArray arr, long... indices)  
      static int[] getMatrixMultiplyShape​(int[] left, int[] right)
      Get the output shape of a matrix multiply
      static long[] getMatrixMultiplyShape​(long[] left, long[] right)  
      static long[] getMaxShape​(INDArray... inputs)
      Return the shape of the largest length array based on the input
      static long getOffset​(int[] shapeInformation, int... indices)  
      static long getOffset​(long[] shapeInformation, int... indices)  
      static long getOffset​(long[] shapeInformation, long... indices)  
      static long getOffset​(long baseOffset, int[] shape, int[] stride, int... indices)
      Get an offset for retrieval from a data buffer based on the given shape stride and given indices
      static long getOffset​(IntBuffer shapeInformation, int row, int col)
      Get the offset of the specified [row,col] for the 2d array
      static long getOffset​(IntBuffer shapeInformation, int dim0, int dim1, int dim2)
      Get the offset of the specified [dim0,dim1,dim2] for the 3d array
      static long getOffset​(IntBuffer shapeInformation, int dim0, int dim1, int dim2, int dim3)
      Get the offset of the specified [dim0,dim1,dim2,dim3] for the 4d array
      static long getOffset​(IntBuffer shapeInformation, long... indices)  
      static long getOffset​(LongBuffer shapeInformation, long... indices)
      Get the offset of the specified indices from the shape info buffer
      static long getOffset​(DataBuffer shapeInformation, int[] indices)
      Deprecated.
      static long getOffset​(DataBuffer shapeInformation, int row, int col)
      Get the offset of the specified [row,col] for the 2d array
      static long getOffset​(DataBuffer shapeInformation, int dim0, int dim1, int dim2)
      Get the offset of the specified [dim0,dim1,dim2] for the 3d array
      static long getOffset​(DataBuffer shapeInformation, int dim0, int dim1, int dim2, int dim3)
      Get the offset of the specified [dim0,dim1,dim2,dim3] for the 4d array
      static long getOffset​(DataBuffer shapeInformation, long... indices)  
      static long getOffsetUnsafe​(int[] shapeInformation, int row, int col)  
      static long getOffsetUnsafe​(int[] shapeInformation, int dim0, int dim1, int dim2)  
      static long getOffsetUnsafe​(int[] shapeInformation, int dim0, int dim1, int dim2, int dim3)  
      static long getOffsetUnsafe​(long[] shapeInformation, long row, long col)  
      static long getOffsetUnsafe​(long[] shapeInformation, long dim0, long dim1, long dim2, long dim3)  
      static long getOffsetUnsafe​(DataBuffer shapeInformation, int row, int col)
      Identical to getOffset(DataBuffer, int, int) but without input validation on array rank
      static long getOffsetUnsafe​(DataBuffer shapeInformation, int dim0, int dim1, int dim2)
      Identical to getOffset(DataBuffer, int, int, int) but without input validation on array rank
      static long getOffsetUnsafe​(DataBuffer shapeInformation, int dim0, int dim1, int dim2, int dim3)  
      static char getOrder​(int[] shape, int[] stride, int elementStride)
      Infer order from
      static char getOrder​(long[] shape, long[] stride, long elementStride)  
      static char getOrder​(INDArray arr)
      Infer the order for the ndarray based on the array's strides
      static long[] getReducedShape​(int[] wholeShape, int[] dimensions)
      Get the shape of the reduced array
      static long[] getReducedShape​(int[] wholeShape, int[] dimensions, boolean keepDims, boolean newFormat)
      Get the shape of the reduced array
      static long[] getReducedShape​(long[] wholeShape, int[] dimensions)  
      static long[] getReducedShape​(long[] wholeShape, int[] dimensions, boolean keepDims)  
      static long[] getReducedShape​(long[] wholeShape, int[] dimensions, boolean keepDims, boolean newFormat)  
      static long getTADLength​(int[] shape, int... dimensions)  
      static long getTADLength​(long[] shape, int... dimensions)  
      static boolean hasDefaultStridesForShape​(INDArray input)  
      static int[] hiddenDimension​(DataBuffer buffer)  
      static int[] ind2sub​(int[] shape, long index)
      Convert a linear index to the equivalent nd index.
      static int[] ind2sub​(int[] shape, long index, long numIndices)
      Convert a linear index to the equivalent nd index
      static long[] ind2sub​(long[] shape, long index)  
      static long[] ind2sub​(long[] shape, long index, long numIndices)  
      static long[] ind2sub​(INDArray arr, long index)
      Convert a linear index to the equivalent nd index based on the shape of the specified ndarray.
      static int[] ind2subC​(int[] shape, long index)
      Convert a linear index to the equivalent nd index.
      static int[] ind2subC​(int[] shape, long index, long numIndices)
      Convert a linear index to the equivalent nd index
      static long[] ind2subC​(long[] shape, long index)  
      static long[] ind2subC​(long[] shape, long index, long numIndices)  
      static long[] ind2subC​(INDArray arr, long index)
      Convert a linear index to the equivalent nd index based on the shape of the specified ndarray.
      static boolean isB​(@NonNull DataType x)  
      static boolean isColumnVectorShape​(int[] shape)
      Returns true if the given shape is length 2 and the size at element 1 is 1
      static boolean isColumnVectorShape​(long[] shape)
      Returns true if the given shape length is 2 and the size at element 1 is 1
      static boolean isContiguousInBuffer​(INDArray in)
      Are the elements in the buffer contiguous for this NDArray?
      static boolean isEmpty​(long[] shapeInfo)  
      static boolean isMatrix​(int[] shape)
      Returns whether the passed in shape is a matrix
      static boolean isMatrix​(long[] shape)  
      static boolean isMatrix​(IntBuffer shapeInfo)
      Returns whether the passed in shape is a matrix
      static boolean isMatrix​(DataBuffer shapeInfo)
      Returns whether the passed in shape is a matrix
      static boolean isPlaceholderShape​(int[] shape)
      Returns true if any shape has a -1 or a null or empty array is passed in
      static boolean isPlaceholderShape​(long[] shape)  
      static boolean isR​(@NonNull DataType x)  
      static boolean isRowVectorShape​(int[] shape)
      Returns true if the given shape is of length 1 or provided the shape length is 2: element 0 is 1
      static boolean isRowVectorShape​(long[] shape)  
      static boolean isRowVectorShape​(IntBuffer shapeInfo)
      Returns true if the given shape is of length 1 or provided the shape length is 2: element 0 is 1
      static boolean isRowVectorShape​(DataBuffer shapeInfo)
      Returns true if the given shape is of length 1 or provided the shape length is 2: element 0 is 1
      static boolean isS​(@NonNull DataType x)  
      static boolean isVector​(int[] shape)
      Returns whether the given shape is a vector
      static boolean isVector​(long[] shape)  
      static boolean isVector​(IntBuffer shapeInfo)
      Returns whether the given shape is a vector
      static boolean isVector​(LongBuffer shapeInfo)  
      static boolean isVector​(DataBuffer shapeInfo)
      Returns whether the given shape is a vector
      static boolean isWholeArray​(int[] shape, int... dimension)
      Returns true if the dimension is null or the dimension length is 1 and the first entry is Integer.MAX_VALUE
      static boolean isWholeArray​(int rank, int... dimension)
      Returns true if the dimension is null or the dimension length is 1 and the first entry is Integer.MAX_VALUE
      static boolean isWholeArray​(long[] shape, int... dimension)  
      static boolean isZ​(@NonNull DataType x)  
      static void iterate​(int dimension, int n, int[] size, int[] res, int dimension2, int n2, int[] size2, int[] res2, CoordinateFunction func)
      Iterate over a pair of coordinates
      static void iterate​(int dimension, int n, int[] size, int[] res, CoordinateFunction func)
      Iterate over a pair of coordinates
      static void iterate​(int dimension, int n, long[] size, long[] res, int dimension2, int n2, long[] size2, long[] res2, CoordinateFunction func)  
      static void iterate​(int dimension, int n, long[] size, long[] res, CoordinateFunction func)  
      static void iterate​(INDArray arr, INDArray arr2, CoordinateFunction coordinateFunction)
      Iterate over 2 coordinate spaces given 2 arrays
      static void iterate​(INDArray arr, CoordinateFunction coordinateFunction)
      Iterate over 2 coordinate spaces given 2 arrays
      static long length​(int[] buffer)  
      static long length​(long[] buffer)  
      static int length​(IntBuffer buffer)
      Gets the rank given the shape info buffer
      static int length​(LongBuffer buffer)  
      static long length​(DataBuffer buffer)
      Gets the rank given the shape info buffer
      static long lengthOf​(int[] shape)  
      static long lengthOf​(long[] shape)  
      static long lengthOfBuffer​(@lombok.NonNull int[] shape, @lombok.NonNull int[] stride)
      Calculate the length of the buffer required to store the given shape with the given strides
      static long lengthOfBuffer​(@lombok.NonNull long[] shape, @lombok.NonNull long[] stride)
      Calculate the length of the buffer required to store the given shape with the given strides
      static INDArray ndArrayDimFromInt​(int... dimensions)
      Create an INDArray to represent the (possibly null) int[] dimensions.
      static INDArray newShapeNoCopy​(INDArray arr, int[] newShape, boolean isFOrder)  
      static INDArray newShapeNoCopy​(INDArray arr, long[] newShape, boolean isFOrder)
      A port of numpy's reshaping algorithm that leverages no copy where possible and returns null if the reshape couldn't happen without copying
      static int[] newStrides​(int[] strides, int newLength, INDArrayIndex[] indexes)  
      static int[] normalizeAxis​(int rank, int... axis)  
      static int offset​(int[] buffer)
      Deprecated.
      static int offset​(long[] buffer)
      Deprecated.
      static int offset​(IntBuffer buffer)
      Deprecated.
      static long offset​(LongBuffer buffer)
      Deprecated.
      static int offset​(DataBuffer buffer)
      Deprecated.
      static long options​(long[] buffer)  
      static char order​(int[] buffer)  
      static char order​(long[] buffer)  
      static char order​(IntBuffer buffer)
      Returns the order given the shape information
      static char order​(LongBuffer buffer)  
      static char order​(DataBuffer buffer)
      Returns the order given the shape information
      static DataType pickPairwiseDataType​(@NonNull DataType typeX, @NonNull Number number)  
      static DataType pickPairwiseDataType​(@NonNull DataType typeX, @NonNull DataType typeY)
      Return a data type to use for output within a pair wise operation such as add or subtract.
      static int rank​(int[] buffer)  
      static int rank​(long[] buffer)  
      static int rank​(IntBuffer buffer)
      Gets the rank given the shape info buffer
      static int rank​(LongBuffer buffer)  
      static int rank​(DataBuffer buffer)
      Gets the rank given the shape info buffer
      static int rankFromShape​(int[] shape)
      Return the rank for the given shape
      static int rankFromShape​(long[] shape)  
      static long[] reductionShape​(INDArray x, int[] dimension, boolean newFormat, boolean keepDims)
      Calculate the shape of the returned array, for a reduction along dimension
      static int[] resolveNegativeShapeIfNeccessary​(int[] newShape, int[] shape)  
      static boolean scalarEquals​(int[] shape1, int[] shape2)
      Returns true if the given shapes are both scalars (0 dimension or shape[0] == 1)
      static boolean scalarEquals​(long[] shape1, long[] shape2)  
      static void setElementWiseStride​(IntBuffer buffer, int elementWiseStride)
      Get the element wise stride for the shape info buffer
      static void setElementWiseStride​(DataBuffer buffer, int elementWiseStride)
      Get the element wise stride for the shape info buffer
      static void setOrder​(IntBuffer buffer, char order)
      Deprecated.
      static int[] shape​(int[] buffer)
      Get array shape from an int[]
      static long[] shape​(long[] buffer)  
      static long[] shape​(IntBuffer buffer)
      Get array shape from the buffer, as an int[]
      static long[] shape​(LongBuffer buffer)  
      static long[] shape​(DataBuffer buffer)
      Get array shape from the buffer, as an int[]
      static boolean shapeEquals​(int[] shape1, int[] shape2)
      Returns whether 2 shapes are equals by checking for dimension semantics as well as array equality
      static boolean shapeEquals​(long[] shape1, long[] shape2)
      Returns whether 2 shapes are equals by checking for dimension semantics as well as array equality
      static boolean shapeEqualWithSqueeze​(long[] shape1, long[] shape2)
      Return true if the shapes are equal after removing any size 1 dimensions For example, [1,3,4] and [3,4] are considered equal by this method.
      static int shapeInfoLength​(long rank)
      Return the shape info length given the rank
      static int shapeInfoLength​(long[] shape)  
      static boolean shapeIsScalar​(int[] shape)
      Returns true if this shape is scalar
      static boolean shapeIsScalar​(long[] shape)  
      static boolean shapeMatchesPlaceholder​(long[] phShape, long[] arrShape)
      Determine whether the placeholder shape and the specified shape are compatible.
      Shapes are compatible if:
      (a) They are both the same length (same array rank, or null)
      (b) At each position either phShape[i] == -1 or phShape[i] == arrShape[i]
      static int[] shapeOf​(int[] buffer)  
      static long[] shapeOf​(long[] buffer)  
      static IntBuffer shapeOf​(IntBuffer buffer)
      Get the shape from the given int buffer
      static LongBuffer shapeOf​(LongBuffer buffer)  
      static DataBuffer shapeOf​(DataBuffer buffer)
      Get the shape from the given int buffer
      static String shapeToString​(IntBuffer buffer)
      Prints the shape for this shape information
      static String shapeToString​(LongBuffer buffer)  
      static String shapeToString​(INDArray arr)
      Prints the shape for this shape information
      static String shapeToStringShort​(INDArray arr)  
      static int size​(int[] buffer, int dimension)  
      static long size​(long[] buffer, int dimension)  
      static int size​(IntBuffer buffer, int dimension)
      Get the size of the specified dimension.
      static long size​(LongBuffer buffer, int dimension)  
      static int size​(DataBuffer buffer, int dimension)
      Get the size of the specified dimension.
      static long sizeAt​(long[] shape, int index)  
      static int[] sizeForAxes​(int[] axes, int[] shape)
      Output an int array for a particular dimension
      static int sizeUnsafe​(int[] buffer, int dimension)  
      static long sizeUnsafe​(long[] buffer, int dimension)  
      static int sizeUnsafe​(DataBuffer buffer, int dimension)
      Get the size of the specified dimension.
      static int[] sparseOffsets​(DataBuffer buffer)  
      static int[] squeeze​(int[] shape)
      Gets rid of any singleton dimensions of the given array
      static long[] squeeze​(long[] shape)
      Gets rid of any singleton dimensions of the given array
      static int[] stride​(int[] buffer)  
      static int stride​(int[] buffer, int dimension)  
      static long[] stride​(long[] buffer)  
      static long stride​(long[] buffer, int dimension)  
      static IntBuffer stride​(IntBuffer buffer)
      Get the stride for the given shape information buffer
      static int stride​(IntBuffer buffer, int dimension)
      Get the stride of the specified dimension
      static LongBuffer stride​(LongBuffer buffer)  
      static long stride​(LongBuffer buffer, int dimension)  
      static DataBuffer stride​(DataBuffer buffer)
      Get the shape from the given int buffer
      static int stride​(DataBuffer buffer, int dimension)
      Get the stride of the specified dimension
      static long[] strideArr​(DataBuffer buffer)
      Get array shape from the buffer, as an int[]
      static boolean strideDescendingCAscendingF​(INDArray array)
      Check if strides are in order suitable for non-strided mmul etc.
      static int[] stridesOf​(int[] buffer)  
      static long[] stridesOf​(long[] buffer)  
      static int strideUnsafe​(int[] buffer, int dimension, int rank)  
      static long strideUnsafe​(long[] buffer, int dimension, int rank)  
      static int strideUnsafe​(DataBuffer buffer, int dimension, int rank)
      Get the stride of the specified dimension, without any input validation
      static long sub2Ind​(int[] shape, int[] indices)
      Convert the given index (such as 1,1) to a linear index
      static IntBuffer toBuffer​(int... arr)
      Convert an array to a byte buffer
      static INDArray toMmulCompatible​(INDArray input)
      This method is used in DL4J LSTM implementation
      static INDArray toOffsetZero​(INDArray arr)
      Create a copy of the matrix where the new offset is zero
      static INDArray toOffsetZeroCopy​(INDArray arr)
      Create a copy of the ndarray where the new offset is zero
      static INDArray toOffsetZeroCopy​(INDArray arr, char order)
      Create a copy of the ndarray where the new offset is zero, and has specified order
      static INDArray toOffsetZeroCopyAnyOrder​(INDArray arr)
      Create a copy of the ndarray where the new offset is zero.
      static String toString​(IntBuffer buffer)
      To String for an int buffer
      static String toString​(DataBuffer buffer)
      To String for an int buffer
      static int underlyingRank​(DataBuffer buffer)  
      static int[] uniquify​(int[] array)  
      static boolean wholeArrayDimension​(int... arr)
      Returns true if the given array is meant for the whole dimension
    • Method Detail

      • getMaxShape

        public static long[] getMaxShape​(INDArray... inputs)
        Return the shape of the largest length array based on the input
        Parameters:
        inputs - the inputs to get the max shape for
        Returns:
        the largest shape based on the inputs
      • shapeIsScalar

        public static boolean shapeIsScalar​(int[] shape)
        Returns true if this shape is scalar
        Parameters:
        shape - the shape that is scalar
        Returns:
      • shapeIsScalar

        public static boolean shapeIsScalar​(long[] shape)
      • isPlaceholderShape

        public static boolean isPlaceholderShape​(int[] shape)
        Returns true if any shape has a -1 or a null or empty array is passed in
        Parameters:
        shape - the input shape to validate
        Returns:
        true if the shape is null,empty, or contains a -1 element
      • isPlaceholderShape

        public static boolean isPlaceholderShape​(long[] shape)
      • getBroadcastDimensions

        public static int[] getBroadcastDimensions​(int[] left,
                                                   int[] right)
        Compute the broadcast rules according to: https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html Note that the array can be null if the arrays are already equal in shape. This function should be used in conjunction with the shape ops.
        Parameters:
        left - the left array
        right - the right array (the array to be broadcasted
        Returns:
        the broadcast dimensions if any
      • sizeAt

        public static long sizeAt​(long[] shape,
                                  int index)
      • getBroadcastDimensions

        public static int[] getBroadcastDimensions​(long[] left,
                                                   long[] right)
      • broadcastOutputShape

        public static int[] broadcastOutputShape​(int[] left,
                                                 int[] right)
        Get the broadcast output shape based on the 2 input shapes Result output shape based on: https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html
        Parameters:
        left - the left shape
        right - the right second
        Returns:
      • containsZeros

        public static boolean containsZeros​(long[] shapeOnly)
      • assertBroadcastable

        public static void assertBroadcastable​(String op,
                                               INDArray first,
                                               INDArray second,
                                               INDArray result)
        Assert that the broadcast operation result = first.op(second) is valid, given the shapes of first, second, and result.
        Throws an exception otherwise
        Parameters:
        op - Name of the operation
        first - First array
        second - Second array
        result - Result arrray.
      • broadcastOutputShape

        public static long[] broadcastOutputShape​(long[] left,
                                                  long[] right)
      • resolveNegativeShapeIfNeccessary

        public static int[] resolveNegativeShapeIfNeccessary​(int[] newShape,
                                                             int[] shape)
        Parameters:
        newShape - the new shape possibly containing a negative number
        shape - the shape to calculate from
        Returns:
      • isWholeArray

        public static boolean isWholeArray​(int[] shape,
                                           int... dimension)
        Returns true if the dimension is null or the dimension length is 1 and the first entry is Integer.MAX_VALUE
        Parameters:
        shape - the shape of the input array
        dimension - the dimensions specified
        Returns:
        true if the dimension length is equal to the shape length the dimension is null or the dimension length is 1 and the first entry is Integer.MAX_VALUE
      • isWholeArray

        public static boolean isWholeArray​(long[] shape,
                                           int... dimension)
      • isWholeArray

        public static boolean isWholeArray​(int rank,
                                           int... dimension)
        Returns true if the dimension is null or the dimension length is 1 and the first entry is Integer.MAX_VALUE
        Parameters:
        rank - the rank of the input array
        dimension - the dimensions specified
        Returns:
        true if the dimension length is equal to the rank, the dimension is null or the dimension length is 1 and the first entry is Integer.MAX_VALUE
      • getReducedShape

        public static long[] getReducedShape​(int[] wholeShape,
                                             int[] dimensions)
        Get the shape of the reduced array
        Parameters:
        wholeShape - the shape of the array with the reduce op being performed
        dimensions - the dimensions the reduce op is being performed on
        Returns:
        the shape of the result array as the result of the reduce
      • getReducedShape

        public static long[] getReducedShape​(long[] wholeShape,
                                             int[] dimensions)
      • getReducedShape

        public static long[] getReducedShape​(int[] wholeShape,
                                             int[] dimensions,
                                             boolean keepDims,
                                             boolean newFormat)
        Get the shape of the reduced array
        Parameters:
        wholeShape - the shape of the array with the reduce op being performed
        dimensions - the dimensions the reduce op is being performed on
        keepDims - if set to true, corresponding dimensions will be set to 1
        Returns:
        the shape of the result array as the result of the reduce
      • getReducedShape

        public static long[] getReducedShape​(long[] wholeShape,
                                             int[] dimensions,
                                             boolean keepDims)
      • getReducedShape

        public static long[] getReducedShape​(long[] wholeShape,
                                             int[] dimensions,
                                             boolean keepDims,
                                             boolean newFormat)
      • getMatrixMultiplyShape

        public static int[] getMatrixMultiplyShape​(int[] left,
                                                   int[] right)
        Get the output shape of a matrix multiply
        Parameters:
        left - the first matrix shape to multiply
        right - the second matrix shape to multiply
        Returns:
        the shape of the output array (the left's rows and right's columns)
      • getMatrixMultiplyShape

        public static long[] getMatrixMultiplyShape​(long[] left,
                                                    long[] right)
      • toOffsetZero

        public static INDArray toOffsetZero​(INDArray arr)
        Create a copy of the matrix where the new offset is zero
        Parameters:
        arr - the array to copy to offset 0
        Returns:
        the same array if offset is zero otherwise a copy of the array with elements set to zero
      • toOffsetZeroCopy

        public static INDArray toOffsetZeroCopy​(INDArray arr)
        Create a copy of the ndarray where the new offset is zero
        Parameters:
        arr - the array to copy to offset 0
        Returns:
        a copy of the array with elements set to zero offset
      • toOffsetZeroCopy

        public static INDArray toOffsetZeroCopy​(INDArray arr,
                                                char order)
        Create a copy of the ndarray where the new offset is zero, and has specified order
        Parameters:
        arr - the array to copy to offset 0
        order - the order of the returned array
        Returns:
        a copy of the array with elements set to zero offset, and with specified order
      • toOffsetZeroCopyAnyOrder

        public static INDArray toOffsetZeroCopyAnyOrder​(INDArray arr)
        Create a copy of the ndarray where the new offset is zero. Unlike toOffsetZeroCopy(INDArray) (which always returns arrays of order Nd4j.order()), and toOffsetZeroCopy(INDArray,char) (which always returns arrays of a specified order) this method returns NDArrays of any order (sometimes c, sometimes f).
        This method may be faster than the other two toOffsetZeroCopyAnyOrder methods as a result, however no performance benefit (or cost) relative to them will be observed in many cases. If a copy is necessary, the output will have order Nd4j.order()
        Parameters:
        arr - NDArray to duplicate
        Returns:
        Copy with offset 0, but order might be c, or might be f
      • getDouble

        public static double getDouble​(INDArray arr,
                                       int[] indices)
        Get a double based on the array and given indices
        Parameters:
        arr - the array to retrieve the double from
        indices - the indices to iterate over
        Returns:
        the double at the specified index
      • getDouble

        public static double getDouble​(INDArray arr,
                                       long... indices)
      • getLong

        public static long getLong​(INDArray arr,
                                   long... indices)
      • iterate

        public static void iterate​(INDArray arr,
                                   CoordinateFunction coordinateFunction)
        Iterate over 2 coordinate spaces given 2 arrays
        Parameters:
        arr - the first array
        coordinateFunction - the coordinate function to use
      • iterate

        public static void iterate​(INDArray arr,
                                   INDArray arr2,
                                   CoordinateFunction coordinateFunction)
        Iterate over 2 coordinate spaces given 2 arrays
        Parameters:
        arr - the first array
        arr2 - the second array
        coordinateFunction - the coordinate function to use
      • iterate

        public static void iterate​(int dimension,
                                   int n,
                                   int[] size,
                                   int[] res,
                                   int dimension2,
                                   int n2,
                                   int[] size2,
                                   int[] res2,
                                   CoordinateFunction func)
        Iterate over a pair of coordinates
        Parameters:
        dimension -
        n -
        size -
        res -
        dimension2 -
        n2 -
        size2 -
        res2 -
        func -
      • iterate

        public static void iterate​(int dimension,
                                   int n,
                                   long[] size,
                                   long[] res,
                                   int dimension2,
                                   int n2,
                                   long[] size2,
                                   long[] res2,
                                   CoordinateFunction func)
      • iterate

        public static void iterate​(int dimension,
                                   int n,
                                   int[] size,
                                   int[] res,
                                   CoordinateFunction func)
        Iterate over a pair of coordinates
        Parameters:
        dimension -
        n -
        size -
      • iterate

        public static void iterate​(int dimension,
                                   int n,
                                   long[] size,
                                   long[] res,
                                   CoordinateFunction func)
      • getOffset

        public static long getOffset​(long baseOffset,
                                     int[] shape,
                                     int[] stride,
                                     int... indices)
        Get an offset for retrieval from a data buffer based on the given shape stride and given indices
        Parameters:
        baseOffset - the offset to start from
        shape - the shape of the array
        stride - the stride of the array
        indices - the indices to iterate over
        Returns:
        the double at the specified index
      • getOffset

        public static long getOffset​(LongBuffer shapeInformation,
                                     long... indices)
        Get the offset of the specified indices from the shape info buffer
        Parameters:
        shapeInformation - Shape information to get the offset for
        indices - Indices array to get the offset for (must be same length as array rank)
        Returns:
        Buffer offset fo the specified indices
      • getOffset

        public static long getOffset​(IntBuffer shapeInformation,
                                     long... indices)
      • getOffset

        @Deprecated
        public static long getOffset​(DataBuffer shapeInformation,
                                     int[] indices)
        Deprecated.
        Get the offset of the specified indices from the shape info buffer
        Parameters:
        shapeInformation - Shape information to get the offset for
        indices - Indices array to get the offset for (must be same length as array rank)
        Returns:
        Buffer offset fo the specified indices
      • getOffset

        public static long getOffset​(DataBuffer shapeInformation,
                                     long... indices)
      • getOffset

        public static long getOffset​(int[] shapeInformation,
                                     int... indices)
      • getOffset

        public static long getOffset​(long[] shapeInformation,
                                     int... indices)
      • getOffset

        public static long getOffset​(long[] shapeInformation,
                                     long... indices)
      • getOffset

        public static long getOffset​(DataBuffer shapeInformation,
                                     int row,
                                     int col)
        Get the offset of the specified [row,col] for the 2d array
        Parameters:
        shapeInformation - Shape information
        row - Row index to get the offset for
        col - Column index to get the offset for
        Returns:
        Buffer offset
      • getOffsetUnsafe

        public static long getOffsetUnsafe​(int[] shapeInformation,
                                           int row,
                                           int col)
      • getOffsetUnsafe

        public static long getOffsetUnsafe​(long[] shapeInformation,
                                           long row,
                                           long col)
      • getOffset

        public static long getOffset​(IntBuffer shapeInformation,
                                     int row,
                                     int col)
        Get the offset of the specified [row,col] for the 2d array
        Parameters:
        shapeInformation - Shape information
        row - Row index to get the offset for
        col - Column index to get the offset for
        Returns:
        Buffer offset
      • getOffset

        public static long getOffset​(IntBuffer shapeInformation,
                                     int dim0,
                                     int dim1,
                                     int dim2)
        Get the offset of the specified [dim0,dim1,dim2] for the 3d array
        Parameters:
        shapeInformation - Shape information
        dim0 - Row index to get the offset for
        dim1 - Column index to get the offset for
        dim2 - dimension 2 index to get the offset for
        Returns:
        Buffer offset
      • getOffset

        public static long getOffset​(DataBuffer shapeInformation,
                                     int dim0,
                                     int dim1,
                                     int dim2)
        Get the offset of the specified [dim0,dim1,dim2] for the 3d array
        Parameters:
        shapeInformation - Shape information
        dim0 - Row index to get the offset for
        dim1 - Column index to get the offset for
        dim2 - dimension 2 index to get the offset for
        Returns:
        Buffer offset
      • getOffsetUnsafe

        public static long getOffsetUnsafe​(int[] shapeInformation,
                                           int dim0,
                                           int dim1,
                                           int dim2)
      • getOffset

        public static long getOffset​(IntBuffer shapeInformation,
                                     int dim0,
                                     int dim1,
                                     int dim2,
                                     int dim3)
        Get the offset of the specified [dim0,dim1,dim2,dim3] for the 4d array
        Parameters:
        shapeInformation - Shape information
        dim0 - Row index to get the offset for
        dim1 - Column index to get the offset for
        dim2 - dimension 2 index to get the offset for
        dim3 - dimension 3 index to get the offset for
        Returns:
        Buffer offset
      • getOffset

        public static long getOffset​(DataBuffer shapeInformation,
                                     int dim0,
                                     int dim1,
                                     int dim2,
                                     int dim3)
        Get the offset of the specified [dim0,dim1,dim2,dim3] for the 4d array
        Parameters:
        shapeInformation - Shape information
        dim0 - Row index to get the offset for
        dim1 - Column index to get the offset for
        dim2 - dimension 2 index to get the offset for
        dim3 - dimension 3 index to get the offset for
        Returns:
        Buffer offset
      • getOffsetUnsafe

        public static long getOffsetUnsafe​(DataBuffer shapeInformation,
                                           int dim0,
                                           int dim1,
                                           int dim2,
                                           int dim3)
      • getOffsetUnsafe

        public static long getOffsetUnsafe​(int[] shapeInformation,
                                           int dim0,
                                           int dim1,
                                           int dim2,
                                           int dim3)
      • getOffsetUnsafe

        public static long getOffsetUnsafe​(long[] shapeInformation,
                                           long dim0,
                                           long dim1,
                                           long dim2,
                                           long dim3)
      • sizeForAxes

        public static int[] sizeForAxes​(int[] axes,
                                        int[] shape)
        Output an int array for a particular dimension
        Parameters:
        axes - the axes
        shape - the current shape
        Returns:
      • isVector

        public static boolean isVector​(IntBuffer shapeInfo)
        Returns whether the given shape is a vector
        Parameters:
        shapeInfo - the shapeinfo to test
        Returns:
        whether the given shape is a vector
      • isVector

        public static boolean isVector​(LongBuffer shapeInfo)
      • isVector

        public static boolean isVector​(DataBuffer shapeInfo)
        Returns whether the given shape is a vector
        Parameters:
        shapeInfo - the shapeinfo to test
        Returns:
        whether the given shape is a vector
      • isVector

        public static boolean isVector​(int[] shape)
        Returns whether the given shape is a vector
        Parameters:
        shape - the shape to test
        Returns:
        whether the given shape is a vector
      • isVector

        public static boolean isVector​(long[] shape)
      • isMatrix

        public static boolean isMatrix​(IntBuffer shapeInfo)
        Returns whether the passed in shape is a matrix
        Parameters:
        shapeInfo - whether the passed in shape is a matrix
        Returns:
        true if the shape is a matrix false otherwise
      • isMatrix

        public static boolean isMatrix​(DataBuffer shapeInfo)
        Returns whether the passed in shape is a matrix
        Parameters:
        shapeInfo - whether the passed in shape is a matrix
        Returns:
        true if the shape is a matrix false otherwise
      • isMatrix

        public static boolean isMatrix​(int[] shape)
        Returns whether the passed in shape is a matrix
        Parameters:
        shape - whether the passed in shape is a matrix
        Returns:
        true if the shape is a matrix false otherwise
      • isMatrix

        public static boolean isMatrix​(long[] shape)
      • squeeze

        public static int[] squeeze​(int[] shape)
        Gets rid of any singleton dimensions of the given array
        Parameters:
        shape - the shape to squeeze
        Returns:
        the array with all of the singleton dimensions removed
      • squeeze

        public static long[] squeeze​(long[] shape)
        Gets rid of any singleton dimensions of the given array
        Parameters:
        shape - the shape to squeeze
        Returns:
        the array with all of the singleton dimensions removed
      • shapeEqualWithSqueeze

        public static boolean shapeEqualWithSqueeze​(long[] shape1,
                                                    long[] shape2)
        Return true if the shapes are equal after removing any size 1 dimensions For example, [1,3,4] and [3,4] are considered equal by this method. Or [2,1,1] and [1,2] are considered equal.
        Parameters:
        shape1 - First shape
        shape2 - Second shape
        Returns:
      • shapeEquals

        public static boolean shapeEquals​(int[] shape1,
                                          int[] shape2)
        Returns whether 2 shapes are equals by checking for dimension semantics as well as array equality
        Parameters:
        shape1 - the first shape for comparison
        shape2 - the second shape for comparison
        Returns:
        whether the shapes are equivalent
      • shapeEquals

        public static boolean shapeEquals​(long[] shape1,
                                          long[] shape2)
        Returns whether 2 shapes are equals by checking for dimension semantics as well as array equality
        Parameters:
        shape1 - the first shape for comparison
        shape2 - the second shape for comparison
        Returns:
        whether the shapes are equivalent
      • scalarEquals

        public static boolean scalarEquals​(int[] shape1,
                                           int[] shape2)
        Returns true if the given shapes are both scalars (0 dimension or shape[0] == 1)
        Parameters:
        shape1 - the first shape for comparison
        shape2 - the second shape for comparison
        Returns:
        whether the 2 shapes are equal based on scalar rules
      • scalarEquals

        public static boolean scalarEquals​(long[] shape1,
                                           long[] shape2)
      • isRowVectorShape

        public static boolean isRowVectorShape​(DataBuffer shapeInfo)
        Returns true if the given shape is of length 1 or provided the shape length is 2: element 0 is 1
        Parameters:
        shapeInfo - the shape info to check
        Returns:
        true if the above conditions hold,false otherwise
      • isRowVectorShape

        public static boolean isRowVectorShape​(IntBuffer shapeInfo)
        Returns true if the given shape is of length 1 or provided the shape length is 2: element 0 is 1
        Parameters:
        shapeInfo - the shape info to check
        Returns:
        true if the above conditions hold,false otherwise
      • isRowVectorShape

        public static boolean isRowVectorShape​(int[] shape)
        Returns true if the given shape is of length 1 or provided the shape length is 2: element 0 is 1
        Parameters:
        shape - the shape to check
        Returns:
        true if the above conditions hold,false otherwise
      • isRowVectorShape

        public static boolean isRowVectorShape​(long[] shape)
      • isColumnVectorShape

        public static boolean isColumnVectorShape​(int[] shape)
        Returns true if the given shape is length 2 and the size at element 1 is 1
        Parameters:
        shape - the shape to check
        Returns:
        true if the above listed conditions hold false otherwise
      • isColumnVectorShape

        public static boolean isColumnVectorShape​(long[] shape)
        Returns true if the given shape length is 2 and the size at element 1 is 1
        Parameters:
        shape -
        Returns:
      • ensureAtMinRowVector

        public static int[] ensureAtMinRowVector​(int... shape)
        If a shape array is ony 1 in length it returns a row vector
        Parameters:
        shape - the shape of the array
        Returns:
        the shape as is if its already >= 2 in length otherwise a row vector shape
      • getTADLength

        public static long getTADLength​(int[] shape,
                                        int... dimensions)
      • getTADLength

        public static long getTADLength​(long[] shape,
                                        int... dimensions)
      • elementWiseStride

        public static int elementWiseStride​(int[] shape,
                                            int[] stride,
                                            boolean isFOrder)
        Parameters:
        shape -
        stride -
        isFOrder -
        Returns:
      • elementWiseStride

        public static long elementWiseStride​(long[] shape,
                                             long[] stride,
                                             boolean isFOrder)
      • newShapeNoCopy

        public static INDArray newShapeNoCopy​(INDArray arr,
                                              int[] newShape,
                                              boolean isFOrder)
      • newShapeNoCopy

        public static INDArray newShapeNoCopy​(INDArray arr,
                                              long[] newShape,
                                              boolean isFOrder)
        A port of numpy's reshaping algorithm that leverages no copy where possible and returns null if the reshape couldn't happen without copying
        Parameters:
        arr - the array to reshape
        newShape - the new shape
        isFOrder - whether the array will be fortran ordered or not
        Returns:
        null if a reshape isn't possible, or a new ndarray
      • cOrFortranOrder

        public static boolean cOrFortranOrder​(long[] shape,
                                              long[] stride,
                                              long elementStride)
        Infer order from
        Parameters:
        shape - the shape to infer by
        stride - the stride to infer by
        elementStride - the element stride to start at
        Returns:
        the storage order given shape and element stride
      • cOrFortranOrder

        @Deprecated
        public static boolean cOrFortranOrder​(int[] shape,
                                              int[] stride,
                                              int elementStride)
        Deprecated.
      • getOrder

        public static char getOrder​(int[] shape,
                                    int[] stride,
                                    int elementStride)
        Infer order from
        Parameters:
        shape - the shape to infer by
        stride - the stride to infer by
        elementStride - the element stride to start at
        Returns:
        the storage order given shape and element stride
      • getOrder

        public static char getOrder​(long[] shape,
                                    long[] stride,
                                    long elementStride)
      • getOrder

        public static char getOrder​(INDArray arr)
        Infer the order for the ndarray based on the array's strides
        Parameters:
        arr - the array to get the ordering for
        Returns:
        the ordering for the given array
      • sub2Ind

        public static long sub2Ind​(int[] shape,
                                   int[] indices)
        Convert the given index (such as 1,1) to a linear index
        Parameters:
        shape - the shape of the indexes to convert
        indices - the index to convert
        Returns:
        the linear index given the shape and indices
      • ind2sub

        public static int[] ind2sub​(int[] shape,
                                    long index,
                                    long numIndices)
        Convert a linear index to the equivalent nd index
        Parameters:
        shape - the shape of the dimensions
        index - the index to map
        numIndices - the number of total indices (typically prod of shape(
        Returns:
        the mapped indexes along each dimension
      • ind2sub

        public static long[] ind2sub​(long[] shape,
                                     long index,
                                     long numIndices)
      • ind2sub

        public static int[] ind2sub​(int[] shape,
                                    long index)
        Convert a linear index to the equivalent nd index. Infers the number of indices from the specified shape.
        Parameters:
        shape - the shape of the dimensions
        index - the index to map
        Returns:
        the mapped indexes along each dimension
      • ind2sub

        public static long[] ind2sub​(long[] shape,
                                     long index)
      • ind2sub

        public static long[] ind2sub​(INDArray arr,
                                     long index)
        Convert a linear index to the equivalent nd index based on the shape of the specified ndarray. Infers the number of indices from the specified shape.
        Parameters:
        arr - the array to compute the indexes based on
        index - the index to map
        Returns:
        the mapped indexes along each dimension
      • ind2subC

        public static int[] ind2subC​(int[] shape,
                                     long index,
                                     long numIndices)
        Convert a linear index to the equivalent nd index
        Parameters:
        shape - the shape of the dimensions
        index - the index to map
        numIndices - the number of total indices (typically prod of shape(
        Returns:
        the mapped indexes along each dimension
      • ind2subC

        public static long[] ind2subC​(long[] shape,
                                      long index,
                                      long numIndices)
      • ind2subC

        public static int[] ind2subC​(int[] shape,
                                     long index)
        Convert a linear index to the equivalent nd index. Infers the number of indices from the specified shape.
        Parameters:
        shape - the shape of the dimensions
        index - the index to map
        Returns:
        the mapped indexes along each dimension
      • ind2subC

        public static long[] ind2subC​(long[] shape,
                                      long index)
      • ind2subC

        public static long[] ind2subC​(INDArray arr,
                                      long index)
        Convert a linear index to the equivalent nd index based on the shape of the specified ndarray. Infers the number of indices from the specified shape.
        Parameters:
        arr - the array to compute the indexes based on
        index - the index to map
        Returns:
        the mapped indexes along each dimension
      • assertShapeLessThan

        public static void assertShapeLessThan​(int[] shape,
                                               int[] lessThan)
        Assert the both shapes are the same length and shape[i] < lessThan[i]
        Parameters:
        shape - the shape to check
        lessThan - the shape to assert against
      • assertShapeLessThan

        public static void assertShapeLessThan​(long[] shape,
                                               long[] lessThan)
      • newStrides

        public static int[] newStrides​(int[] strides,
                                       int newLength,
                                       INDArrayIndex[] indexes)
      • strideDescendingCAscendingF

        public static boolean strideDescendingCAscendingF​(INDArray array)
        Check if strides are in order suitable for non-strided mmul etc. Returns true if c order and strides are descending [100,10,1] etc Returns true if f order and strides are ascending [1,10,100] etc False otherwise.
        Returns:
        true if c+descending, f+ascending, false otherwise
      • length

        public static int length​(IntBuffer buffer)
        Gets the rank given the shape info buffer
        Parameters:
        buffer - the buffer to get the rank for
        Returns:
        the rank for the shape buffer
      • length

        public static int length​(LongBuffer buffer)
      • length

        public static long length​(DataBuffer buffer)
        Gets the rank given the shape info buffer
        Parameters:
        buffer - the buffer to get the rank for
        Returns:
        the rank for the shape buffer
      • length

        public static long length​(int[] buffer)
      • length

        public static long length​(long[] buffer)
      • rank

        public static int rank​(DataBuffer buffer)
        Gets the rank given the shape info buffer
        Parameters:
        buffer - the buffer to get the rank for
        Returns:
        the rank for the shape buffer
      • rank

        public static int rank​(IntBuffer buffer)
        Gets the rank given the shape info buffer
        Parameters:
        buffer - the buffer to get the rank for
        Returns:
        the rank for the shape buffer
      • rank

        public static int rank​(LongBuffer buffer)
      • rank

        public static int rank​(long[] buffer)
      • rank

        public static int rank​(int[] buffer)
      • size

        public static int size​(IntBuffer buffer,
                               int dimension)
        Get the size of the specified dimension. Equivalent to shape()[dimension]
        Parameters:
        buffer - The buffer to get the
        dimension - The dimension to get.
        Returns:
        The size of the specified dimension
      • size

        public static long size​(LongBuffer buffer,
                                int dimension)
      • size

        public static int size​(DataBuffer buffer,
                               int dimension)
        Get the size of the specified dimension. Equivalent to shape()[dimension]
        Parameters:
        buffer - The buffer to get the shape from
        dimension - The dimension to get.
        Returns:
        The size of the specified dimension
      • size

        public static int size​(int[] buffer,
                               int dimension)
      • size

        public static long size​(long[] buffer,
                                int dimension)
      • sizeUnsafe

        public static int sizeUnsafe​(DataBuffer buffer,
                                     int dimension)
        Get the size of the specified dimension. Identical to Shape.size(...), but does not perform any input validation
        Parameters:
        buffer - The buffer to get the shape from
        dimension - The dimension to get.
        Returns:
        The size of the specified dimension
      • sizeUnsafe

        public static int sizeUnsafe​(int[] buffer,
                                     int dimension)
      • sizeUnsafe

        public static long sizeUnsafe​(long[] buffer,
                                      int dimension)
      • shape

        public static long[] shape​(IntBuffer buffer)
        Get array shape from the buffer, as an int[]
        Parameters:
        buffer - Buffer to get the shape from
        Returns:
        Shape array
      • shape

        public static long[] shape​(LongBuffer buffer)
      • shape

        public static long[] shape​(DataBuffer buffer)
        Get array shape from the buffer, as an int[]
        Parameters:
        buffer - Buffer to get the shape from
        Returns:
        Shape array
      • shape

        public static int[] shape​(int[] buffer)
        Get array shape from an int[]
        Parameters:
        buffer - Buffer to get the shape from
        Returns:
        Shape array
      • shape

        public static long[] shape​(long[] buffer)
      • stride

        public static int stride​(IntBuffer buffer,
                                 int dimension)
        Get the stride of the specified dimension
        Parameters:
        buffer - The buffer to get the stride from
        dimension - The dimension to get.
        Returns:
        The stride of the specified dimension
      • stride

        public static long stride​(LongBuffer buffer,
                                  int dimension)
      • stride

        public static int stride​(DataBuffer buffer,
                                 int dimension)
        Get the stride of the specified dimension
        Parameters:
        buffer - The buffer to get the stride from
        dimension - The dimension to get.
        Returns:
        The stride of the specified dimension
      • stride

        public static int stride​(int[] buffer,
                                 int dimension)
      • stride

        public static long stride​(long[] buffer,
                                  int dimension)
      • strideArr

        public static long[] strideArr​(DataBuffer buffer)
        Get array shape from the buffer, as an int[]
        Parameters:
        buffer - Buffer to get the shape from
        Returns:
        Shape array
      • strideUnsafe

        public static int strideUnsafe​(DataBuffer buffer,
                                       int dimension,
                                       int rank)
        Get the stride of the specified dimension, without any input validation
        Parameters:
        buffer - The buffer to get the stride from
        dimension - The dimension to get.
        rank - Rank of the array
        Returns:
        The stride of the specified dimension
      • strideUnsafe

        public static int strideUnsafe​(int[] buffer,
                                       int dimension,
                                       int rank)
      • strideUnsafe

        public static long strideUnsafe​(long[] buffer,
                                        int dimension,
                                        int rank)
      • shapeInfoLength

        public static int shapeInfoLength​(long rank)
        Return the shape info length given the rank
        Parameters:
        rank - the rank to get the length for
        Returns:
        rank * 2 + 4
      • shapeInfoLength

        public static int shapeInfoLength​(long[] shape)
      • stride

        public static IntBuffer stride​(IntBuffer buffer)
        Get the stride for the given shape information buffer
        Parameters:
        buffer -
        Returns:
      • stride

        public static DataBuffer stride​(DataBuffer buffer)
        Get the shape from the given int buffer
        Parameters:
        buffer - the buffer to get the shape information for
        Returns:
      • stride

        public static int[] stride​(int[] buffer)
      • stride

        public static long[] stride​(long[] buffer)
      • shapeOf

        public static DataBuffer shapeOf​(DataBuffer buffer)
        Get the shape from the given int buffer
        Parameters:
        buffer - the buffer to get the shape information for
        Returns:
      • shapeOf

        public static IntBuffer shapeOf​(IntBuffer buffer)
        Get the shape from the given int buffer
        Parameters:
        buffer - the buffer to get the shape information for
        Returns:
      • shapeOf

        public static int[] shapeOf​(int[] buffer)
      • shapeOf

        public static long[] shapeOf​(long[] buffer)
      • stridesOf

        public static int[] stridesOf​(int[] buffer)
      • stridesOf

        public static long[] stridesOf​(long[] buffer)
      • flags

        public static int[] flags​(DataBuffer buffer)
      • sparseOffsets

        public static int[] sparseOffsets​(DataBuffer buffer)
      • hiddenDimension

        public static int[] hiddenDimension​(DataBuffer buffer)
      • underlyingRank

        public static int underlyingRank​(DataBuffer buffer)
      • shapeToString

        public static String shapeToString​(INDArray arr)
        Prints the shape for this shape information
        Parameters:
        arr - the shape information to print
        Returns:
        the shape information to string
      • shapeToString

        public static String shapeToString​(IntBuffer buffer)
        Prints the shape for this shape information
        Parameters:
        buffer - the shape information to print
        Returns:
        the shape information to string
      • shapeToStringShort

        public static String shapeToStringShort​(INDArray arr)
      • offset

        @Deprecated
        public static int offset​(DataBuffer buffer)
        Deprecated.
        Get the offset for the buffer PLEASE NOTE: Legacy method. Will return 0 ALWAYS
        Parameters:
        buffer - the shape info buffer to get the offset for
        Returns:
      • options

        public static long options​(long[] buffer)
      • extras

        public static long extras​(long[] buffer)
      • offset

        @Deprecated
        public static int offset​(int[] buffer)
        Deprecated.
        Get the offset for the buffer PLEASE NOTE: Legacy method. Will return 0 ALWAYS
        Parameters:
        buffer -
        Returns:
      • offset

        @Deprecated
        public static int offset​(long[] buffer)
        Deprecated.
      • offset

        @Deprecated
        public static int offset​(IntBuffer buffer)
        Deprecated.
        Get the offset for the buffer
        Parameters:
        buffer - the shape info buffer to get the offset for
        Returns:
      • elementWiseStride

        public static int elementWiseStride​(DataBuffer buffer)
        Get the element wise stride for the shape info buffer
        Parameters:
        buffer - the buffer to get the element wise stride from
        Returns:
        the element wise stride for the buffer
      • elementWiseStride

        public static int elementWiseStride​(IntBuffer buffer)
        Get the element wise stride for the shape info buffer
        Parameters:
        buffer - the buffer to get the element wise stride from
        Returns:
        the element wise stride for the buffer
      • elementWiseStride

        public static long elementWiseStride​(LongBuffer buffer)
      • elementWiseStride

        public static long elementWiseStride​(long[] buffer)
        Get the element wise stride for the shape info buffer
        Parameters:
        buffer - the buffer to get the element wise stride from
        Returns:
        the element wise stride for the buffer
      • setElementWiseStride

        public static void setElementWiseStride​(IntBuffer buffer,
                                                int elementWiseStride)
        Get the element wise stride for the shape info buffer
        Parameters:
        buffer - the buffer to get the element wise stride from
      • setElementWiseStride

        public static void setElementWiseStride​(DataBuffer buffer,
                                                int elementWiseStride)
        Get the element wise stride for the shape info buffer
        Parameters:
        buffer - the buffer to get the element wise stride from
      • bufferToString

        public static String bufferToString​(IntBuffer buffer)
        Prints the IntBuffer
        Parameters:
        buffer - the buffer to print
        Returns:
        the to string for the buffer
      • order

        public static char order​(IntBuffer buffer)
        Returns the order given the shape information
        Parameters:
        buffer - the buffer
        Returns:
      • order

        public static char order​(LongBuffer buffer)
      • order

        public static char order​(DataBuffer buffer)
        Returns the order given the shape information
        Parameters:
        buffer - the buffer
        Returns:
      • order

        public static char order​(int[] buffer)
      • order

        public static char order​(long[] buffer)
      • setOrder

        @Deprecated
        public static void setOrder​(IntBuffer buffer,
                                    char order)
        Deprecated.
        Returns the order given the shape information
        Parameters:
        buffer - the buffer
      • createShapeInformation

        public static DataBuffer createShapeInformation​(long[] shape,
                                                        long[] stride,
                                                        long elementWiseStride,
                                                        char order,
                                                        DataType dataType,
                                                        boolean empty)
      • createShapeInformation

        public static DataBuffer createShapeInformation​(long[] shape,
                                                        long[] stride,
                                                        long elementWiseStride,
                                                        char order,
                                                        long extras)
      • createSparseInformation

        public static DataBuffer createSparseInformation​(int[] flags,
                                                         long[] sparseOffsets,
                                                         int[] hiddenDimensions,
                                                         int underlyingRank)
      • toBuffer

        public static IntBuffer toBuffer​(int... arr)
        Convert an array to a byte buffer
        Parameters:
        arr - the array
        Returns:
        a direct byte buffer with the array contents
      • toString

        public static String toString​(IntBuffer buffer)
        To String for an int buffer
        Parameters:
        buffer -
        Returns:
      • toString

        public static String toString​(DataBuffer buffer)
        To String for an int buffer
        Parameters:
        buffer -
        Returns:
      • wholeArrayDimension

        public static boolean wholeArrayDimension​(int... arr)
        Returns true if the given array is meant for the whole dimension
        Parameters:
        arr - the array to test
        Returns:
        true if arr.length == 1 && arr[0] is Integer.MAX_VALUE
      • uniquify

        public static int[] uniquify​(int[] array)
      • normalizeAxis

        public static int[] normalizeAxis​(int rank,
                                          int... axis)
      • contentEquals

        public static boolean contentEquals​(int[] arr,
                                            DataBuffer other)
        Compare the contents of a buffer and an array for equals
        Parameters:
        arr - the array
        other - the buffer
        Returns:
        true if the content equals false otherwise
      • contentEquals

        public static boolean contentEquals​(long[] arr,
                                            long[] other)
      • contentEquals

        public static boolean contentEquals​(long[] arr,
                                            DataBuffer other)
      • contentEquals

        public static boolean contentEquals​(int[] arr,
                                            IntBuffer other)
        Compare the contents of a buffer and an array for equals
        Parameters:
        arr - the array
        other - the buffer
        Returns:
        true if the content equals false otherwise
      • contentEquals

        public static boolean contentEquals​(long[] arr,
                                            IntBuffer other)
      • contentEquals

        public static boolean contentEquals​(long[] arr,
                                            LongBuffer other)
      • isContiguousInBuffer

        public static boolean isContiguousInBuffer​(INDArray in)
        Are the elements in the buffer contiguous for this NDArray?
      • toMmulCompatible

        public static INDArray toMmulCompatible​(INDArray input)
        This method is used in DL4J LSTM implementation
        Parameters:
        input -
        Returns:
      • rankFromShape

        public static int rankFromShape​(int[] shape)
        Return the rank for the given shape
        Parameters:
        shape - Shape to get the rank for
        Returns:
        Rank, of the array given the shape
        Throws:
        ND4JIllegalStateException - If shape array is null
      • rankFromShape

        public static int rankFromShape​(long[] shape)
      • assertBroadcastable

        public static void assertBroadcastable​(@NonNull
                                               @NonNull INDArray x,
                                               @NonNull
                                               @NonNull INDArray y)
      • assertBroadcastable

        public static void assertBroadcastable​(@NonNull
                                               @lombok.NonNull int[] x,
                                               @NonNull
                                               @lombok.NonNull int[] y)
      • assertBroadcastable

        public static void assertBroadcastable​(@NonNull
                                               @lombok.NonNull long[] x,
                                               @NonNull
                                               @lombok.NonNull long[] y)
      • assertBroadcastable

        public static void assertBroadcastable​(@NonNull
                                               @lombok.NonNull long[] x,
                                               @NonNull
                                               @lombok.NonNull long[] y,
                                               Class<?> opClass)
      • areShapesBroadcastable

        public static boolean areShapesBroadcastable​(@NonNull
                                                     @lombok.NonNull int[] x,
                                                     @NonNull
                                                     @lombok.NonNull int[] y)
      • areShapesBroadcastable

        public static boolean areShapesBroadcastable​(@NonNull
                                                     @lombok.NonNull long[] left,
                                                     @NonNull
                                                     @lombok.NonNull long[] right)
      • lengthOf

        public static long lengthOf​(long[] shape)
        Parameters:
        shape -
        Returns:
      • lengthOf

        public static long lengthOf​(int[] shape)
      • lengthOfBuffer

        public static long lengthOfBuffer​(@NonNull
                                          @lombok.NonNull long[] shape,
                                          @NonNull
                                          @lombok.NonNull long[] stride)
        Calculate the length of the buffer required to store the given shape with the given strides
        Parameters:
        shape - Shape of the array
        stride - Strides
        Returns:
        Length of the buffer
      • lengthOfBuffer

        public static long lengthOfBuffer​(@NonNull
                                          @lombok.NonNull int[] shape,
                                          @NonNull
                                          @lombok.NonNull int[] stride)
        Calculate the length of the buffer required to store the given shape with the given strides
        Parameters:
        shape - Shape of the array
        stride - Strides
        Returns:
        Length of the buffer
      • hasDefaultStridesForShape

        public static boolean hasDefaultStridesForShape​(INDArray input)
      • isS

        public static boolean isS​(@NonNull
                                  @NonNull DataType x)
      • isB

        public static boolean isB​(@NonNull
                                  @NonNull DataType x)
      • isZ

        public static boolean isZ​(@NonNull
                                  @NonNull DataType x)
      • isR

        public static boolean isR​(@NonNull
                                  @NonNull DataType x)
      • pickPairwiseDataType

        public static DataType pickPairwiseDataType​(@NonNull
                                                    @NonNull DataType typeX,
                                                    @NonNull
                                                    @NonNull Number number)
      • pickPairwiseDataType

        public static DataType pickPairwiseDataType​(@NonNull
                                                    @NonNull DataType typeX,
                                                    @NonNull
                                                    @NonNull DataType typeY)
        Return a data type to use for output within a pair wise operation such as add or subtract. Basically: favor float like data types over ints since they're typically used for indexing.
        Parameters:
        typeX - the first input data type
        typeY - the second input data type
        Returns:
        the resolved data type
      • isEmpty

        public static boolean isEmpty​(long[] shapeInfo)
      • assertValidOrder

        public static void assertValidOrder​(char order)
      • ndArrayDimFromInt

        public static INDArray ndArrayDimFromInt​(int... dimensions)
        Create an INDArray to represent the (possibly null) int[] dimensions. If null or length 0, returns an empty INT array. Otherwise, returns a 1d INT NDArray
        Parameters:
        dimensions - Dimensions to convert
        Returns:
        Dimensions as an INDArray
      • reductionShape

        public static long[] reductionShape​(INDArray x,
                                            int[] dimension,
                                            boolean newFormat,
                                            boolean keepDims)
        Calculate the shape of the returned array, for a reduction along dimension
        Parameters:
        x - Input array to reduce
        dimension - Dimensions/axis to reduce on
        newFormat - If new format (almost always true; will be removed eventually)
        keepDims - If reduced dimensions should be kept as size 1 dimensions
        Returns:
        Shape of the output array for the reduction
      • shapeMatchesPlaceholder

        public static boolean shapeMatchesPlaceholder​(long[] phShape,
                                                      long[] arrShape)
        Determine whether the placeholder shape and the specified shape are compatible.
        Shapes are compatible if:
        (a) They are both the same length (same array rank, or null)
        (b) At each position either phShape[i] == -1 or phShape[i] == arrShape[i]
        Parameters:
        phShape - Placeholder shape
        arrShape - Array shape to check if it matches the placeholder shape
        Returns:
        True if the array shape is compatible with the placeholder shape