Class Nd4j


  • public class Nd4j
    extends Object
    • Field Detail

      • bitwise

        public static final NDBitwise bitwise
        Bitwise namespace - operations related to bitwise manipulation of arrays
      • linalg

        public static final NDLinalg linalg
        Bitwise namespace - operations related to bitwise manipulation of arrays
      • math

        public static final NDMath math
        Math namespace - general mathematical operations
      • random

        public static final NDRandom random
        Random namespace - (pseudo) random number generation methods
      • nn

        public static final NDNN nn
        Neural network namespace - operations related to neural networks
      • loss

        public static final NDLoss loss
        Loss function namespace - operations related to loss functions.
      • cnn

        public static final NDCNN cnn
        Convolutional network namespace - operations related to convolutional neural networks
      • rnn

        public static final NDRNN rnn
        Recurrent neural network namespace - operations related to recurrent neural networks
      • image

        public static final NDImage image
        Image namespace - operations related to images
      • dtype

        protected static DataType dtype
      • EPS_THRESHOLD

        public static double EPS_THRESHOLD
      • compressDebug

        public static boolean compressDebug
      • preventUnpack

        public static volatile boolean preventUnpack
    • Constructor Detail

      • Nd4j

        public Nd4j()
    • Method Detail

      • bitwise

        public static NDBitwise bitwise()
        Bitwise namespace - operations related to bitwise manipulation of arrays
      • math

        public static NDMath math()
        Math namespace - general mathematical operations
      • linalg

        public static NDLinalg linalg()
        Linalg namespace - operations related to linear algebra (lapack operations)
      • random

        public static NDRandom random()
        Random namespace - (pseudo) random number generation methods
      • nn

        public static NDNN nn()
        Neural network namespace - operations related to neural networks
      • loss

        public static NDLoss loss()
        Loss function namespace - operations related to loss functions.
      • cnn

        public static NDCNN cnn()
        Convolutional network namespace - operations related to convolutional neural networks
      • rnn

        public static NDRNN rnn()
        Recurrent neural network namespace - operations related to recurrent neural networks
      • image

        public static NDImage image()
        Image namespace - operations related to images
      • pad

        public static INDArray pad​(@NonNull
                                   @NonNull INDArray toPad,
                                   @NonNull
                                   @lombok.NonNull int... padWidth)
        See pad(INDArray, INDArray). Uses 0 padding, and uses padWidth for all dimensions.
      • pad

        public static INDArray pad​(@NonNull
                                   @NonNull INDArray toPad,
                                   @NonNull
                                   @NonNull INDArray padWidth,
                                   @NonNull
                                   Pad.Mode padMode,
                                   double padValue)
        Pad the given ndarray to the size along each dimension.
        Parameters:
        toPad - the ndarray to pad
        padWidth - the width to pad along each dimension
        padMode - the mode to pad in
        padValue - the value used during padding. Only used when padMode is Pad.Mode.CONSTANT.
        Returns:
        the padded ndarray based on the specified mode
      • append

        public static INDArray append​(INDArray arr,
                                      int padAmount,
                                      double val,
                                      int axis)
        Append the given array with the specified value size along a particular axis. The prepend method has the same signature and prepends the given array.
        Parameters:
        arr - the array to append to
        padAmount - the pad amount of the array to be returned
        val - the value to append
        axis - the axis to append to
        Returns:
        the newly created array
      • expandDims

        public static INDArray expandDims​(INDArray input,
                                          int dimension)
        Expand the array dimensions. This is equivalent to adding a new axis dimension
        Parameters:
        input - the input array
        dimension - the dimension to add the new axis at
        Returns:
        the array with the new axis dimension
      • squeeze

        public static INDArray squeeze​(INDArray input,
                                       int dimension)
        Squeeze : removes a dimension of size 1
        Parameters:
        input - the input array
        dimension - the dimension to remove
        Returns:
        the array with dimension removed
      • allowsSpecifyOrdering

        public static boolean allowsSpecifyOrdering()
        Backend specific: Returns whether specifying the order for the blas impl is allowed (cblas)
        Returns:
        true if the blas impl can support specifying array order
      • shuffle

        public static void shuffle​(INDArray toShuffle,
                                   Random random,
                                   @NonNull
                                   @lombok.NonNull int... dimension)
        In place shuffle of an ndarray along a specified set of dimensions
        Parameters:
        toShuffle - the ndarray to shuffle
        random - the random to use
        dimension - the dimension to do the shuffle
      • shuffle

        public static void shuffle​(INDArray toShuffle,
                                   @NonNull
                                   @lombok.NonNull int... dimension)
        In place shuffle of an ndarray along a specified set of dimensions
        Parameters:
        toShuffle - the ndarray to shuffle
        dimension - the dimension to do the shuffle
      • shuffle

        public static void shuffle​(Collection<INDArray> toShuffle,
                                   @NonNull
                                   @lombok.NonNull int... dimension)
        Symmetric in place shuffle of an ndarray along a specified set of dimensions
        Parameters:
        toShuffle - the ndarray to shuffle
        dimension - the dimension to do the shuffle
      • shuffle

        public static void shuffle​(Collection<INDArray> toShuffle,
                                   Random rnd,
                                   @NonNull
                                   @lombok.NonNull int... dimension)
        Symmetric in place shuffle of an ndarray along a specified set of dimensions
        Parameters:
        toShuffle - the ndarray to shuffle
        dimension - the dimension to do the shuffle
      • shuffle

        public static void shuffle​(List<INDArray> toShuffle,
                                   Random rnd,
                                   List<int[]> dimensions)
        Symmetric in place shuffle of an ndarray along a variable dimensions
        Parameters:
        toShuffle - the ndarray to shuffle
        dimensions - the dimension to do the shuffle. Please note - order matters here.
      • getDistributions

        public static DistributionFactory getDistributions()
        Get the primary distributions factory
        Returns:
        the primary distributions
      • getRandom

        public static Random getRandom()
        Get the current random generator
        Returns:
        the current random generator
      • getRandomFactory

        public static RandomFactory getRandomFactory()
        Get the RandomFactory instance
        Returns:
        the RandomFactory instance
      • getConvolution

        public static ConvolutionInstance getConvolution()
        Get the convolution singleton
        Returns:
        the convolution singleton
      • setConvolution

        public static void setConvolution​(ConvolutionInstance convolutionInstance)
        Set a convolution instance
        Parameters:
        convolutionInstance - the new convolution instance
      • shape

        public static long[] shape​(INDArray arr)
        Returns the shape of the ndarray
        Parameters:
        arr - the array to get the shape of
        Returns:
        the shape of tihs ndarray
      • create

        public static INDArray create​(int[] sliceShape,
                                      float[]... arrays)
        Create an ndarray based on the given data
        Parameters:
        sliceShape - the shape of each slice
        arrays - the arrays of data to create
        Returns:
        the ndarray of the specified shape where number of slices is equal to array length and each slice is the specified shape
      • create

        public static INDArray create​(LongShapeDescriptor descriptor,
                                      boolean initialize)
        Create an ndarray based on the given description,
        Parameters:
        descriptor - object with data for array creation.
        initialize - true/false creates initialized/uninitialized array.
        Returns:
        the ndarray of the specified description.
      • getEnvironment

        public static Environment getEnvironment()
        Get the backend Environment instance
        Returns:
        The backend Environment instance
      • getExecutioner

        public static OpExecutioner getExecutioner()
        Get the operation executioner instance.
        Returns:
        the operation executioner instance.
      • getDataBufferFactory

        public static DataBufferFactory getDataBufferFactory()
        Get the data buffer factory instance.
        Returns:
        the data buffer factory instance.
      • rollAxis

        public static INDArray rollAxis​(INDArray a,
                                        int axis)
        Roll the specified axis backwards, until it lies in a given position. Starting ends up being zero. See numpy's rollaxis
        Parameters:
        a - the array to roll
        axis - the axis to roll backwards
        Returns:
        the rolled ndarray
      • argMax

        public static INDArray argMax​(INDArray arr,
                                      @NonNull
                                      @lombok.NonNull int... dimension)
        Get the maximum values for a dimension.
        Parameters:
        arr - input array.
        dimension - the dimension along which to get the maximum
        Returns:
        array of maximum values.
      • rollAxis

        public static INDArray rollAxis​(INDArray a,
                                        int axis,
                                        int start)
        Roll the specified axis backwards, until it lies in a given position. See numpy's rollaxis
        Parameters:
        a - the array to roll
        axis - the axis to roll backwards
        start - the starting point
        Returns:
        the rolled ndarray
      • tensorMmul

        public static INDArray tensorMmul​(INDArray a,
                                          INDArray b,
                                          INDArray result,
                                          int[][] axes)
        Tensor matrix multiplication. Both tensors must be the same rank
        Parameters:
        a - the left tensor
        b - the right tensor
        result - the result array
        axes - the axes for each array to do matrix multiply along
        Returns:
        the result array
      • tensorMmul

        public static INDArray tensorMmul​(INDArray a,
                                          INDArray b,
                                          int[][] axes)
        Tensor matrix multiplication. Both tensors must be the same rank
        Parameters:
        a - the left tensor
        b - the right tensor
        axes - the axes for each array to do matrix multiply along
        Returns:
        the multiplication result.
      • gemm

        public static INDArray gemm​(INDArray a,
                                    INDArray b,
                                    boolean transposeA,
                                    boolean transposeB)
        matrix multiply: implements op(a)*op(b) where op(x) means transpose x (or not) depending on setting of arguments transposea and transposeb.
        so gemm(a,b,false,false) == a.mmul(b), gemm(a,b,true,false) == a.transpose().mmul(b) etc.
        Parameters:
        a - first matrix
        b - second matrix
        transposeA - if true: transpose matrix a before mmul
        transposeB - if true: transpose matrix b before mmul
        Returns:
        result
      • gemm

        public static INDArray gemm​(INDArray a,
                                    INDArray b,
                                    INDArray c,
                                    boolean transposeA,
                                    boolean transposeB,
                                    double alpha,
                                    double beta)
        Matrix multiply: Implements c = alpha*op(a)*op(b) + beta*c where op(X) means transpose X (or not) depending on setting of arguments transposeA and transposeB.
        Note that matrix c MUST be fortran order, have zero offset and have c.data().length == c.length(). i.e., the result array must not be a view. An exception will be thrown otherwise.
        (Note: some views are allowed, if and only if they have f order and are contiguous in the buffer other than an offset. Put another way, they must be f order and have strides identical to a non-view/default array of the same shape)
        Don't use this unless you know about level 3 blas and NDArray storage orders.
        Parameters:
        a - First matrix
        b - Second matrix
        c - result matrix. Used in calculation (assuming beta != 0) and result is stored in this. f order, and not a view only
        transposeA - if true: transpose matrix a before mmul
        transposeB - if true: transpose matrix b before mmul
        Returns:
        result, i.e., matrix c is returned for convenience
      • matmul

        public static INDArray matmul​(INDArray a,
                                      INDArray b,
                                      INDArray result,
                                      boolean transposeA,
                                      boolean transposeB,
                                      boolean transposeResult)
        Matrix multiplication/dot product Depending on inputs dimensionality output result might be different. matrix x matrix = BLAS gemm vector x matrix = BLAS gemm vector x vector = BLAS dot vector x scalar = element-wise mul scalar x vector = element-wise mul tensor x tensor = matrix multiplication using the last two dimensions Transpose operations only available where applicable. In the tensor x tensor case it will be applied only to the last two dimensions.
        Parameters:
        a - First tensor
        b - Second tensor
        result - result matrix.
        transposeA - if true: transpose matrix a before mmul
        transposeB - if true: transpose matrix b before mmul
        transposeResult - if true: result matrix will be transposed
        Returns:
        result, i.e., result matrix is returned for convenience
      • factory

        public static NDArrayFactory factory()
        The factory used for creating ndarrays
        Returns:
        the factory instance used for creating ndarrays
      • createBuffer

        public static DataBuffer createBuffer​(DataBuffer underlyingBuffer,
                                              long offset,
                                              long length)
        Create a view of a data buffer Leverages the underlying storage of the buffer with a new view
        Parameters:
        underlyingBuffer - the underlying buffer
        offset - the offset for the view
        Returns:
        the new view of the data buffer
      • createBuffer

        public static DataBuffer createBuffer​(int[] shape,
                                              DataType type,
                                              long offset)
        Create a buffer equal of length prod(shape)
        Parameters:
        shape - the shape of the buffer to create
        type - the opType to create
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(ByteBuffer buffer,
                                              DataType type,
                                              int length,
                                              long offset)
        Creates a buffer of the specified opType and length with the given byte buffer. This will wrap the buffer as a reference (no copy) if the allocation opType is the same.
        Parameters:
        buffer - the buffer to create from
        type - the opType of buffer to create
        length - the length of the buffer
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(byte[] data,
                                              int length,
                                              long offset)
        Create a buffer based on the data opType
        Parameters:
        data - the data to create the buffer with
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(int length,
                                              long offset)
        Creates a buffer of the specified length based on the data opType
        Parameters:
        length - the length of te buffer
        Returns:
        the buffer to create
      • createBuffer

        public static DataBuffer createBuffer​(@NonNull
                                              @NonNull org.bytedeco.javacpp.Pointer pointer,
                                              long length,
                                              @NonNull
                                              @NonNull DataType dataType)
        Creates a buffer of the specified type and length with the given pointer.
        Parameters:
        pointer - pointer to data to create from.
        length - the length of the buffer
        dataType - the opType of buffer to create,
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(@NonNull
                                              @NonNull org.bytedeco.javacpp.Pointer pointer,
                                              @NonNull
                                              @NonNull org.bytedeco.javacpp.Pointer devicePointer,
                                              long length,
                                              @NonNull
                                              @NonNull DataType dataType)
        Creates a buffer of the specified type and length with the given pointer at the specified device. (This method is relevant only for a CUDA backend).
        Parameters:
        pointer - pointer to data to create from.
        devicePointer - pointer to device to create in (only implemented in the CUDA backend)
        length - the length of the buffer
        dataType - the opType of buffer to create,
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(float[] data,
                                              long offset)
        Create a buffer based on the data opType
        Parameters:
        data - the data to create the buffer with
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(double[] data,
                                              long offset)
        Create a buffer based on the data opType
        Parameters:
        data - the data to create the buffer with
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(@NonNull
                                              @lombok.NonNull int[] shape,
                                              @NonNull
                                              @NonNull DataType type)
        Create a buffer equal of length prod(shape)
        Parameters:
        shape - the shape of the buffer to create
        type - the opType to create
        Returns:
        the created buffer
      • createBufferDetached

        public static DataBuffer createBufferDetached​(int[] shape,
                                                      DataType type)
        Create a buffer equal of length prod(shape). The buffer is 'detached': Not in any memory workspace even if a workspace is currently open.
        Parameters:
        shape - the shape of the buffer to create
        type - the opType to create
        Returns:
        the created buffer.
      • createBuffer

        public static DataBuffer createBuffer​(ByteBuffer buffer,
                                              DataType type,
                                              int length)
        Creates a buffer of the specified opType and length with the given byte buffer. This will wrap the buffer as a reference (no copy) if the allocation opType is the same.
        Parameters:
        buffer - the buffer to create from
        type - the opType of buffer to create
        length - the length of the buffer
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(int[] data)
        Create a buffer equal of length prod(shape)
        Parameters:
        data - the shape of the buffer to create
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(long[] data)
        Create a buffer equal of length prod(shape)
        Parameters:
        data - the shape of the buffer to create
        Returns:
        the created buffer
      • createBufferDetached

        public static DataBuffer createBufferDetached​(int[] data)
        Create a buffer equal of length prod(shape). This method is NOT affected by workspaces
        Parameters:
        data - the shape of the buffer to create
        Returns:
        the created buffer
      • createBufferDetached

        public static DataBuffer createBufferDetached​(long[] data)
        Create a buffer equal of length prod(shape). This method is NOT affected by workspaces
        Parameters:
        data - the shape of the buffer to create
        Returns:
        the created buffer
      • createBuffer

        public static DataBuffer createBuffer​(long length)
        Creates a buffer of the specified length based on the data opType
        Parameters:
        length - the length of te buffer
        Returns:
        the buffer to create
      • createBuffer

        public static DataBuffer createBuffer​(org.bytedeco.javacpp.Pointer pointer,
                                              DataType type,
                                              long length,
                                              org.bytedeco.javacpp.indexer.Indexer indexer)
        Create a data buffer based on a pointer with the given opType and length
        Parameters:
        pointer - the pointer to create the buffer for
        type - the opType of pointer
        length - the length of the buffer
        indexer - the indexer to use
        Returns:
        the data buffer based on the given parameters
      • createBuffer

        public static DataBuffer createBuffer​(DataType dataType,
                                              long length,
                                              boolean initialize)
        Create a data buffer based on datatype.
        Parameters:
        dataType - the type of buffer to create
        length - the length of the buffer
        initialize - flag to leave the underlying memory (false) or initialize with zero (true).
        Returns:
        the created buffer.
      • createBuffer

        public static DataBuffer createBuffer​(DataType dataType,
                                              long length,
                                              boolean initialize,
                                              MemoryWorkspace workspace)
        Create a data buffer based on datatype, workspace.
        Parameters:
        dataType - the type of buffer to create
        length - the length of the buffer
        initialize - flag to leave the underlying memory (false) or initialize with zero (true).
        workspace - workspace to use for buffer creation.
        Returns:
        the created buffer.
      • createBuffer

        public static DataBuffer createBuffer​(float[] data)
        Create a buffer based on the data opType
        Parameters:
        data - the data to create the buffer with
        Returns:
        the created buffer
      • createBufferDetached

        public static DataBuffer createBufferDetached​(float[] data)
        Create a buffer based on underlying array.
        Parameters:
        data - data to create the buffer with
        Returns:
        the created buffer
      • createTypedBuffer

        public static DataBuffer createTypedBuffer​(double[] data,
                                                   DataType dataType)
        Create a buffer based on the data of the underlying java array with the specified type..
        Parameters:
        data - underlying java array
        dataType - specified type.
        Returns:
        created buffer,
      • createTypedBuffer

        public static DataBuffer createTypedBuffer​(double[] data,
                                                   DataType dataType,
                                                   MemoryWorkspace workspace)
        Create a buffer based on the data of the underlying java array, specified type and workspace
        Parameters:
        data - underlying java array
        dataType - specified type.
        workspace - specified workspace.
        Returns:
        created buffer,
      • createTypedBufferDetached

        public static DataBuffer createTypedBufferDetached​(double[] data,
                                                           DataType dataType)
        Create am uninitialized buffer based on the data of the underlying java array and specified type.
        Parameters:
        data - underlying java array
        dataType - specified type.
        Returns:
        the created buffer.
      • setFactory

        public static void setFactory​(NDArrayFactory factory)
        Set the factory instance for INDArray creation.
        Parameters:
        factory - new INDArray factory
      • order

        public static Character order()
        Returns the ordering of the ndarrays
        Returns:
        the ordering of the ndarrays
      • dataType

        public static DataType dataType()
        Returns the data opType used for the runtime
        Returns:
        the datatype used for the runtime
      • setDefaultDataTypes

        public static void setDefaultDataTypes​(@NonNull
                                               @NonNull DataType defaultType,
                                               @NonNull
                                               @NonNull DataType defaultFloatingPointType)
        Set the default data types.
        The default data types are used for array creation methods where no data type is specified.
        When the user explicitly provides a datatype (such as in Nd4j.ones(DataType.FLOAT, 1, 10)) these default values will not be used.
        defaultType: used in methods such as Nd4j.ones(1,10) and Nd4j.zeros(10).
        defaultFloatingPointType: used internally where a floating point array needs to be created, but no datatype is specified. defaultFloatingPointType must be one of DOUBLE, FLOAT or HALF
        Parameters:
        defaultType - Default datatype for new arrays (used when no type is specified).
        defaultFloatingPointType - Default datatype for new floating point arrays (used when no type is specified. Must be one of DOUBLE, FLOAT or HALF
      • getBackend

        public static Nd4jBackend getBackend()
        Retrieve the Nd4J backend.
        Returns:
        the Nd4J backend.
      • getBlasWrapper

        public static BlasWrapper getBlasWrapper()
        Retrieve the BLAS wrapper.
        Returns:
        the BLAS wrapper.
      • sortWithIndices

        public static INDArray[] sortWithIndices​(INDArray ndarray,
                                                 int dimension,
                                                 boolean ascending)
        Sort an ndarray along a particular dimension.
        Note that the input array is modified in-place.
        Parameters:
        ndarray - the ndarray to sort
        dimension - the dimension to sort
        Returns:
        the indices and the sorted ndarray (the original array, modified in-place)
      • sort

        public static INDArray sort​(INDArray ndarray,
                                    boolean ascending)
        Sort all elements of an array. sorts all elements of an array. For multi dimansional arrays the result depends on the array ordering] Nd4j.factory().setOrder('f'); INDArray x = Nd4j.arange(4).reshape(2,2); Nd4j.sort(x, true); gives: [[ 0, 2.0000], [ 1.0000, 3.0000]] The same ode with .setOrder('c') [[ 0, 1.0000], [ 2.0000, 3.0000]]
        Parameters:
        ndarray - array to sort
        ascending - true for ascending, false for descending
        Returns:
        the sorted ndarray
      • sort

        public static INDArray sort​(INDArray ndarray,
                                    int dimension,
                                    boolean ascending)
        Sort an ndarray along a particular dimension
        Note that the input array is modified in-place.
        Parameters:
        ndarray - the ndarray to sort
        dimension - the dimension to sort
        Returns:
        the sorted ndarray
      • sortRows

        public static INDArray sortRows​(INDArray in,
                                        int colIdx,
                                        boolean ascending)
        Sort (shuffle) the rows of a 2d array according to the value at a specified column. Other than the order of the rows, each row is unmodified. Copy operation: original INDArray is unmodified
        So if sorting the following on values of column 2 (ascending):
        [a b 2]
        [c d 0]
        [e f -3]
        Then output is
        [e f -3]
        [c d 0]
        [a b 2]
        Parameters:
        in - 2d array to sort
        colIdx - The column to sort on
        ascending - true if smallest-to-largest; false if largest-to-smallest
        Returns:
        the sorted ndarray
      • sortColumns

        public static INDArray sortColumns​(INDArray in,
                                           int rowIdx,
                                           boolean ascending)
        Sort (shuffle) the columns of a 2d array according to the value at a specified row. Other than the order of the columns, each column is unmodified. Copy operation: original INDArray is unmodified
        So if sorting the following on values of row 1 (ascending):
        [a b c]
        [1 -1 0]
        [d e f]
        Then output is
        [b c a]
        [-1 0 1]
        [e f d]
        Parameters:
        in - 2d array to sort
        rowIdx - The row to sort on
        ascending - true if smallest-to-largest; false if largest-to-smallest
        Returns:
        the sorted array.
      • repeat

        public static INDArray repeat​(INDArray n,
                                      int num)
        Create an n x (shape) ndarray where the ndarray is repeated num times
        Parameters:
        n - the ndarray to replicate
        num - the number of copies to repeat
        Returns:
        the repeated ndarray
      • linspace

        public static INDArray linspace​(@NonNull
                                        @NonNull DataType dtype,
                                        long lower,
                                        long num,
                                        long step)
        Generate a linearly spaced vector
        Parameters:
        lower - upper bound
        num - number of items in returned vector
        step - the step (incompatible with upper)
        Returns:
        the linearly spaced vector
      • linspace

        public static INDArray linspace​(long lower,
                                        long upper,
                                        long num)
        Generate a linearly spaced vector with default data type
        Parameters:
        lower - lower bound
        upper - upper bound
        num - number of items in returned vector
        Returns:
        the linearly spaced vector
      • linspace

        public static INDArray linspace​(long lower,
                                        long upper,
                                        long num,
                                        @NonNull
                                        @NonNull DataType dtype)
        Generate a linearly spaced vector
        Parameters:
        lower - lower bound
        upper - upper bound
        num - number of items in returned vector
        Returns:
        the linearly spaced vector
      • linspace

        public static INDArray linspace​(@NonNull
                                        @NonNull DataType dataType,
                                        double lower,
                                        double step,
                                        long num)
        Generate a linearly spaced 1d vector of the specified datatype
        Parameters:
        lower - lower bound
        step - step between items
        num - number of resulting items
        Returns:
        the linearly spaced vector
      • linspace

        public static INDArray linspace​(double lower,
                                        double upper,
                                        long num,
                                        @NonNull
                                        @NonNull DataType dataType)
        Generate a linearly spaced 1d vector of the specified datatype
        Parameters:
        lower - lower bound
        upper - upper bound
        num - number of resulting items
        Returns:
        the linearly spaced vector
      • meshgrid

        public static INDArray[] meshgrid​(@NonNull
                                          @NonNull INDArray x,
                                          @NonNull
                                          @NonNull INDArray y)
        Meshgrid op. Returns a pair of arrays where values are broadcast on a 2d grid.
        For example, if x = [1,2,3,4] and y = [5,6,7], then:
        out[0] =
        [1,2,3,4]
        [1,2,3,4]
        [1,2,3,4]

        out[1] =
        [5,5,5,5]
        [6,6,6,6]
        [7,7,7,7]

        Parameters:
        x - X array input
        y - Y array input
        Returns:
        INDArray[] of length 2, shape [y.length, x.length]
      • toFlattened

        public static INDArray toFlattened​(Collection<INDArray> matrices)
        Create a long row vector of all of the given ndarrays
        Parameters:
        matrices - the matrices to create the flattened ndarray for
        Returns:
        the flattened representation of these ndarrays
      • toFlattened

        public static INDArray toFlattened​(char order,
                                           Collection<INDArray> matrices)
        Create a long row vector of all of the given ndarrays
        Parameters:
        order - the order in which to flatten the matrices
        matrices - the matrices to create the flattened ndarray for
        Returns:
        the flattened representation of these ndarrays
      • toFlattened

        public static INDArray toFlattened​(@NonNull
                                           @NonNull INDArray... matrices)
        Create a long row vector of all of the given ndarrays
        Parameters:
        matrices - the matrices to create the flattened ndarray for
        Returns:
        the flattened representation of these ndarrays
      • toFlattened

        public static INDArray toFlattened​(char order,
                                           @NonNull
                                           @NonNull INDArray... matrices)
        Create a long row vector of all of the given ndarrays/
        Parameters:
        order - order in which to flatten ndarrays
        matrices - the matrices to create the flattened ndarray for
        Returns:
        the flattened representation of these ndarrays
      • eye

        public static INDArray eye​(long n)
        Create the identity ndarray
        Parameters:
        n - the number for the identity
        Returns:
        the identity array
      • rot90

        public static void rot90​(INDArray toRotate)
        Rotate a matrix 90 degrees
        Parameters:
        toRotate - the matrix to rotate
      • writeTxt

        public static void writeTxt​(INDArray write,
                                    String filePath,
                                    String split,
                                    int precision)
        Deprecated.
        Precision is no longer used. Split is no longer used. Defaults to scientific notation with 18 digits after the decimal Use writeTxt(INDArray, String)
        Write NDArray to a text file
        Parameters:
        filePath - path to write to
        split - the split separator, defaults to ","
        precision - digits after the decimal point
      • writeTxt

        public static void writeTxt​(INDArray write,
                                    String filePath,
                                    int precision)
        Deprecated.
        Defaults to scientific notation with 18 digits after the decimal Use writeTxt(INDArray, String)
        Write NDArray to a text file
        Parameters:
        write - array to write
        filePath - path to write to
        precision - Precision is no longer used.
      • writeTxt

        public static void writeTxt​(INDArray write,
                                    String filePath,
                                    String split)
        Deprecated.
        custom col and higher dimension separators are no longer supported; uses "," Use writeTxt(INDArray, String)
        Write NDArray to a text file
        Parameters:
        write - array to write
        filePath - path to write to
        split - the split separator, defaults to ","
      • writeTxt

        public static void writeTxt​(INDArray write,
                                    String filePath)
        Write NDArray to a text file
        Parameters:
        write - Array to write
        filePath - path to write to
      • write

        public static void write​(OutputStream writer,
                                 INDArray write)
                          throws IOException
        Y Write an ndarray to a writer
        Parameters:
        writer - the writer to write to
        write - the ndarray to write
        Throws:
        IOException
      • toByteArray

        public static byte[] toByteArray​(@NonNull
                                         @NonNull INDArray arr)
                                  throws IOException
        Convert an ndarray to a byte array
        Parameters:
        arr - the array to convert
        Returns:
        the converted byte array
        Throws:
        IOException
      • fromByteArray

        public static INDArray fromByteArray​(@NonNull
                                             @lombok.NonNull byte[] arr)
        Read an ndarray from a byte array
        Parameters:
        arr - the array to read from
        Returns:
        the deserialized ndarray
      • readNumpy

        public static INDArray readNumpy​(@NonNull
                                         @NonNull InputStream filePath,
                                         @NonNull
                                         @NonNull String split)
                                  throws IOException
        Read line via input streams
        Parameters:
        filePath - the input stream ndarray
        split - the split separator
        Returns:
        the read txt method
        Throws:
        IOException
      • readNumpy

        public static INDArray readNumpy​(@NonNull
                                         @NonNull DataType dataType,
                                         @NonNull
                                         @NonNull InputStream filePath,
                                         @NonNull
                                         @NonNull String split,
                                         @NonNull
                                         @NonNull Charset charset)
                                  throws IOException
        Read array from input stream.
        Parameters:
        dataType - datatype of array
        filePath - the input stream
        split - the split separator
        charset - the charset
        Returns:
        the deserialized array.
        Throws:
        IOException
      • readNumpy

        public static INDArray readNumpy​(String filePath,
                                         String split)
                                  throws IOException
        Read line via input streams
        Parameters:
        filePath - the input stream ndarray
        split - the split separator
        Returns:
        the read txt method
        Throws:
        IOException
      • readNumpy

        public static INDArray readNumpy​(String filePath)
                                  throws IOException
        Read line via input streams
        Parameters:
        filePath - the input stream ndarray
        Returns:
        the read txt method
        Throws:
        IOException
      • readTxtString

        @Deprecated
        public static INDArray readTxtString​(InputStream ndarray)
        Deprecated.
        To be removed in 1.0
        Read line via input streams
        Parameters:
        ndarray - the input stream ndarray
        Returns:
        NDArray
      • readTxt

        @Deprecated
        public static INDArray readTxt​(String filePath)
        Deprecated.
        to be removed in 1.0
        Read line via input streams
        Parameters:
        filePath - the input stream ndarray
        Returns:
        NDArray
      • createArrayFromShapeBuffer

        public static INDArray createArrayFromShapeBuffer​(DataBuffer data,
                                                          DataBuffer shapeInfo)
        Create array based in data buffer and shape info,
        Parameters:
        data - Data buffer.
        shapeInfo - shape information.
        Returns:
        new INDArray.
      • createArrayFromShapeBuffer

        public static INDArray createArrayFromShapeBuffer​(DataBuffer data,
                                                          Pair<DataBuffer,​long[]> shapeInfo)
        Create array based in data buffer and shape info,
        Parameters:
        data - data buffer.
        shapeInfo - shape information.
        Returns:
        new INDArray.
      • read

        public static INDArray read​(DataInputStream dis)
        Read in an ndarray from a data input stream
        Parameters:
        dis - the data input stream to read from
        Returns:
        the ndarray
      • write

        public static void write​(INDArray arr,
                                 DataOutputStream dataOutputStream)
                          throws IOException
        Write an ndarray to the specified outputstream
        Parameters:
        arr - the array to write
        dataOutputStream - the data output stream to write to
        Throws:
        IOException
      • saveBinary

        public static void saveBinary​(INDArray arr,
                                      File saveTo)
                               throws IOException
        Save an ndarray to the given file
        Parameters:
        arr - the array to save
        saveTo - the file to save to
        Throws:
        IOException
      • readBinary

        public static INDArray readBinary​(File read)
                                   throws IOException
        Read a binary ndarray from the given file
        Parameters:
        read - the nd array to read
        Returns:
        the loaded ndarray
        Throws:
        IOException
      • clearNans

        public static void clearNans​(INDArray arr)
        Clear nans from an ndarray
        Parameters:
        arr - the array to clear
      • reverse

        public static INDArray reverse​(INDArray reverse)
        Reverses the passed in matrix such that m[0] becomes m[m.length - 1] etc
        Parameters:
        reverse - the matrix to reverse
        Returns:
        the reversed matrix
      • arange

        public static INDArray arange​(double begin,
                                      double end,
                                      double step)
        Create a 1D array of evenly spaced values between begin (inclusive) and end (exclusive) with a step size.
        Parameters:
        begin - the begin of the range (inclusive)
        end - the end of the range (exclusive)
        step - spacing between values. Default value is 1.
        Returns:
        the 1D range vector
      • arange

        public static INDArray arange​(double begin,
                                      double end)
        Create a 1D array of evenly spaced values between begin (inclusive) and end (exclusive) with a step size of 1 See arange(double, double, double) with step size 1.
      • arange

        public static INDArray arange​(double end)
        Create a 1D array of evenly spaced values between 0 (inclusive) and end (exclusive) with a step size of 1 See arange(double, double, double) with begin = 0 and step size 1.
      • copy

        public static void copy​(INDArray a,
                                INDArray b)
        Copy a to b
        Parameters:
        a - the origin matrix
        b - the destination matrix
      • diag

        public static INDArray diag​(INDArray x)
        Creates a new matrix where the values of the given vector are the diagonal values of the matrix if a vector is passed in, if a matrix is returns the kth diagonal in the matrix
        Parameters:
        x - the diagonal values
        Returns:
        new matrix
      • choice

        public static INDArray choice​(@NonNull
                                      @NonNull INDArray source,
                                      @NonNull
                                      @NonNull INDArray probs,
                                      @NonNull
                                      @NonNull INDArray target,
                                      @NonNull
                                      Random rng)
        This method samples value from Source array to Target, with probabilites provided in Probs argument
        Parameters:
        source - source array.
        probs - array with probabilities.
        target - destination array.
        rng - Random number generator.
        Returns:
        the destination (target) array.
      • appendBias

        public static INDArray appendBias​(@NonNull
                                          @NonNull INDArray... vectors)
      • rand

        public static INDArray rand​(@NonNull
                                    @lombok.NonNull int... shape)
        Create a random ndarray with values from a uniform distribution over (0, 1) with the given shape
        Parameters:
        shape - the shape of the array
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(@NonNull
                                    @lombok.NonNull long... shape)
      • rand

        public static INDArray rand​(@NonNull
                                    @NonNull DataType dataType,
                                    @NonNull
                                    @lombok.NonNull long... shape)
        Create a random ndarray with values from a uniform distribution over (0, 1) with the given shape and data type
        Parameters:
        shape - the shape of the ndarray
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(char order,
                                    @NonNull
                                    @lombok.NonNull int... shape)
        Create a random ndarray with the given shape and array order Values are sampled from a uniform distribution over (0, 1)
        Parameters:
        order - the order of the ndarray to return
        shape - the shape of the array
        Returns:
        the random ndarray with the specified shape
      • rand

        @Deprecated
        public static INDArray rand​(@NonNull
                                    @NonNull DataType dataType,
                                    int[] shape,
                                    char order)
        Deprecated.
        use {@link Nd4j#rand(DataType, char, long...))
      • rand

        public static INDArray rand​(@NonNull
                                    @NonNull DataType dataType,
                                    char order,
                                    @NonNull
                                    @lombok.NonNull long... shape)
        Create a random ndarray with the given shape, data type, and array order Values are sampled from a uniform distribution over (0, 1)
        Parameters:
        order - the order of the ndarray to return
        shape - the shape of the ndarray
        dataType - the data type of the ndarray
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(@NonNull
                                    @NonNull DataType dataType,
                                    @NonNull
                                    @lombok.NonNull int... shape)
        Create a random ndarray with the given shape and data type Values are sampled from a uniform distribution over (0, 1)
        Parameters:
        shape - the shape of the ndarray
        dataType - the data type of the ndarray
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(long seed,
                                    @NonNull
                                    @lombok.NonNull long... shape)
        Create a random ndarray with values from a uniform distribution over (0, 1) with the given shape using given seed
        Parameters:
        shape - the shape of the array
        seed - the seed to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(@NonNull
                                    Random rng,
                                    @NonNull
                                    @lombok.NonNull long... shape)
        Create a random ndarray with the given shape using the given RandomGenerator
        Parameters:
        shape - the shape of the array
        rng - the random generator to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(@NonNull
                                    @NonNull Distribution dist,
                                    @NonNull
                                    @lombok.NonNull long... shape)
        Create a random ndarray with the given shape using the given rng
        Parameters:
        shape - the shape of the array
        dist - distribution to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(int rows,
                                    int columns,
                                    @NonNull
                                    Random rng)
        Create a random ndarray with the given shape using the given rng
        Parameters:
        rows - the number of rows in the matrix
        columns - the number of columns in the matrix
        rng - the random generator to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(double min,
                                    double max,
                                    @NonNull
                                    Random rng,
                                    @NonNull
                                    @lombok.NonNull long... shape)
        Generates a random matrix between min and max
        Parameters:
        shape - the number of rows of the matrix
        min - the minimum number
        max - the maximum number
        rng - the rng to use
        Returns:
        a random matrix of the specified shape and range
      • randn

        public static INDArray randn​(INDArray target)
        Fill the given ndarray with random numbers drawn from a normal distribution
        Parameters:
        target - target array
        Returns:
        the given target array
      • randn

        public static INDArray randn​(@NonNull
                                     @lombok.NonNull int[] shape)
        Create a ndarray of the given shape with values from N(0,1)
        Parameters:
        shape - the shape of the array
        Returns:
        new array with random values
      • randn

        public static INDArray randn​(@NonNull
                                     @NonNull DataType dataType,
                                     @NonNull
                                     @lombok.NonNull int[] shape)
        Create a ndarray of the given shape and data type with values from N(0,1)
        Parameters:
        shape - the shape of the ndarray
        Returns:
        new array with random values
      • randn

        public static INDArray randn​(@NonNull
                                     @NonNull DataType dataType,
                                     @NonNull
                                     @lombok.NonNull long... shape)
        Create a ndarray of the given shape and data type with values from N(0,1)
        Parameters:
        dataType - datatype to use, must be a float type datatype.
        shape - shape for the new array.
        Returns:
        new array with random values
      • randn

        public static INDArray randn​(@NonNull
                                     @lombok.NonNull long... shape)
        Create a ndarray of the given shape with values from N(0,1). Defaults to FLOAT and c-order.
        Parameters:
        shape - shape for the new array.
        Returns:
        new array with random values
      • randn

        public static INDArray randn​(char order,
                                     @NonNull
                                     @lombok.NonNull int... shape)
        Random normal N(0,1) with the specified shape and array order
        Parameters:
        order - order of the output ndarray
        shape - the shape of the array
        Returns:
        new array with random values
      • randn

        public static INDArray randn​(char order,
                                     @NonNull
                                     @lombok.NonNull long... shape)
        Random normal N(0,1) with the specified shape and array order
        Parameters:
        order - order of the output ndarray
        shape - the shape of the array
        Returns:
        new array with random values
      • randn

        public static INDArray randn​(@NonNull
                                     @NonNull DataType dataType,
                                     char order,
                                     @NonNull
                                     @lombok.NonNull long... shape)
        Random normal N(0,1) with the specified shape and array order
        Parameters:
        order - order of the output ndarray
        shape - the shape of the ndarray
        dataType - the data type of the ndarray
      • randn

        public static INDArray randn​(long seed,
                                     @NonNull
                                     @lombok.NonNull long[] shape)
        Random normal N(0, 1) using the specified seed
        Parameters:
        shape - the shape of the array
        Returns:
        new array with random values
      • randn

        public static INDArray randn​(@NonNull
                                     Random r,
                                     @NonNull
                                     @lombok.NonNull long... shape)
        Random normal using the given rng
        Parameters:
        shape - the shape of the array
        r - the random generator to use
        Returns:
        new array with random values
      • randn

        public static INDArray randn​(double mean,
                                     double stddev,
                                     INDArray target,
                                     @NonNull
                                     Random rng)
      • randn

        public static INDArray randn​(double mean,
                                     double stddev,
                                     long[] shape,
                                     @NonNull
                                     Random rng)
      • rand

        public static INDArray rand​(INDArray target)
        Fill the given ndarray with random numbers drawn from a uniform distribution
        Parameters:
        target - target array
        Returns:
        the given target array
      • rand

        public static INDArray rand​(INDArray target,
                                    long seed)
        Fill the given ndarray with random numbers drawn from a uniform distribution
        Parameters:
        target - target array
        seed - the seed to use
        Returns:
        the given target array
      • rand

        public static INDArray rand​(INDArray target,
                                    @NonNull
                                    Random rng)
        Fill the given ndarray with random numbers drawn from a uniform distribution using the given RandomGenerator
        Parameters:
        target - target array
        rng - the random generator to use
        Returns:
        the given target array
      • rand

        public static INDArray rand​(INDArray target,
                                    @NonNull
                                    @NonNull Distribution dist)
        Fill the given ndarray with random numbers drawn from the given distribution
        Parameters:
        target - target array
        dist - distribution to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public static INDArray rand​(INDArray target,
                                    double min,
                                    double max,
                                    @NonNull
                                    Random rng)
        Fill the given ndarray with random numbers drawn from a uniform distribution using the given RandomGenerator
        Parameters:
        target - target array
        min - the minimum number
        max - the maximum number
        rng - the random generator to use
        Returns:
        the given target array
      • randn

        public static INDArray randn​(INDArray target,
                                     long seed)
        Fill the given ndarray with random numbers drawn from a normal distribution
        Parameters:
        target - target array
        Returns:
        the given target array
      • randn

        public static INDArray randn​(INDArray target,
                                     @NonNull
                                     Random rng)
        Fill the given ndarray with random numbers drawn from a normal distribution utilizing the given random generator
        Parameters:
        target - target array
        rng - the random generator to use
        Returns:
        the given target array
      • randomBernoulli

        public static INDArray randomBernoulli​(double p,
                                               @NonNull
                                               @lombok.NonNull long... shape)
        Generate a random array according to a binomial distribution with probability p: i.e., values 0 with probability (1-p) or value 1 with probability p
        Parameters:
        p - Probability. Must be in range 0 to 1
        shape - Shape of the result array
        Returns:
        Result array
      • randomBernoulli

        public static INDArray randomBernoulli​(double p,
                                               @NonNull
                                               @NonNull INDArray target)
        Fill the specified array with values generated according to a binomial distribution with probability p: i.e., values 0 with probability (1-p) or value 1 with probability p
        Parameters:
        p - Probability. Must be in range 0 to 1
        target - Result array to place generated values in
        Returns:
        Result array
      • randomBinomial

        public static INDArray randomBinomial​(int nTrials,
                                              double p,
                                              @NonNull
                                              @lombok.NonNull long... shape)
        Generate an array with random values generated according to a binomial distribution with the specified number of trials and probability
        Parameters:
        nTrials - Number of trials. Must be >= 0
        p - Probability. Must be in range 0 to 1
        shape - Shape of the result array
        Returns:
        Result array
      • randomBinomial

        public static INDArray randomBinomial​(int nTrials,
                                              double p,
                                              INDArray target)
        Fill the target array with random values generated according to a binomial distribution with the specified number of trials and probability
        Parameters:
        nTrials - Number of trials. Must be >= 0
        p - Probability. Must be in range 0 to 1
        target - Result array
        Returns:
        Result array
      • randomExponential

        public static INDArray randomExponential​(double lambda,
                                                 long... shape)
        Exponential distribution: P(x) = lambda * exp(-lambda * x)
        Parameters:
        lambda - Must be > 0
        shape - Shape of the array to generate
      • randomExponential

        public static INDArray randomExponential​(double lambda,
                                                 INDArray target)
        Exponential distribution: P(x) = lambda * exp(-lambda * x)
        Parameters:
        lambda - Must be > 0
        target - Array to hold the result
      • create

        public static INDArray create​(float[] data)
        Creates a row vector with the data
        Parameters:
        data - the columns of the ndarray
        Returns:
        the created ndarray
      • create

        public static INDArray create​(boolean[] data)
        Create a vector based on a java boolean array.
        Parameters:
        data - java boolean array
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(List<? extends Number> list)
        Creates a row vector with the data
        Parameters:
        list - the columns of the ndarray
        Returns:
        the created ndarray
      • create

        public static INDArray create​(double[] data)
        Create double array based on java double array.
        Parameters:
        data - java double array,
        Returns:
        the created ndarray
      • create

        public static INDArray create​(float[][] data)
        Create 2D float array based on java 2d float array.
        Parameters:
        data - java 2d arrau.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(float[][] data,
                                      char ordering)
        Create 2D float array based on java 2d float array and ordering.
        Parameters:
        data - java 2d arrau.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(double[][] data)
        Create 2D double array based on java 2d double array. and ordering
        Parameters:
        data - the data to use
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(long[][] data)
        Create 2D long array based on java 2d long array.
        Parameters:
        data - java 2d long array
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(boolean[][] data)
        Create 2D boolean array based on java 2d boolean array.
        Parameters:
        data - java 2d boolean array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(boolean[][] data,
                                      @NonNull
                                      @lombok.NonNull long... shape)
        Create a boolean array with given shape based on java 2d boolean array.
        Parameters:
        data - java 2d boolean array.
        shape - desired shape of new array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(double[][][] data)
        Create a 3D double array based on the 3D java double array.
        Parameters:
        data - java 3d double array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(float[][][] data)
        Create a 3D float array based on the 3D java float array.
        Parameters:
        data - java 3d float array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(int[][] data)
        Create 2D double array based on java 2d double array. and ordering
        Parameters:
        data - the data to use
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(int[][][] data)
        create 3D int array based on 3D java int array.
        Parameters:
        data - java 3D i array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(double[][][][] data)
        Create 4D double array based on 4D java double array.
        Parameters:
        data - java 4D double array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(float[][][][] data)
        Create 4D float array based on 4D java float array.
        Parameters:
        data - java 4D float array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(int[][][][] data)
        Create 4D int array based on 4D java int array.
        Parameters:
        data - java 4D int array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(double[][] data,
                                      char ordering)
        Create a 2D double array based on a 2D java double array with given ordering.
        Parameters:
        data - java 2D double array.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray,
      • create

        public static INDArray create​(int columns)
        Creates a row vector with the specified number of columns
        Parameters:
        columns - the columns of the ndarray
        Returns:
        the created ndarray
      • create

        public static INDArray create​(float[] data,
                                      char order)
        Creates a row vector with the data
        Parameters:
        data - the columns of the ndarray
        order - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray
      • create

        public static INDArray create​(double[] data,
                                      char order)
        Creates a row vector with the data
        Parameters:
        data - the columns of the ndarray
        order - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray
      • create

        public static INDArray create​(int columns,
                                      char order)
        Creates a row vector with the specified number of columns
        Parameters:
        columns - the columns of the ndarray
        order - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray
      • zeros

        public static INDArray zeros​(int columns,
                                     char order)
        Create a 1D float array in soecified order initialized with zero.
        Parameters:
        columns - number of elements.
        order - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(int[] data,
                                      long[] shape,
                                      DataType type)
        Create an array of the specified type and shape initialized with values from a java 1d array.
        Parameters:
        data - java array used for initialisation. Must have at least the number of elements required.
        shape - desired shape of new array.
        type - Datatype of the new array. Does not need to match int. data will be converted.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(int[] data,
                                      long[] shape,
                                      long[] strides,
                                      char order,
                                      DataType type)
        Create an array of the specified type, shape and stride initialized with values from a java 1d array.
        Parameters:
        data - java array used for initialisation. Must have at least the number of elements required.
        shape - desired shape of new array.
        strides - stride, separation of elements in each dimension.
        order - Fortran 'f' or C/C++ 'c' ordering.
        type - Datatype of the new array. Does not need to match int. data will be converted.
        Returns:
        the created ndarray.
      • empty

        public static INDArray empty()
        This method creates "empty" INDArray with datatype determined by dataType()
        Returns:
        Empty INDArray
      • empty

        public static INDArray empty​(DataType type)
        This method creates "empty" INDArray of the specified datatype
        Returns:
        Empty INDArray
      • create

        public static INDArray create​(float[] data,
                                      int[] shape)
        Create an ndrray with the specified shape
        Parameters:
        data - the data to use with tne ndarray
        shape - the shape of the array
        Returns:
        the created ndarray
      • create

        public static INDArray create​(double[] data,
                                      int[] shape)
        Create an array of the specified shape initialized with values from a java 1d array.
        Parameters:
        data - the data to use with tne ndarray
        shape - the shape of the array
        Returns:
        the created ndarray
      • create

        public static INDArray create​(double[] data,
                                      int[] shape,
                                      long offset,
                                      char ordering)
        Create an array. Use specified shape and ordering initialized with values from a java 1d array starting at offset.
        Parameters:
        data - java array used for initialisation. Must have at least the number of elements required.
        shape - desired shape of new array.
        offset - the offset of data array used for initialisation.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(float[] data,
                                      int[] shape,
                                      int[] stride,
                                      long offset)
        Create an array of the specified type, shape and stride initialized with values from a java 1d array using offset.
        Parameters:
        data - java array used for initialisation. Must have at least the number of elements required.
        shape - desired shape of new array.
        stride - stride, separation of elements in each dimension.
        offset - the offset of data array used for initialisation.
        Returns:
        the instance
      • create

        public static INDArray create​(List<INDArray> list,
                                      int... shape)
        Creates an array with the specified shape from a list of arrays.
        Parameters:
        list - list of arrays.
        shape - desired shape of new array. Must match the resulting shape of combining the list.
        Returns:
        the instance
      • create

        public static INDArray create​(int rows,
                                      int columns,
                                      int[] stride,
                                      long offset)
        Creates an ndarray with the specified shape
        Parameters:
        rows - the rows of the ndarray
        columns - the columns of the ndarray
        stride - the stride for the ndarray
        offset - the offset of the ndarray
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(int[] shape,
                                      int[] stride,
                                      long offset)
        Creates an ndarray with the specified shape
        Parameters:
        shape - the shape of the ndarray
        stride - the stride for the ndarray
        offset - the offset of the ndarray
        Returns:
        the instance
      • create

        public static INDArray create​(int rows,
                                      int columns,
                                      int[] stride)
        Creates an ndarray with the specified shape
        Parameters:
        rows - the rows of the ndarray
        columns - the columns of the ndarray
        stride - the stride for the ndarray
        Returns:
        the instance
      • zeros

        public static INDArray zeros​(int rows,
                                     int columns,
                                     int[] stride)
        See {@link @see #create(int, int, int[], char)}
      • create

        public static INDArray create​(int[] shape,
                                      int[] stride)
        Creates an ndarray with the specified shape
        Parameters:
        shape - the shape of the ndarray
        stride - the stride for the ndarray
        Returns:
        the instance
      • create

        public static INDArray create​(int... shape)
        Creates an ndarray with the specified shape
        Parameters:
        shape - the shape of the array
        Returns:
        the instance
      • create

        public static INDArray create​(long... shape)
        Creates an ndarray with the specified shape
        Parameters:
        shape - the shape of the array
        Returns:
        the instance
      • create

        public static INDArray create​(DataType type,
                                      long... shape)
        Create an array with specified shape and datatype.
        Parameters:
        type - Datatype of the new array.
        shape - desired shape of new array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(DataBuffer data,
                                      int[] shape,
                                      int[] strides,
                                      long offset)
        Create an array based on the data buffer with given shape, stride and offset.
        Parameters:
        data - data buffer used for initialisation. . Must have at least the number of elements required.
        shape - desired shape of new array.
        strides - stride, separation of elements in each dimension.
        offset - the offset of data array used for initialisation.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(DataBuffer data,
                                      long[] newShape,
                                      long[] newStride,
                                      long offset,
                                      long ews,
                                      char ordering)
        Create an array based on the data buffer with given shape, stride and offset.
        Parameters:
        data - data buffer used for initialisation. . Must have at least the number of elements required.
        newShape - desired shape of new array.
        newStride - stride, separation of elements in each dimension.
        offset - the offset of data array used for initialisation.
        ews - element wise stride.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(DataBuffer data,
                                      long[] newShape,
                                      long[] newStride,
                                      long offset,
                                      char ordering,
                                      DataType dataType)
        Create an array based on the data buffer with given shape, stride, offset and data type.
        Parameters:
        data - data buffer used for initialisation. . Must have at least the number of elements required.
        newShape - desired shape of new array.
        newStride - stride, separation of elements in each dimension.
        offset - the offset of data array used for initialisation.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        dataType - data type.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(DataBuffer data,
                                      int... shape)
        Create an array based on the data buffer with given shape.
        Parameters:
        data - data data buffer used for initialisation. . Must have at least the number of elements required.
        shape - desired shape of new array.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(DataBuffer buffer)
        Create an array based on the data buffer.
        Parameters:
        buffer - data data buffer used for initialisation.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(int[] shape,
                                      DataType dataType)
        Create an array of given shape and data type.
        Parameters:
        shape - desired shape of new array.
        dataType - data type.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(double[] data,
                                      int[] shape,
                                      char ordering)
        Create an array withgiven shape and ordering based on a java double array.
        Parameters:
        data - java array used for initialisation. Must have at least the number of elements required.
        shape - desired shape of new array.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created ndarray.
      • create

        public static INDArray create​(long[] shape,
                                      long[] stride,
                                      long offset,
                                      char ordering)
        Creates an ndarray with the specified shape
        Parameters:
        shape - the shape of the ndarray
        stride - the stride for the ndarray
        offset - the offset of the ndarray
        Returns:
        the instance
      • create

        public static INDArray create​(int rows,
                                      int columns,
                                      int[] stride,
                                      char ordering)
        Create a 2D array with given rows, columns, stride and ordering.
        Parameters:
        rows - number of rows.
        columns - number of columns
        stride - stride, separation of elements in each dimension.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created array.
      • create

        public static INDArray create​(int[] shape,
                                      int[] stride,
                                      char ordering)
        Creates an ndarray with the specified shape
        Parameters:
        shape - the shape of the ndarray
        stride - the stride for the ndarray
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the instance
      • create

        public static INDArray create​(long rows,
                                      long columns,
                                      char ordering)
        Creates an ndarray with the specified shape
        Parameters:
        rows - the rows of the ndarray
        columns - the columns of the ndarray
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the instance
      • zeros

        public static INDArray zeros​(int rows,
                                     int columns,
                                     char ordering)
        Create a 2D array initialized with zeros.
        Parameters:
        rows - the rows of the ndarray
        columns - the columns of the ndarray
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the instance
      • create

        public static INDArray create​(@NonNull
                                      @lombok.NonNull int[] shape,
                                      char ordering)
        Creates an ndarray with the specified shape
        Parameters:
        shape - the shape of the array
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the instance
      • create

        public static INDArray create​(@NonNull
                                      @lombok.NonNull long[] shape,
                                      char ordering)
        Create an array with given shape and ordering.
        Parameters:
        shape - the shape of the array
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created array.
      • create

        public static INDArray create​(DataType dataType,
                                      @NonNull
                                      @lombok.NonNull long[] shape,
                                      long[] strides,
                                      char ordering)
        Create an array with given shape, stride and ordering.
        Parameters:
        dataType - data type.
        shape - the shape of the array
        strides - stride, separation of elements in each dimension.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created array.
      • create

        public static INDArray create​(@NonNull
                                      @NonNull DataType dataType,
                                      @NonNull
                                      @lombok.NonNull long[] shape,
                                      char ordering)
        Create an array with given data type shape and ordering.
        Parameters:
        dataType - data type.
        shape - the shape of the array
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created array.
      • checkShapeValues

        public static void checkShapeValues​(long... shape)
        Throws exception on negative shape values.
        Parameters:
        shape - to check
      • createUninitialized

        public static INDArray createUninitialized​(int[] shape,
                                                   char ordering)
        Creates an *uninitialized* array with the specified shape and ordering.
        NOTE: The underlying memory (DataBuffer) will not be initialized. Don't use this unless you know what you are doing.
        Parameters:
        shape - the shape of the array
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the instance
      • createUninitialized

        public static INDArray createUninitialized​(DataType type,
                                                   long... shape)
      • createUninitialized

        public static INDArray createUninitialized​(DataType type,
                                                   long[] shape,
                                                   char ordering)
        Creates an *uninitialized* array with the specified data type, shape and ordering.
        Parameters:
        type - data type
        shape - the shape of the array
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created array.
      • createUninitialized

        public static INDArray createUninitialized​(long[] shape,
                                                   char ordering)
        Creates an *uninitialized* array with the specified shape and ordering.
        Parameters:
        shape - the shape of the array
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        Returns:
        the created array.
      • createUninitialized

        public static INDArray createUninitialized​(long... shape)
        Creates an *uninitialized* ndarray with the specified shape and default ordering.
        NOTE: The underlying memory (DataBuffer) will not be initialized. Don't use this unless you know what you are doing.
        Parameters:
        shape - the shape of the array
        Returns:
        the instance
      • createUninitialized

        public static INDArray createUninitialized​(long length)
        This method creates an *uninitialized* ndarray of specified length and default ordering. PLEASE NOTE: Do not use this method unless you're 100% sure why you use it.
        Parameters:
        length - length of array to create
        Returns:
        the created INDArray
      • createUninitializedDetached

        public static INDArray createUninitializedDetached​(DataType dataType,
                                                           char ordering,
                                                           long... shape)
        Create an uninitialized ndArray. Detached from workspace.
        Parameters:
        dataType - data type. Exceptions will be thrown for UTF8, COMPRESSED and UNKNOWN data types.
        ordering - Fortran 'f' or C/C++ 'c' ordering.
        shape - the shape of the array.
        Returns:
        the created detached array.
      • zeros

        public static INDArray zeros​(DataType dataType,
                                     @NonNull
                                     @lombok.NonNull long... shape)
        Creates an array with the specified data tyoe and shape initialized with zero.
        Parameters:
        dataType - data type.
        shape - the shape of the array
        Returns:
        the created array.
      • valueArrayOf

        public static INDArray valueArrayOf​(int[] shape,
                                            double value)
        Creates an ndarray with the specified value as the only value in the ndarray. Some people may know this as np.full
        Parameters:
        shape - the shape of the array
        value - the value to assign
        Returns:
        the created ndarray
      • valueArrayOf

        public static INDArray valueArrayOf​(long[] shape,
                                            float value)
        Creates an ndarray with the specified value as the only value in the FLOAT32 datatype NDArray. Equivalent to Numpy's np.full
        Parameters:
        shape - the shape of the array
        value - the value to assign
        Returns:
        the created ndarray
      • valueArrayOf

        public static INDArray valueArrayOf​(long[] shape,
                                            int value)
        Creates an ndarray with the specified value as the only value in the INTEGER datatype NDArray. Equivalent to Numpy's np.full
        Parameters:
        shape - the shape of the array
        value - the value to assign
        Returns:
        the created ndarray
      • valueArrayOf

        public static INDArray valueArrayOf​(long[] shape,
                                            double value,
                                            DataType type)
        Creates an ndarray with the specified value as the only value in the ndarray. Some people may know this as np.full
        Parameters:
        shape - the shape of the array
        value - the value to assign
        type - data type
        Returns:
        the created ndarray
      • valueArrayOf

        public static INDArray valueArrayOf​(long num,
                                            double value)
        Creates a row vector ndarray with the specified value as the only value in the ndarray Some people may know this as np.full
        Parameters:
        num - number of columns
        value - the value to assign
        Returns:
        the created ndarray
      • valueArrayOf

        public static INDArray valueArrayOf​(long rows,
                                            long columns,
                                            double value)
        Creates a row vector with the specified number of columns Some people may know this as np.full
        Parameters:
        rows - the number of rows in the matrix
        columns - the columns of the ndarray
        value - the value to assign
        Returns:
        the created ndarray
      • zerosLike

        public static INDArray zerosLike​(INDArray arr)
        Empty like
        Parameters:
        arr - the array to create the ones like
        Returns:
        ones in the shape of the given array
      • onesLike

        public static INDArray onesLike​(INDArray arr)
        Ones like
        Parameters:
        arr - the array to create the ones like
        Returns:
        ones in the shape of the given array
      • ones

        public static INDArray ones​(DataType dataType,
                                    @NonNull
                                    @lombok.NonNull long... shape)
        Creates an array with the specified datatype and shape, with values all set to 1
        Parameters:
        shape - Shape fo the array
        Returns:
        the created ndarray
      • hstack

        public static INDArray hstack​(@NonNull
                                      @NonNull INDArray... arrs)
        Concatenates two matrices horizontally. Matrices must have identical numbers of rows.
        Parameters:
        arrs - the first matrix to concat
      • hstack

        public static INDArray hstack​(Collection<INDArray> arrs)
        Concatenates two matrices horizontally. Matrices must have identical numbers of rows.
        Parameters:
        arrs - the first matrix to concat
      • vstack

        public static INDArray vstack​(@NonNull
                                      @NonNull INDArray... arrs)
        Concatenates two matrices vertically. Matrices must have identical numbers of columns.
        Note that for vstack on rank 1 arrays, this is equivalent to pile(INDArray...). Example: vstack([3],[3]) -> [2,3]
        Parameters:
        arrs - Arrays to vstack
      • vstack

        public static INDArray vstack​(Collection<INDArray> arrs)
        Concatenates two matrices vertically. Matrices must have identical numbers of columns.
        Note that for vstack on rank 1 arrays, this is equivalent to pile(INDArray...). Example: vstack([3],[3]) -> [2,3]
        Parameters:
        arrs - Arrays to vstack
      • averageAndPropagate

        public static INDArray averageAndPropagate​(INDArray[] arrays)
        This method averages input arrays, and returns averaged array. On top of that, averaged array is propagated to all input arrays
        Parameters:
        arrays - arrays to average
        Returns:
        averaged arrays
      • averageAndPropagate

        public static INDArray averageAndPropagate​(Collection<INDArray> arrays)
        This method averages input arrays, and returns averaged array. On top of that, averaged array is propagated to all input arrays
        Parameters:
        arrays - arrays to average
        Returns:
        averaged arrays
      • averageAndPropagate

        public static INDArray averageAndPropagate​(INDArray target,
                                                   Collection<INDArray> arrays)
        This method averages input arrays, and returns averaged array. On top of that, averaged array is propagated to all input arrays
        Parameters:
        arrays - arrays to average
        Returns:
        averaged arrays
      • stripOnes

        public static INDArray stripOnes​(INDArray toStrip)
        Reshapes an ndarray to remove leading 1s
        Parameters:
        toStrip - the ndarray to newShapeNoCopy
        Returns:
        the reshaped ndarray
      • accumulate

        public static INDArray accumulate​(@NonNull
                                          @NonNull INDArray... arrays)
        This method sums given arrays and stores them to a new array
        Parameters:
        arrays - array to accumulate
        Returns:
        accumulated array.
      • accumulate

        public static INDArray accumulate​(INDArray target,
                                          Collection<INDArray> arrays)
        This method sums given arrays and stores them to a given target array
        Parameters:
        target - result array
        arrays - arrays to sum
        Returns:
        result array
      • accumulate

        public static INDArray accumulate​(INDArray target,
                                          INDArray[] arrays)
        This method sums given arrays and stores them to a given target array
        Parameters:
        target - result array
        arrays - arrays to sum
        Returns:
        result array
      • pullRows

        public static INDArray pullRows​(INDArray source,
                                        int sourceDimension,
                                        @NonNull
                                        @lombok.NonNull int... indexes)
        This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes
        Parameters:
        source - source tensor
        sourceDimension - dimension of source tensor
        indexes - indexes from source array
        Returns:
        result array
      • pullRows

        public static INDArray pullRows​(INDArray source,
                                        int sourceDimension,
                                        int[] indexes,
                                        char order)
        This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes
        Parameters:
        source - source tensor
        sourceDimension - dimension of source tensor
        indexes - indexes from source array
        Returns:
        concatenated array
      • pullRows

        public static INDArray pullRows​(INDArray source,
                                        INDArray destination,
                                        int sourceDimension,
                                        @NonNull
                                        @lombok.NonNull int... indexes)
        This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes. The concatenated arrays are placed in the specified array.
        Parameters:
        source - source tensor
        destination - Destination tensor (result will be placed here)
        sourceDimension - dimension of source tensor
        indexes - indexes from source array
        Returns:
        Destination array with specified tensors
      • stack

        public static INDArray stack​(int axis,
                                     @NonNull
                                     @NonNull INDArray... values)
        Stack a set of N SDVariables of rank X into one rank X+1 variable. If inputs have shape [a,b,c] then output has shape:
        axis = 0: [N,a,b,c]
        axis = 1: [a,N,b,c]
        axis = 2: [a,b,N,c]
        axis = 3: [a,b,c,N]
        Parameters:
        axis - Axis to stack on
        values - Input variables to stack. Must have the same shape for all inputs
        Returns:
        Output array
        See Also:
        concat(int, INDArray...)
      • concat

        public static INDArray concat​(int dimension,
                                      @NonNull
                                      @NonNull INDArray... toConcat)
        Concatenate ndarrays along a dimension
        Parameters:
        dimension - the dimension to concatenate along
        toConcat - the ndarrays to concat
        Returns:
        the merged ndarrays with an output shape of the ndarray shapes save the dimension shape specified which is then the sum of the sizes along that dimension
      • specialConcat

        public static INDArray specialConcat​(int dimension,
                                             @NonNull
                                             @NonNull INDArray... toConcat)
        Concatenate ndarrays along a dimension PLEASE NOTE: This method is special for GPU backend, it works on HOST side only.
        Parameters:
        dimension - dimension
        toConcat - arrays to concatenate
        Returns:
        concatenated arrays.
      • zeros

        public static INDArray zeros​(int[] shape,
                                     char order)
        Create an ndarray of zeros
        Parameters:
        shape - the shape of the array
        Returns:
        an ndarray with ones filled in
      • zeros

        public static INDArray zeros​(@NonNull
                                     @lombok.NonNull int... shape)
        Create an ndarray of zeros
        Parameters:
        shape - the shape of the array
        Returns:
        an ndarray with ones filled in
      • zeros

        public static INDArray zeros​(@NonNull
                                     @lombok.NonNull long... shape)
        Create an ndarray of zeros
        Parameters:
        shape - the shape of the array
        Returns:
        an ndarray with ones filled in
      • ones

        public static INDArray ones​(@NonNull
                                    @lombok.NonNull int... shape)
        Create an ndarray of ones
        Parameters:
        shape - the shape of the array
        Returns:
        an ndarray with ones filled in
      • scalar

        public static INDArray scalar​(Number value)
        Create a scalar ndarray with the specified value
        Parameters:
        value - the value to initialize the scalar with
        Returns:
        the created ndarray
      • scalar

        public static INDArray scalar​(DataType dataType,
                                      Number value)
        Create a scalar ndarray with the specified value and datatype
        Parameters:
        value - the value to initialize the scalar with
        Returns:
        the created ndarray
      • scalar

        public static INDArray scalar​(double value)
        Create a scalar nd array with the specified value
        Parameters:
        value - the value of the scalar
        Returns:
        the scalar nd array
      • scalar

        public static INDArray scalar​(float value)
        Create a scalar NDArray with the specified value and FLOAT datatype
        Parameters:
        value - the value of the scalar
        Returns:
        the scalar nd array
      • scalar

        public static INDArray scalar​(boolean value)
        Create a scalar NDArray with the specified value and BOOLEAN datatype
        Parameters:
        value - the value of the scalar
        Returns:
        the scalar nd array
      • scalar

        public static INDArray scalar​(int value)
        Create a scalar NDArray with the specified value and INT datatype
        Parameters:
        value - the value of the scalar
        Returns:
        the scalar nd array
      • scalar

        public static INDArray scalar​(long value)
        Create a scalar NDArray with the specified value and LONG datatype
        Parameters:
        value - the value of the scalar
        Returns:
        the scalar nd array
      • getStrides

        public static int[] getStrides​(int[] shape,
                                       char order)
        Get the strides for the given order and shape
        Parameters:
        shape - the shape of the array
        order - the order to getScalar the strides for
        Returns:
        the strides for the given shape and order
      • getStrides

        public static long[] getStrides​(long[] shape,
                                        char order)
      • getStrides

        public static int[] getStrides​(@NonNull
                                       @lombok.NonNull int... shape)
        Get the strides based on the shape and NDArrays.order()
        Parameters:
        shape - the shape of the array
        Returns:
        the strides for the given shape and order specified by NDArrays.order()
      • getStrides

        public static long[] getStrides​(@NonNull
                                        @lombok.NonNull long... shape)
        Get the strides based on the shape and NDArrays.order()
        Parameters:
        shape - the shape of the array
        Returns:
        the strides for the given shape and order specified by NDArrays.order()
      • tile

        public static INDArray tile​(INDArray tile,
                                    @NonNull
                                    @lombok.NonNull int... repeat)
        An alias for repmat
        Parameters:
        tile - the ndarray to tile
        repeat - the shape to repeat
        Returns:
        the tiled ndarray
      • initWithBackend

        public void initWithBackend​(Nd4jBackend backend)
        Initialize with the specific backend
        Parameters:
        backend - the backend to initialize with
      • getShapeInfoProvider

        public static ShapeInfoProvider getShapeInfoProvider()
        Returns:
        Shape info provider
      • getConstantHandler

        public static ConstantHandler getConstantHandler()
        Returns:
        constant handler
      • getAffinityManager

        public static AffinityManager getAffinityManager()
        Returns:
        affinity manager
      • getNDArrayFactory

        public static NDArrayFactory getNDArrayFactory()
        Returns:
        NDArrayFactory
      • getCompressor

        public static BasicNDArrayCompressor getCompressor()
        This method returns BasicNDArrayCompressor instance, suitable for NDArray compression/decompression at runtime
        Returns:
        BasicNDArrayCompressor instance
      • getMemoryManager

        public static MemoryManager getMemoryManager()
        This method returns backend-specific MemoryManager implementation, for low-level memory management
        Returns:
        MemoryManager
      • sizeOfDataType

        @Deprecated
        public static int sizeOfDataType()
        Deprecated.
        Use DataType.width()
        This method returns sizeOf(currentDataType), in bytes
        Returns:
        number of bytes per element
      • sizeOfDataType

        public static int sizeOfDataType​(DataType dtype)
        This method returns size of element for specified dataType, in bytes
        Parameters:
        dtype - number of bytes per element
        Returns:
        element size
      • enableFallbackMode

        public static void enableFallbackMode​(boolean reallyEnable)
        This method enables fallback to safe-mode for specific operations. Use of this method will reduce performance. Currently supported operations are: 1) CPU GEMM PLEASE NOTE: Do not use this method, unless you have too.
        Parameters:
        reallyEnable - fallback mode
      • isFallbackModeEnabled

        public static boolean isFallbackModeEnabled()
        This method checks, if fallback mode was enabled.
        Returns:
        fallback mode
      • getWorkspaceManager

        public static MemoryWorkspaceManager getWorkspaceManager()
        This method returns WorkspaceManager implementation to be used within this JVM process
        Returns:
        WorkspaceManager
      • pile

        public static INDArray pile​(@NonNull
                                    @NonNull INDArray... arrays)
        This method stacks vertically examples with the same shape, increasing result dimensionality. I.e. if you provide bunch of 3D tensors, output will be 4D tensor. Alignment is always applied to axis 0.
        Parameters:
        arrays - arrays to stack
        Returns:
        stacked arrays
      • pile

        public static INDArray pile​(@NonNull
                                    @NonNull Collection<INDArray> arrays)
        This method stacks vertically examples with the same shape, increasing result dimensionality. I.e. if you provide bunch of 3D tensors, output will be 4D tensor. Alignment is always applied to axis 0.
        Parameters:
        arrays - arrays to stack
        Returns:
        stacked array
      • tear

        public static INDArray[] tear​(INDArray tensor,
                                      @NonNull
                                      @lombok.NonNull int... dimensions)
        This method does the opposite to pile/vstack/hstack - it returns independent TAD copies along given dimensions
        Parameters:
        tensor - Array to tear
        dimensions - dimensions
        Returns:
        Array copies
      • triu

        public static INDArray triu​(INDArray m,
                                    int k)
        Upper triangle of an array. Referenced from the numpy docs: Return a copy of a matrix with the elements below the `k`-th diagonal zeroed. Please refer to the documentation for `tril` for further details. See Also -------- tril : lower triangle of an array Examples -------- >>> np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1) array([[ 1, 2, 3], [ 4, 5, 6], [ 0, 8, 9], [ 0, 0, 12]]) """ m = asanyarray(m) mask = tri(*m.shape[-2:], k=k-1, dtype=bool) return where(mask, zeros(1, m.dtype), m)
        Parameters:
        m - source array
        k - to zero below the k-th diagonal
        Returns:
        copy with elements below the `k`-th diagonal zeroed.
      • tri

        public static INDArray tri​(int n,
                                   int m,
                                   int k)
        Like the scipy function tri. From the scipy documentation: An array with ones at and below the given diagonal and zeros elsewhere.
        Parameters:
        n - number of rows in the array
        m - number of columns in the array ( can be just equal to n)
        k - The sub-diagonal at and below which the array is filled. `k` = 0 is the main diagonal, while `k` < 0 is below it, and `k` > 0 is above. The default is 0.
        Returns:
        array with ones at and below the given diagonal and zeros elsewhere
      • where

        public static INDArray[] where​(INDArray condition,
                                       INDArray x,
                                       INDArray y)
        Similar to numpy.where operation. Supports two modes of operation:
        (a) condition array only is provided: returns N 1d arrays of the indices where "condition" values are non-zero. Specifically, each output out has shape [numNonZero(condition)], such that in[out[0], ..., out[n-1]] is non-zero
        (b) all 3 arrays are provided: returns out[i] = (condition[i] != 0 ? x[i] : y[i])
        Parameters:
        condition - Condition array
        x - X array. If null, y must be null also.
        y - Y array. If null, x must be null also
        Returns:
        Either the indices where condition is non-zero (if x and y are null), or values from x/y depending on value of condition
      • writeAsNumpy

        public static void writeAsNumpy​(INDArray arr,
                                        File file)
                                 throws IOException
        Write an INDArray to a File in Numpy .npy format, which can then be loaded with numpy.load
        Parameters:
        arr - the array to write in Numpy .npy format
        file - the file to write to
        Throws:
        IOException - if an error occurs when writing the file
      • convertToNumpy

        public static org.bytedeco.javacpp.Pointer convertToNumpy​(INDArray arr)
        Converts an INDArray to a numpy struct.
        Parameters:
        arr - the array to convert
        Returns:
        a pointer to the numpy struct
      • writeAsNumpy

        public static void writeAsNumpy​(INDArray arr,
                                        OutputStream writeTo)
                                 throws IOException
        Writes an array to an output stream
        Parameters:
        arr - the array to write
        writeTo - the output stream to write to
        Throws:
        IOException
      • createFromNpyPointer

        public static INDArray createFromNpyPointer​(org.bytedeco.javacpp.Pointer pointer)
        Create from an in memory numpy pointer
        Parameters:
        pointer - the pointer to the numpy array
        Returns:
        an ndarray created from the in memory numpy pointer
      • readNpy

        public static INDArray readNpy​(@NonNull
                                       @NonNull String path)
        Create an INDArray from a given Numpy .npy file.
        Parameters:
        path - Path to the .npy file to read
        Returns:
        the created ndarray
      • readNpy

        public static INDArray readNpy​(@NonNull
                                       @NonNull File file)
        Create an INDArray from a given Numpy .npy file.
        Parameters:
        file - the file to create the ndarray from
        Returns:
        the created ndarray
      • createFromNpyFile

        public static INDArray createFromNpyFile​(@NonNull
                                                 @NonNull File file)
        Create an INDArray from a given Numpy .npy file.
        Parameters:
        file - the file to create the ndarray from
        Returns:
        the created ndarray
      • createNpyFromInputStream

        public static INDArray createNpyFromInputStream​(@NonNull
                                                        @NonNull InputStream is)
                                                 throws IOException
        Create a numpy array based on the passed in input stream
        Parameters:
        is - the input stream to read
        Returns:
        the loaded ndarray
        Throws:
        IOException
      • createNpyFromByteArray

        public static INDArray createNpyFromByteArray​(@NonNull
                                                      @lombok.NonNull byte[] input)
        Create an INDArray from the given numpy input.
        The numpy input follows the format: https://docs.scipy.org/doc/numpy-1.14.0/neps/npy-format.html
        Parameters:
        input - the input byte array with the npy format
        Returns:
        the equivalent INDArray
      • toNpyByteArray

        public static byte[] toNpyByteArray​(INDArray input)
        Converts an INDArray to a byte array
        Parameters:
        input - the input array
        Returns:
        the INDArray as a byte array with the numpy format. For more on the format, see: https://docs.scipy.org/doc/numpy-1.14.0/neps/npy-format.html
      • defaultFloatingPointType

        public static DataType defaultFloatingPointType()
      • isPrecisionBoostAllowed

        public static boolean isPrecisionBoostAllowed()
      • scalar

        public static INDArray scalar​(@NonNull
                                      @NonNull String string)
      • create

        public static INDArray create​(@NonNull
                                      @NonNull String... strings)
      • createFromArray

        public static INDArray createFromArray​(double... array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with DOUBLE data type
      • createFromArray

        public static INDArray createFromArray​(float... array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with FLOAT data type
      • createFromArray

        public static INDArray createFromArray​(int... array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with INT32 data type
      • createFromArray

        public static INDArray createFromArray​(short... array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with INT16 data type
      • createFromArray

        public static INDArray createFromArray​(byte... array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with INT8 data type
      • createFromArray

        public static INDArray createFromArray​(long... array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with INT64 data type
      • createFromArray

        public static INDArray createFromArray​(boolean... array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with BOOL data type
      • createFromArray

        public static INDArray createFromArray​(double[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with DOUBLE data type
      • createFromArray

        public static INDArray createFromArray​(float[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with FLOAT data type
      • createFromArray

        public static INDArray createFromArray​(long[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with INT64 data type
      • createFromArray

        public static INDArray createFromArray​(int[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with INT32 data type
      • createFromArray

        public static INDArray createFromArray​(short[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with INT16 data type
      • createFromArray

        public static INDArray createFromArray​(byte[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with INT8 data type
      • createFromArray

        public static INDArray createFromArray​(boolean[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with BOOL data type
      • createFromArray

        public static INDArray createFromArray​(double[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with DOUBLE data type
      • createFromArray

        public static INDArray createFromArray​(float[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with FLOAT data type
      • createFromArray

        public static INDArray createFromArray​(long[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with INT64 data type
      • createFromArray

        public static INDArray createFromArray​(int[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with INT32 data type
      • createFromArray

        public static INDArray createFromArray​(short[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with INT16 data type
      • createFromArray

        public static INDArray createFromArray​(byte[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with INT8 data type
      • createFromArray

        public static INDArray createFromArray​(boolean[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with BOOL data type
      • createFromArray

        public static INDArray createFromArray​(double[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with DOUBLE data type
      • createFromArray

        public static INDArray createFromArray​(float[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with FLOAT data type
      • createFromArray

        public static INDArray createFromArray​(long[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with INT64 data type
      • createFromArray

        public static INDArray createFromArray​(int[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with INT32 data type
      • createFromArray

        public static INDArray createFromArray​(short[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with INT16 data type
      • createFromArray

        public static INDArray createFromArray​(byte[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with INT8 data type
      • createFromArray

        public static INDArray createFromArray​(boolean[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with BOOL data type
      • createFromArray

        public static INDArray createFromArray​(Double[] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with DOUBLE data type
      • createFromArray

        public static INDArray createFromArray​(Float[] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with FLOAT data type
      • createFromArray

        public static INDArray createFromArray​(Integer[] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with INT32 data type
      • createFromArray

        public static INDArray createFromArray​(Short[] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with INT16 data type
      • createFromArray

        public static INDArray createFromArray​(Byte[] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with INT8 data type
      • createFromArray

        public static INDArray createFromArray​(Long[] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with INT64 data type
      • createFromArray

        public static INDArray createFromArray​(Boolean[] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        1D INDArray with BOOL data type
      • createFromArray

        public static INDArray createFromArray​(Double[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with DOUBLE data type
      • createFromArray

        public static INDArray createFromArray​(Float[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with FLOAT data type
      • createFromArray

        public static INDArray createFromArray​(Integer[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with INT32 data type
      • createFromArray

        public static INDArray createFromArray​(Short[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with INT16 data type
      • createFromArray

        public static INDArray createFromArray​(Byte[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with INT8 data type
      • createFromArray

        public static INDArray createFromArray​(Long[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with INT64 data type
      • createFromArray

        public static INDArray createFromArray​(Boolean[][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        2D INDArray with BOOL data type
      • createFromArray

        public static INDArray createFromArray​(Double[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with DOUBLE data type
      • createFromArray

        public static INDArray createFromArray​(Float[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with FLOAT data type
      • createFromArray

        public static INDArray createFromArray​(Integer[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with INT32 data type
      • createFromArray

        public static INDArray createFromArray​(Short[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with INT16 data type
      • createFromArray

        public static INDArray createFromArray​(Byte[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with INT8 data type
      • createFromArray

        public static INDArray createFromArray​(Long[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with INT64 data type
      • createFromArray

        public static INDArray createFromArray​(Boolean[][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        3D INDArray with BOOL data type
      • createFromArray

        public static INDArray createFromArray​(Double[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with DOUBLE data type
      • createFromArray

        public static INDArray createFromArray​(Float[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with FLOAT data type
      • createFromArray

        public static INDArray createFromArray​(Integer[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with INT32 data type
      • createFromArray

        public static INDArray createFromArray​(Short[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with INT16 data type
      • createFromArray

        public static INDArray createFromArray​(Byte[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with INT8 data type
      • createFromArray

        public static INDArray createFromArray​(Long[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with INT64 data type
      • createFromArray

        public static INDArray createFromArray​(Boolean[][][][] array)
        This method creates INDArray from provided jvm array
        Parameters:
        array - jvm array
        Returns:
        4D INDArray with BOOL data type
      • isExperimentalMode

        public static boolean isExperimentalMode()
      • exec

        public static INDArray exec​(Op op)
        Execute the operation and return the result
        Parameters:
        op - the operation to execute
      • exec

        public static INDArray[] exec​(CustomOp op)
        Execute the operation and return the result
        Parameters:
        op - the operation to execute
      • exec

        public static INDArray[] exec​(CustomOp op,
                                      OpContext context)
        Execute the operation and return the result
        Parameters:
        op - the operation to execute