Documentation of 'mikera.matrixx.impl.SparseColumnMatrix' Java class
SparseColumnMatrix
mikera.matrixx.impl

Class SparseColumnMatrix

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, INDArray, ISparse, IMatrix, IFastColumns


    public class SparseColumnMatrix
    extends ASparseRCMatrix
    implements ISparse, IFastColumns
    Matrix stored as a collection of normally sparse column vectors This format is especially efficient for: - transposeInnerProduct() with another matrix - access via getColumn() operation - transpose into SparseRowMatrix
    See Also:
    Serialized Form
    • Method Detail

      • create

        public static SparseColumnMatrix create(AVector... vecs)
        Create a SparseColumnMatrix wrapping a specified array of columns null may be provided after first row
        Parameters:
        vecs -
        Returns:
      • componentCount

        public int componentCount()
        Description copied from interface: INDArray
        Returns the number of components of this array. May return 0 if components are not supported
        Specified by:
        componentCount in interface INDArray
        Specified by:
        componentCount in class ASparseRCMatrix
        Returns:
      • getComponent

        public AVector getComponent(int k)
        Description copied from interface: INDArray
        Gets a component from the array at the specified index Will throw an error if components are not supported, or if the component is out of bounds as defined by 0 <= k
        Specified by:
        getComponent in interface INDArray
        Specified by:
        getComponent in class ASparseRCMatrix
        Returns:
      • 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
        Specified by:
        get 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
      • unsafeGet

        public double unsafeGet(int row,
                                int column)
        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 AMatrix
        Returns:
      • 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 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 AMatrix
      • setColumn

        public void setColumn(int i,
                              AVector col)
        Description copied from class: AMatrix
        Sets a column in a matrix.
        Overrides:
        setColumn in class AMatrix
      • 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
      • addToArray

        public void addToArray(double[] targetData,
                               int offset)
        Description copied from interface: INDArray
        Adds all the elements of this array to a double array at the specified offset, in row-major order
        Specified by:
        addToArray in interface INDArray
        Overrides:
        addToArray in class AMatrix
      • 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
      • applyOp

        public void applyOp(IOperator 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 AMatrix
        Parameters:
        op - The operator to apply to the array
      • 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 ASparseRCMatrix
      • reduce

        public double reduce(Op2 op,
                             double init)
        Description copied from interface: INDArray
        Reduces over all elements of the array in row-major order. Applies the operator to the initial/previous result at each step. Returns the final result.
        Specified by:
        reduce in interface INDArray
        Overrides:
        reduce in class AMatrix
      • getRows

        public java.util.List<AVector> getRows()
        Description copied from interface: IMatrix
        Gets a List of rows of a matrix. May return either copies or views, depending on the specific matrix type.
        Specified by:
        getRows in interface IMatrix
        Overrides:
        getRows in class AMatrix
        Returns:
      • toSparseRowMatrix

        public SparseRowMatrix toSparseRowMatrix()
        Coerces this matrix into a SparseRowMatrix format.
        Returns:
      • getColumn

        public AVector getColumn(int j)
        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
        Specified by:
        getColumn in interface IFastColumns
        Overrides:
        getColumn in class AMatrix
      • getColumnView

        public AVector getColumnView(int j)
        Description copied from interface: IMatrix
        Returns a column of the matrix as a vector view. May be used to modify the original matrix.
        Specified by:
        getColumnView in interface IMatrix
        Overrides:
        getColumnView in class AMatrix
      • isLowerTriangular

        public boolean isLowerTriangular()
        Description copied from class: AMatrix
        Returns true if a matrix is lower triangular. A lower triangular matrix is defined as having all elements equal to 0.0 where i < j
        Overrides:
        isLowerTriangular 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
      • replaceColumn

        public void replaceColumn(int i,
                                  AVector vec)
        Description copied from class: AMatrix
        Replaces a column in a matrix, adding the column to the internal structure of the matrix. Will throw UnsupportedOperationException if not possible for the given matrix type.
        Overrides:
        replaceColumn in class AMatrix
      • add

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

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

        public void copyColumnTo(int i,
                                 double[] targetData,
                                 int offset)
        Description copied from class: AMatrix
        Copies the elements in a selected row of this matrix to a double array
        Overrides:
        copyColumnTo in class ASparseRCMatrix
        targetData - Destination double[] array
      • copyRowTo

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

        public AMatrix multiplyCopy(double a)
        Description copied from interface: INDArray
        Returns a copy of the array with all elements multiplied by a single constant value
        Specified by:
        multiplyCopy in interface INDArray
        Overrides:
        multiplyCopy in class AMatrix
        Parameters:
        a - A scalar factor
        Returns:
        A new array, with all element values scaled by the given factor
      • innerProduct

        public AMatrix 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:
      • innerProduct

        public Vector innerProduct(Vector a)
        Description copied from interface: IMatrix
        Transforms a dense source Vector using matrix multiplication (inner product).
        Specified by:
        innerProduct in interface IMatrix
        Overrides:
        innerProduct in class AMatrix
        Returns:
        A new dense vector
      • 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
      • exactClone

        public SparseColumnMatrix 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
      • clone

        public AMatrix clone()
        Description copied from interface: INDArray
        Returns a clone of the array data, as a new array which will be fully mutable and may be of a different class to the original. Clone should attempt to return the most efficient possible array type. Clone should preserve sparsity property where possible, but this is not guaranteed.
        Specified by:
        clone in interface INDArray
        Overrides:
        clone in class AMatrix
      • sparse

        public AMatrix sparse()
        Description copied from interface: INDArray
        Coerces this INDArray to a sparse format, without changing its element values. May return the same INDArray if already sparse. May also mutate the internal structure of the original NDArray, or create a view over parts of the original INDArray. You should take a defensive copy of the original NDArray if any of this concerns you. The returned sparse array may not be fully mutable in all elements.
        Specified by:
        sparse in interface INDArray
        Overrides:
        sparse in class ASparseRCMatrix
      • validate

        public void validate()
        Description copied from interface: INDArray
        Validates the internal data structure of the INDArray. Throws an exception on failure. Failure indicates a serious bug and/or data corruption.
        Specified by:
        validate in interface INDArray
        Overrides:
        validate in class ASparseRCMatrix
      • equals

        public boolean equals(AMatrix m)
        Description copied from class: AMatrix
        Returns true if this matrix is exactly equal to another matrix
        Overrides:
        equals in class AMatrix
      • equals

        public boolean equals(IFastColumns m)
        Compares this matrix to another matrix implementing IFastColumns This is much faster than the default equals
        Parameters:
        m -
        Returns:
      • equalsArray

        public boolean equalsArray(double[] data,
                                   int offset)
        Description copied from interface: INDArray
        Returns true if the elements in this array exactly match the elements in the given array, in row-major order
        Specified by:
        equalsArray in interface INDArray
        Overrides:
        equalsArray in class AMatrix
        Parameters:
        data - Array of double element values to check for equality
        offset - Offset into the data array
        Returns:

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.