Documentation of 'mikera.matrixx.Matrix' Java class
Matrix
mikera.matrixx

Class Matrix

    • Constructor Detail

      • Matrix

        public Matrix(AMatrix m)
        Creates a new Matrix with a copy of all data from the source matrix
        Parameters:
        m -
      • Matrix

        public Matrix(int rowCount,
                      int columnCount)
    • Method Detail

      • create

        public static Matrix create(int rowCount,
                                    int columnCount)
        Creates a new zero-filled matrix of the specified shape.
      • create

        public static Matrix create(int... shape)
        Creates a new zero-filled matrix of the specified shape.
      • create

        public static Matrix create(AMatrix m)
        Creates a new mutable dense matrix containing a copy of another matroix
      • createRandom

        public static Matrix createRandom(int rows,
                                          int cols)
      • createFromRows

        public static Matrix createFromRows(java.lang.Object... rows)
      • create

        public static Matrix create(double[][] data)
      • create

        public static Matrix create(AVector... data)
        Creates a new Matrix using the given vectors as row data
        Parameters:
        data -
        Returns:
      • isFullyMutable

        public boolean isFullyMutable()
        Description copied from interface: INDArray
        If this method returns true, the INDArray is guaranteed to be fully mutable in all positions i.e. every position can store any valid double value
        Specified by:
        isFullyMutable in interface INDArray
        Specified by:
        isFullyMutable in class AMatrix
      • isView

        public boolean isView()
        Description copied from interface: INDArray
        Return true if this array is considered as a view type. This indicates (but does not guarantee): a) Data is *likely* to be shared with other arrays, so mutation of one may affect others b) It is *unlikely* to be in the most efficient general purpose format isView is intended to be used as for heuristics. It should *not* be used where the outcome might affect correctness.
        Specified by:
        isView in interface INDArray
        Overrides:
        isView in class AMatrix
      • isBoolean

        public boolean isBoolean()
        Description copied from interface: INDArray
        Returns true if the array is boolean (contains only 0.0 or 1.0 values)
        Specified by:
        isBoolean in interface INDArray
        Overrides:
        isBoolean in class AMatrix
      • isZero

        public boolean isZero()
        Description copied from class: AMatrix
        Returns true if the matrix is the zero matrix (all components zero)
        Specified by:
        isZero in interface INDArray
        Overrides:
        isZero in class ADenseArrayMatrix
      • wrap

        public static Matrix wrap(int rowCount,
                                  int columnCount,
                                  double[] data)
        Wraps a double[] array as a dense Matrix. Double array must contain exactly the right number of elements, if not consider Matrixx.wrapStrided(..) *
        Parameters:
        rowCount -
        columnCount -
        data -
        Returns:
      • innerProduct

        public Matrix innerProduct(AMatrix a)
        Description copied from interface: IMatrix
        Computes the inner product of this matrix with another. Equivalent to matrix x matrix multiplication
        Specified by:
        innerProduct in interface IMatrix
        Overrides:
        innerProduct in class AMatrix
        Returns:
      • elementMax

        public double elementMax()
        Description copied from interface: INDArray
        Returns the maximum element value in this array. Throws an error if there are no elements.
        Specified by:
        elementMax in interface INDArray
        Overrides:
        elementMax in class ADenseArrayMatrix
      • elementMin

        public double elementMin()
        Description copied from interface: INDArray
        Returns the maximum element value in this array. Throws an error if there are no elements.
        Specified by:
        elementMin in interface INDArray
        Overrides:
        elementMin in class ADenseArrayMatrix
      • abs

        public void abs()
        Description copied from interface: INDArray
        Replaces all elements of this array with their absolute values, according to Math.abs(double)
        Specified by:
        abs in interface INDArray
        Overrides:
        abs in class AMatrix
      • signum

        public void signum()
        Description copied from interface: INDArray
        Calculates the signum of all elements of this mutable array Sets each component of the array to its sign value (-1, 0 or 1)
        Specified by:
        signum in interface INDArray
        Overrides:
        signum in class AMatrix
      • square

        public void square()
        Description copied from interface: INDArray
        Squares all elements of the array in place
        Specified by:
        square in interface INDArray
        Overrides:
        square in class AMatrix
      • exp

        public void exp()
        Description copied from interface: INDArray
        Computes the function e^x (in-place) for all array elements
        Specified by:
        exp in interface INDArray
        Overrides:
        exp in class AMatrix
      • log

        public void log()
        Description copied from interface: INDArray
        Computes the natural logarithm (in-place) for all array elements
        Specified by:
        log in interface INDArray
        Overrides:
        log in class AMatrix
      • nonZeroCount

        public long nonZeroCount()
        Description copied from interface: INDArray
        Returns the number of non-zero elements in the array.
        Specified by:
        nonZeroCount in interface INDArray
        Overrides:
        nonZeroCount in class AMatrix
      • copyRowTo

        public final void copyRowTo(int row,
                                    double[] dest,
                                    int destOffset)
        Description copied from class: AMatrix
        Copies the elements in a selected row of this matrix to a double array
        Overrides:
        copyRowTo in class ADenseArrayMatrix
        Parameters:
        row - The index of the selected row
        dest - Destination double[] array
        destOffset - Offset into destination array
      • copyColumnTo

        public final void copyColumnTo(int col,
                                       double[] dest,
                                       int destOffset)
        Description copied from class: AMatrix
        Copies the elements in a selected row of this matrix to a double array
        Specified by:
        copyColumnTo in class AStridedMatrix
        dest - Destination double[] array
      • transform

        public void transform(AVector source,
                              AVector dest)
        Description copied from interface: IMatrix
        Transforms a source vector into a destination vector, using matrix multiplication (inner product). The destination vector is overwritten.
        Specified by:
        transform in interface IMatrix
        Overrides:
        transform in class ADenseArrayMatrix
      • getRow

        public ArraySubVector getRow(int row)
        Description copied from interface: IMatrix
        Returns a row of the matrix. May or may not be a view, depending on matrix type. Intended for the fastest possible read access of the row. This often means a view, but might not be (e.g. getRow on a Matrix33 returns a Vector3).
        Specified by:
        getRow in interface IMatrix
        Specified by:
        getRow in interface IFastRows
        Overrides:
        getRow in class ADenseArrayMatrix
      • getColumn

        public AStridedVector getColumn(int col)
        Description copied from interface: IMatrix
        Returns a column of the matrix. May or may not be a view, depending on matrix type. Intended for the fastest possible read access of the column. This often means a view, but might not be (e.g. getColumn on a Matrix33 returns a Vector3).
        Specified by:
        getColumn in interface IMatrix
        Overrides:
        getColumn in class ADenseArrayMatrix
      • swapRows

        public void swapRows(int i,
                             int j)
        Description copied from class: AMatrix
        Swaps two rows of the matrix in place This is an elementary row operation
        Overrides:
        swapRows in class AMatrix
      • swapColumns

        public void swapColumns(int i,
                                int j)
        Description copied from class: AMatrix
        Swaps two columns of the matrix in place
        Overrides:
        swapColumns in class AMatrix
      • multiplyRow

        public void multiplyRow(int i,
                                double factor)
        Description copied from class: AMatrix
        Multiplies a row by a constant factor This is an elementary row operation
        Overrides:
        multiplyRow in class AMatrix
      • addRowMultiple

        public void addRowMultiple(int src,
                                   int dst,
                                   double factor)
        Description copied from class: AMatrix
        Adds a multiple of a source row to a destination row This is an elementary row operation
        Overrides:
        addRowMultiple in class AMatrix
      • toVector

        public Vector toVector()
        Description copied from interface: INDArray
        Coerces the array into a flattened dense Vector, in row-major order. May return the same array if it is already a Vector instance.
        Specified by:
        toVector in interface INDArray
        Overrides:
        toVector in class AMatrix
      • toMatrix

        public final Matrix toMatrix()
        Description copied from class: AMatrix
        Coerces the matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.
        Overrides:
        toMatrix in class AMatrix
      • toDoubleArray

        public final double[] toDoubleArray()
        Description copied from interface: INDArray
        Copies the elements of this array to a new double[] array.
        Specified by:
        toDoubleArray in interface INDArray
        Overrides:
        toDoubleArray in class AMatrix
      • toMatrixTranspose

        public Matrix toMatrixTranspose()
        Description copied from class: AMatrix
        Coerces the transpose of a matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.
        Overrides:
        toMatrixTranspose in class AMatrix
      • toDoubleBuffer

        public void toDoubleBuffer(java.nio.DoubleBuffer dest)
        Description copied from interface: INDArray
        Copies the elements of this INDArray to the specified double buffer.
        Specified by:
        toDoubleBuffer in interface INDArray
        Overrides:
        toDoubleBuffer in class AMatrix
      • asDoubleArray

        public double[] asDoubleArray()
        Description copied from interface: INDArray
        Returns the underlying double array representing the densely packed elements of this array. Modifications to this double array will change the original array. Returns null if there is no such array.
        Specified by:
        asDoubleArray in interface INDArray
        Overrides:
        asDoubleArray in class AStridedMatrix
      • get

        public double get(int i,
                          int j)
        Description copied from interface: INDArray
        Returns the double value at the specified position in a 2D matrix
        Specified by:
        get in interface INDArray
        Specified by:
        get in interface IMatrix
        Overrides:
        get in class AArrayMatrix
      • unsafeSet

        public void unsafeSet(int i,
                              int j,
                              double value)
        Description copied from class: AMatrix
        Sets an element value in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.
        Overrides:
        unsafeSet in class ADenseArrayMatrix
      • unsafeGet

        public double unsafeGet(int i,
                                int j)
        Description copied from class: AMatrix
        Gets an element in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.
        Overrides:
        unsafeGet in class ADenseArrayMatrix
        Returns:
      • addAt

        public void addAt(int i,
                          int j,
                          double d)
        Description copied from interface: IMatrix
        Adds a value at a specific position in the matrix, mutating the matrix Does not perform bounds checking - this in an unsafe operation
        Specified by:
        addAt in interface IMatrix
        Overrides:
        addAt in class AMatrix
      • set

        public void set(int i,
                        int j,
                        double value)
        Description copied from interface: INDArray
        Sets a value at a given position in a mutable 2D array
        Specified by:
        set in interface INDArray
        Specified by:
        set in interface IMatrix
        Overrides:
        set in class ARectangularMatrix
      • applyOp

        public void applyOp(Op op)
        Description copied from interface: INDArray
        Applies a unary operator to all elements of the array (in-place)
        Specified by:
        applyOp in interface INDArray
        Overrides:
        applyOp in class AStridedMatrix
      • applyOp

        public void applyOp(Op2 op,
                            double b)
        Description copied from interface: INDArray
        Applies a binary operator to this array and a double value. Works as if the double value was broadcast to the shape of this array.
        Specified by:
        applyOp in interface INDArray
        Overrides:
        applyOp in class AMatrix
      • setMultiple

        public void setMultiple(Matrix m,
                                double factor)
      • add

        public void add(AMatrix m)
        Description copied from class: AMatrix
        Adds another matrix to this matrix. Matrices must be the same size.
        Overrides:
        add in class ADenseArrayMatrix
      • add2

        public void add2(AMatrix a,
                         AMatrix b)
        Description copied from interface: IMatrix
        Adds two matrices to this matrix. May be better optimised than adding both matrices individually.
        Specified by:
        add2 in interface IMatrix
        Overrides:
        add2 in class AMatrix
      • scale

        public static void scale(Matrix dest,
                                 Matrix src,
                                 double factor)
      • scaleAdd

        public static void scaleAdd(Matrix dest,
                                    Matrix a,
                                    Matrix b,
                                    double bFactor)
      • addMultiple

        public void addMultiple(AMatrix m,
                                double factor)
        Description copied from class: AMatrix
        Adds a scalar multiple of another matrix to this matrix
        Overrides:
        addMultiple in class AMatrix
      • add

        public void add(double d)
        Description copied from interface: INDArray
        Adds a double value to all elements in this array. Implementations may optimize the case of 0.0
        Specified by:
        add in interface INDArray
        Overrides:
        add in class AMatrix
      • multiply

        public void multiply(double factor)
        Description copied from interface: INDArray
        Multiplies all elements of the array in place by a given double value
        Specified by:
        multiply in interface INDArray
        Overrides:
        multiply in class AMatrix
      • set

        public void set(AMatrix a)
        Description copied from class: AMatrix
        Sets this matrix with the element values from another matrix. Source matrix must have the same shape.
        Overrides:
        set in class ADenseArrayMatrix
      • set

        public void set(AVector a)
        Description copied from class: AMatrix
        Sets every row of this matrix with the element values from a vector.
        Overrides:
        set in class ADenseArrayMatrix
      • getElements

        public void getElements(double[] dest,
                                int offset)
        Description copied from interface: INDArray
        Copies all elements of this array a double array at the specified offset
        Specified by:
        getElements in interface INDArray
        Overrides:
        getElements in class AMatrix
      • elementIterator

        public java.util.Iterator<java.lang.Double> elementIterator()
        Description copied from interface: INDArray
        Returns an iterator over all elements in this array, in row-major order
        Specified by:
        elementIterator in interface INDArray
        Overrides:
        elementIterator in class AStridedMatrix
      • getTranspose

        public DenseColumnMatrix getTranspose()
        Description copied from interface: INDArray
        Returns the transpose of this array. A transpose of an array is equivalent to reversing the order of dimensions. May or may not return a view depending on the array type.
        Specified by:
        getTranspose in interface INDArray
        Specified by:
        getTranspose in interface IMatrix
        Overrides:
        getTranspose in class AStridedMatrix
        Returns:
        the transpose of this matrix
      • fill

        public void fill(double value)
        Description copied from interface: INDArray
        Fills this array with a single double value. Requires the array to be mutable.
        Specified by:
        fill in interface INDArray
        Overrides:
        fill in class AMatrix
      • reciprocal

        public void reciprocal()
        Description copied from interface: INDArray
        Replaces all elements in the array with their reciprocal
        Specified by:
        reciprocal in interface INDArray
        Overrides:
        reciprocal in class AMatrix
      • clamp

        public void clamp(double min,
                          double max)
        Description copied from interface: INDArray
        Clamps all the elements of this array within the specified [min,max] range
        Specified by:
        clamp in interface INDArray
        Overrides:
        clamp in class AMatrix
      • copy

        public Matrix copy()
        Description copied from interface: INDArray
        Returns a defensive copy of the array data. Use this if the original array might change and you need a defensive copy. May return the same array if the original was immutable, otherwise will return a defensive copy.
        Specified by:
        copy in interface INDArray
        Overrides:
        copy in class AMatrix
      • exactClone

        public Matrix exactClone()
        Description copied from interface: INDArray
        Creates a deep clone of an array, using the same class implementation as the original array
        Specified by:
        exactClone in interface INDArray
        Specified by:
        exactClone in class AMatrix
        Returns:
        A clone of the original array
      • setRow

        public void setRow(int i,
                           AVector row)
        Description copied from class: AMatrix
        Sets a row in a matrix to the value specified by the given vector
        Overrides:
        setRow in class ADenseArrayMatrix
      • setColumn

        public void setColumn(int j,
                              AVector col)
        Description copied from class: AMatrix
        Sets a column in a matrix.
        Overrides:
        setColumn in class AMatrix
      • getBand

        public StridedVector getBand(int band)
        Description copied from class: AMatrix
        Gets a specific band of the matrix, as a view vector. The band is truncated at the edges of the matrix, i.e. it does not wrap around the matrix.
        Specified by:
        getBand in interface IMatrix
        Overrides:
        getBand in class AStridedMatrix
        Returns:
      • createIdentity

        public static Matrix createIdentity(int numRows,
                                            int numCols)
        Creates a Matrix which contains ones along the main diagonal and zeros everywhere else. If square, is equal to the identity matrix.
        Parameters:
        numRows - Number of rows in the matrix.
        numCols - Number of columns in the matrix.
        Returns:
        A matrix with diagonal elements equal to one.
      • createIdentity

        public static Matrix createIdentity(int dims)

        Creates a square mutable dense identity Matrix of the specified size.

        aij = 0 if i ≠ j
        aij = 1 if i = j

        Returns:
        A new instance of an identity matrix.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.