Class BaseNDArrayFactory

    • Field Detail

      • order

        protected char order
      • blas

        protected Blas blas
      • level1

        protected Level1 level1
      • level2

        protected Level2 level2
      • level3

        protected Level3 level3
      • lapack

        protected Lapack lapack
    • Constructor Detail

      • BaseNDArrayFactory

        public BaseNDArrayFactory()
      • BaseNDArrayFactory

        protected BaseNDArrayFactory​(DataType dtype,
                                     Character order)
        Initialize with the given data opType and ordering The ndarray factory will use this for
        Parameters:
        dtype - the data opType
        order - the ordering in mem
      • BaseNDArrayFactory

        protected BaseNDArrayFactory​(DataType dtype,
                                     char order)
        Parameters:
        dtype - the data opType
        order - the ordering
    • Method Detail

      • setOrder

        public void setOrder​(char order)
        Sets the order. Primarily for testing purposes
        Specified by:
        setOrder in interface NDArrayFactory
        Parameters:
        order -
      • order

        public char order()
        Returns the order for this ndarray for internal data storage
        Specified by:
        order in interface NDArrayFactory
        Returns:
        the order (c or f)
      • dtype

        public DataType dtype()
        Returns the data opType for this ndarray
        Specified by:
        dtype in interface NDArrayFactory
        Returns:
        the data opType for this ndarray
      • create

        public INDArray create​(int[] ints,
                               int[] ints1,
                               int[] stride,
                               long offset)
        Specified by:
        create in interface NDArrayFactory
        Returns:
      • toFlattened

        public INDArray toFlattened​(Collection<INDArray> matrices)
        Returns a vector with all of the elements in every nd array equal to the sum of the lengths of the ndarrays
        Specified by:
        toFlattened in interface NDArrayFactory
        Parameters:
        matrices - the ndarrays to getFloat a flattened representation of
        Returns:
        the flattened ndarray
      • toFlattened

        public INDArray toFlattened​(int length,
                                    Iterator<? extends INDArray>... matrices)
        Description copied from interface: NDArrayFactory
        Returns a flattened ndarray with all of the elements in each ndarray regardless of dimension
        Specified by:
        toFlattened in interface NDArrayFactory
        matrices - the ndarrays to use
        Returns:
        a flattened ndarray of the elements in the order of titerating over the ndarray and the linear view of each
      • toFlattened

        public INDArray toFlattened​(INDArray... matrices)
        Description copied from interface: NDArrayFactory
        Flatten all of the ndarrays in to one long vector
        Specified by:
        toFlattened in interface NDArrayFactory
        Parameters:
        matrices - the matrices to flatten
        Returns:
        the flattened vector
      • toFlattened

        public INDArray toFlattened​(char order,
                                    INDArray... matrices)
        Description copied from interface: NDArrayFactory
        Flatten all of the ndarrays in to one long vector
        Specified by:
        toFlattened in interface NDArrayFactory
        matrices - the matrices to flatten
        Returns:
        the flattened vector
      • eye

        public INDArray eye​(long n)
        Create the identity ndarray
        Specified by:
        eye in interface NDArrayFactory
        Parameters:
        n - the number for the identity
        Returns:
      • rot90

        public void rot90​(INDArray toRotate)
        Rotate a matrix 90 degrees
        Specified by:
        rot90 in interface NDArrayFactory
        Parameters:
        toRotate - the matrix to rotate
      • rot

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

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

        public INDArray arange​(double begin,
                               double end,
                               double step)
        Array of evenly spaced values.
        Specified by:
        arange in interface NDArrayFactory
        Parameters:
        begin - the begin of the range
        end - the end of the range
        Returns:
        the range vector
      • copy

        public void copy​(INDArray a,
                         INDArray b)
        Copy a to b
        Specified by:
        copy in interface NDArrayFactory
        Parameters:
        a - the origin matrix
        b - the destination matrix
      • rand

        public INDArray rand​(int[] shape,
                             float min,
                             float max,
                             Random rng)
        Generates a random matrix between min and max
        Specified by:
        rand in interface NDArrayFactory
        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
      • rand

        public INDArray rand​(long rows,
                             long columns,
                             float min,
                             float max,
                             Random rng)
        Generates a random matrix between min and max
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        rows - the number of rows of the matrix
        columns - the number of columns in 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
      • appendBias

        public INDArray appendBias​(INDArray... vectors)
        Merge the vectors and append a bias. Each vector must be either row or column vectors. An exception is thrown for inconsistency (mixed row and column vectors)
        Specified by:
        appendBias in interface NDArrayFactory
        Parameters:
        vectors - the vectors to merge
        Returns:
        the merged ndarray appended with the bias
      • rand

        public INDArray rand​(long rows,
                             long columns,
                             Random r)
        Create a random ndarray with the given shape using the given rng
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        rows - the number of rows in the matrix
        columns - the number of columns in the matrix
        r - the random generator to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(long rows,
                             long columns,
                             long seed)
        Create a random ndarray with the given shape using the given rng
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        rows - the number of rows in the matrix
        columns - the columns of the ndarray
        seed - the seed to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(long rows,
                             long columns)
        Create a random ndarray with the given shape using the current time as the seed
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        rows - the number of rows in the matrix
        columns - the number of columns in the matrix
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(char order,
                             long rows,
                             long columns)
        Create a random (uniform 0-1) NDArray with the specified shape and order
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        order - Order ('c' or 'f') of the output array
        rows - Number of rows of the output array
        columns - Number of columns of the output array
      • randn

        public INDArray randn​(long rows,
                              long columns,
                              Random r)
        Random normal using the given rng
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        rows - the number of rows in the matrix
        columns - the number of columns in the matrix
        r - the random generator to use
        Returns:
      • randn

        public INDArray randn​(long rows,
                              long columns)
        Random normal using the current time stamp as the seed
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        rows - the number of rows in the matrix
        columns - the number of columns in the matrix
        Returns:
      • randn

        public INDArray randn​(char order,
                              long rows,
                              long columns)
        Generate a random normal N(0,1) with the specified order and shape
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        order - Order of the output array
        rows - the number of rows in the matrix
        columns - the number of columns in the matrix
        Returns:
      • randn

        public INDArray randn​(long rows,
                              long columns,
                              long seed)
        Random normal using the specified seed
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        rows - the number of rows in the matrix
        columns - the number of columns in the matrix
        Returns:
      • rand

        public INDArray rand​(int[] shape,
                             Distribution r)
        Create a random ndarray with the given shape using the given rng
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        r - the random generator to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(int[] shape,
                             Random r)
        Create a random ndarray with the given shape using the given rng
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        r - the random generator to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(int[] shape,
                             long seed)
        Create a random ndarray with the given shape using the given rng
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        seed - the seed to use
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(int[] shape)
        Create a random ndarray with the given shape using the current time as the seed
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(long[] shape)
        Description copied from interface: NDArrayFactory
        Create a random ndarray with the given shape using the current time as the seed
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(char order,
                             int[] shape)
        Create a random ndarray with the given shape and order
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
        the random ndarray with the specified shape
      • rand

        public INDArray rand​(char order,
                             long[] shape)
        Description copied from interface: NDArrayFactory
        Create a random ndarray with the given shape and specified output order
        Specified by:
        rand in interface NDArrayFactory
        Parameters:
        order - the order of the array
        shape - the shape of the array
        Returns:
        the created ndarray
      • randn

        public INDArray randn​(int[] shape,
                              Random r)
        Random normal using the given rng
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        r - the random generator to use
        Returns:
      • randn

        public INDArray randn​(char order,
                              int[] shape)
        Random normal using the current time stamp as the seed
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        order - the order ('c' or 'f') of the output array
        Returns:
      • randn

        public INDArray randn​(char order,
                              long[] shape)
        Description copied from interface: NDArrayFactory
        Random normal N(0,1) with the specified shape and order
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        order - the order ('c' or 'f') of the output array
        shape - the shape of the ndarray
      • randn

        public INDArray randn​(int[] shape)
        Random normal N(0,1) with the specified shape and
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
      • randn

        public INDArray randn​(long[] shape)
        Description copied from interface: NDArrayFactory
        Random normal N(0,1) using the current time stamp as the seed
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
      • randn

        public INDArray randn​(int[] shape,
                              long seed)
        Random normal using the specified seed
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
      • randn

        public INDArray randn​(long[] shape,
                              long seed)
        Description copied from interface: NDArrayFactory
        Random normal using the specified seed
        Specified by:
        randn in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
      • create

        public INDArray create​(double[] data)
        Creates a row vector with the data
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        data - the columns of the ndarray
        Returns:
        the created ndarray
      • create

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

        public INDArray create​(long columns)
        Creates a row vector with the specified number of columns
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        columns - the columns of the ndarray
        Returns:
        the created ndarray
      • zeros

        public INDArray zeros​(long rows,
                              long columns)
        Creates a row vector with the specified number of columns
        Specified by:
        zeros in interface NDArrayFactory
        Parameters:
        rows - the rows of the ndarray
        columns - the columns of the ndarray
        Returns:
        the created ndarray
      • pullRows

        public 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
        Specified by:
        pullRows in interface NDArrayFactory
        Parameters:
        source - source tensor
        sourceDimension - dimension of source tensor
        indexes - indexes from source array
        order - order for result array
        Returns:
      • pullRows

        public INDArray pullRows​(INDArray source,
                                 int sourceDimension,
                                 int[] indexes)
        This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes
        Specified by:
        pullRows in interface NDArrayFactory
        Parameters:
        source - source tensor
        sourceDimension - dimension of source tensor
        indexes - indexes from source array
        Returns:
      • zeros

        public INDArray zeros​(long columns)
        Creates a row vector with the specified number of columns
        Specified by:
        zeros in interface NDArrayFactory
        Parameters:
        columns - the columns of the ndarray
        Returns:
        the created ndarray
      • valueArrayOf

        public INDArray valueArrayOf​(int[] shape,
                                     double value)
        Creates an ndarray with the specified value as the only value in the ndarray
        Specified by:
        valueArrayOf in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        value - the value to assign
        Returns:
        the created ndarray
      • create

        public INDArray create​(int[] shape,
                               int[] stride,
                               long offset,
                               char ordering)
        Specified by:
        create in interface NDArrayFactory
        Returns:
      • valueArrayOf

        public INDArray valueArrayOf​(long rows,
                                     long columns,
                                     double value)
        Creates a row vector with the specified number of columns
        Specified by:
        valueArrayOf in interface NDArrayFactory
        Parameters:
        rows - the number of rows in the matrix
        columns - the columns of the ndarray
        value - the value to assign
        Returns:
        the created ndarray
      • ones

        public INDArray ones​(long rows,
                             long columns)
        Creates a row vector with the specified number of columns
        Specified by:
        ones in interface NDArrayFactory
        Parameters:
        rows - the number of rows in the matrix
        columns - the columns of the ndarray
        Returns:
        the created ndarray
      • ones

        public INDArray ones​(long columns)
        Creates a row vector with the specified number of columns
        Specified by:
        ones in interface NDArrayFactory
        Parameters:
        columns - the columns of the ndarray
        Returns:
        the created ndarray
      • create

        public INDArray create​(float[] data,
                               int[] shape,
                               char ordering)
        Specified by:
        create in interface NDArrayFactory
        Returns:
      • concat

        public INDArray concat​(int dimension,
                               INDArray... toConcat)
        concatenate ndarrays along a dimension
        Specified by:
        concat in interface NDArrayFactory
        Parameters:
        dimension - the dimension to concatenate along
        toConcat - the ndarrays to concatenate
        Returns:
        the concatenate ndarrays
      • hstack

        public INDArray hstack​(@NonNull
                               @NonNull INDArray... arrs)
        Concatenates two matrices horizontally. Matrices must have identical numbers of rows.
        Specified by:
        hstack in interface NDArrayFactory
        Parameters:
        arrs -
      • vstack

        public INDArray vstack​(INDArray... arrs)
        Concatenates two matrices vertically. Matrices must have identical numbers of columns.
        Specified by:
        vstack in interface NDArrayFactory
        Parameters:
        arrs -
      • zeros

        public INDArray zeros​(int[] shape)
        Create an ndarray of zeros
        Specified by:
        zeros in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
        an ndarray with ones filled in
      • ones

        public INDArray ones​(int[] shape)
        Create an ndarray of ones
        Specified by:
        ones in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
        an ndarray with ones filled in
      • create

        public INDArray create​(float[] data,
                               long rows,
                               long columns,
                               int[] stride,
                               long offset)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        data - the data to use with the ndarray
        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 instance
      • create

        public abstract INDArray create​(float[] data,
                                        int[] shape,
                                        int[] stride,
                                        long offset)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        stride - the stride for the ndarray
        offset - the offset of the ndarray
        Returns:
        the instance
      • create

        public INDArray create​(double[] data,
                               int[] shape)
        Create an ndrray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        data - the data to use with tne ndarray
        shape - the shape of the ndarray
        Returns:
        the created ndarray
      • create

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

        public INDArray create​(double[] data,
                               long rows,
                               long columns,
                               int[] stride,
                               long offset)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        data - the data to use with tne ndarray
        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 instance
      • create

        public abstract INDArray create​(double[] data,
                                        int[] shape,
                                        int[] stride,
                                        long offset)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        stride - the stride for the ndarray
        offset - the offset of the ndarray
        Returns:
        the instance
      • create

        public abstract INDArray create​(List<INDArray> list,
                                        int[] shape)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
        the instance
      • create

        public INDArray create​(long rows,
                               long columns,
                               int[] stride,
                               long offset)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        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 instance
      • create

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

        public INDArray scalar​(DataType dataType)
        Description copied from interface: NDArrayFactory
        Create a scalar nd array with the data type and a default value depending on the data type. Generally this will be an empty string for UTF8 or 0.0 for numerical values, or true for booleans.
        Specified by:
        scalar in interface NDArrayFactory
        Parameters:
        dataType - the dataType of the scalar * @return the scalar nd array
      • create

        public INDArray create​(long rows,
                               long columns,
                               int[] stride)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        rows - the rows of the ndarray
        columns - the columns of the ndarray
        stride - the stride for the ndarray
        Returns:
        the instance
      • create

        public INDArray create​(long[] shape,
                               long[] stride,
                               long offset,
                               char ordering)
        Specified by:
        create in interface NDArrayFactory
      • create

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

        public INDArray create​(long rows,
                               long columns)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        rows - the rows of the ndarray
        columns - the columns of the ndarray
        Returns:
        the instance
      • create

        public INDArray create​(long[] shape)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
        the instance
      • create

        public INDArray create​(int[] shape)
        Creates an ndarray with the specified shape
        Specified by:
        create in interface NDArrayFactory
        Parameters:
        shape - the shape of the ndarray
        Returns:
        the instance
      • scalar

        public INDArray scalar​(float value,
                               long offset)
        Create a scalar nd array with the specified value and offset
        Specified by:
        scalar in interface NDArrayFactory
        Parameters:
        value - the value of the scalar
        offset - the offset of the ndarray
        Returns:
        the scalar nd array
      • scalar

        public INDArray scalar​(double value,
                               long offset)
        Create a scalar nd array with the specified value and offset
        Specified by:
        scalar in interface NDArrayFactory
        Parameters:
        value - the value of the scalar
        offset - the offset of the ndarray
        Returns:
        the scalar nd array
      • scalar

        public INDArray scalar​(int value,
                               long offset)
        Create a scalar nd array with the specified value and offset
        Specified by:
        scalar in interface NDArrayFactory
        Parameters:
        value - the value of the scalar
        offset - the offset of the ndarray
        Returns:
        the scalar nd array
      • scalar

        public INDArray scalar​(Number value)
        Create a scalar ndarray with the specified offset
        Specified by:
        scalar in interface NDArrayFactory
        Parameters:
        value - the value to initialize the scalar with
        Returns:
        the created ndarray
      • scalar

        public INDArray scalar​(double value)
        Create a scalar nd array with the specified value and offset
        Specified by:
        scalar in interface NDArrayFactory
        Parameters:
        value - the value of the scalar
        Returns:
        the scalar nd array
      • scalar

        public INDArray scalar​(float value)
        Description copied from interface: NDArrayFactory
        Create a scalar nd array with the specified value and offset
        Specified by:
        scalar in interface NDArrayFactory
        Parameters:
        value - the value of the scalar = * @return the scalar nd array
      • create

        public INDArray create​(float[] data,
                               int[] shape,
                               int[] stride,
                               char order,
                               long offset)
        Specified by:
        create in interface NDArrayFactory
        Returns:
      • create

        public INDArray create​(double[] data,
                               int[] shape,
                               int[] stride,
                               char order,
                               long offset)
        Specified by:
        create in interface NDArrayFactory
        Returns:
      • create

        public INDArray create​(int[] data,
                               int[] shape,
                               int[] stride,
                               char order,
                               long offset)
        Specified by:
        create in interface NDArrayFactory
        Returns: