Class DenseMatrix

  • All Implemented Interfaces:
    Matrix

    public class DenseMatrix
    extends AbstractMatrix
    Dense matrix implementation based on an array of rowCount * columnCount double values.
    Author:
    Geoffroy Jamgotchian
    • Constructor Detail

      • DenseMatrix

        public DenseMatrix​(int rowCount,
                           int columnCount,
                           double[] values)
      • DenseMatrix

        public DenseMatrix​(int rowCount,
                           int columnCount)
      • DenseMatrix

        public DenseMatrix​(int rowCount,
                           int columnCount,
                           Supplier<ByteBuffer> bufferSupplier)
      • DenseMatrix

        public DenseMatrix​(Jama.Matrix matrix)
    • Method Detail

      • get

        public double get​(int i,
                          int j)
        Get value at row i and column j.
        Parameters:
        i - row index
        j - column index
        Returns:
        value at row i and column j
      • set

        public void set​(int i,
                        int j,
                        double value)
        Description copied from interface: Matrix
        Set value at row i and column j.
        Parameters:
        i - row index
        j - column index
        value - the value to set at row i and column j
      • add

        public void add​(int i,
                        int j,
                        double value)
        Description copied from interface: Matrix
        Add value at row i and column j.
        Parameters:
        i - row index
        j - column index
        value - the value to add at row i and column j
      • addAndGetElement

        public Matrix.Element addAndGetElement​(int i,
                                               int j,
                                               double value)
        Description copied from interface: Matrix
        Add value at row i and column j and get an #Element to later update the element.
        Parameters:
        i - row index
        j - column index
        value - the value to add at row i and column j
        Returns:
        an element at row i and column j
      • addAndGetIndex

        public int addAndGetIndex​(int i,
                                  int j,
                                  double value)
        Description copied from interface: Matrix
        Add value at row i and column j and get an element index to later update the element.
        Parameters:
        i - row index
        j - column index
        value - the value to add at row i and column j
        Returns:
        an element index corresponding to row i and column j
      • setAtIndex

        public void setAtIndex​(int index,
                               double value)
        Description copied from interface: Matrix
        Set value at element index index.
        Parameters:
        index - element index
        value - the value to set at element index index
      • setQuickAtIndex

        public void setQuickAtIndex​(int index,
                                    double value)
        Description copied from interface: Matrix
        Set value at element index index without doing any bound checking.
        Parameters:
        index - element index
        value - the value to set at element index index
      • addAtIndex

        public void addAtIndex​(int index,
                               double value)
        Description copied from interface: Matrix
        Add value at element index index.
        Parameters:
        index - element index
        value - the value to add at element index index
      • addQuickAtIndex

        public void addQuickAtIndex​(int index,
                                    double value)
        Description copied from interface: Matrix
        Add value at element index index without doing any bound checking.
        Parameters:
        index - element index
        value - the value to add at element index index
      • reset

        public void reset()
        Description copied from interface: Matrix
        Fill matrix with zeros.
      • getRowCount

        public int getRowCount()
        Description copied from interface: Matrix
        Get row count.
        Returns:
        row count
      • getColumnCount

        public int getColumnCount()
        Description copied from interface: Matrix
        Get column count.
        Returns:
        column count
      • decomposeLU

        public LUDecomposition decomposeLU()
        Description copied from interface: Matrix
        Get LU decomposition utility class for this matrix.
        Returns:
        LU decomposition utility class for this matrix
      • times

        public Matrix times​(Matrix other,
                            double scalar)
        Description copied from interface: Matrix
        Multiply the matrix by another one and by a scalar (this*other*scalar). The resulting matrix has the same implementation as this matrix.
        Parameters:
        other - the other matrix
        scalar - a scalar to multiply the result matrix
        Returns:
        the result of the multiplication of this matrix by the other one
      • add

        public Matrix add​(Matrix other,
                          double alpha,
                          double beta)
        Description copied from interface: Matrix
        Addition the matrix with another one (alpha * this + beta * other). The resulting matrix has the same implementation as this matrix.
        Parameters:
        other - the other matrix
        alpha - a scalar to multiply this matrix
        beta - a scalar to multiply other matrix
        Returns:
        the result of the addition of this matrix and the other one
      • toDense

        public DenseMatrix toDense()
        Description copied from interface: Matrix
        Copy this matrix using a dense implementation. If already a dense matrix, this method is allowed to return this.
        Returns:
        a copy of the matrix with a dense implementation.
      • toSparse

        public SparseMatrix toSparse()
        Description copied from interface: Matrix
        Copy this matrix using a sparse implementation. If already a sparse matrix, this method is allowed to return this.
        Returns:
        a copy of the matrix with a sparse implementation.
      • to

        public Matrix to​(MatrixFactory factory)
        Description copied from interface: Matrix
        Copy this matrix using another implementation. If already with the right implementation, this method is allowed to return this.
        Parameters:
        factory - a matrix factory to create the copy.
        Returns:
        a copy of the matrix
      • getEstimatedNonZeroValueCount

        protected int getEstimatedNonZeroValueCount()
        Description copied from class: AbstractMatrix
        Get an estimation of non zero value count.
        Specified by:
        getEstimatedNonZeroValueCount in class AbstractMatrix
        Returns:
        an estimation of non zero value count
      • transpose

        public DenseMatrix transpose()
        Description copied from interface: Matrix
        Calculate the transposed matrix.
        Returns:
        the transposed matrix
      • print

        public void print​(PrintStream out)
        Description copied from interface: Matrix
        Print the matrix to a stream.
        Parameters:
        out - the stream
      • print

        public void print​(PrintStream out,
                          List<String> rowNames,
                          List<String> columnNames)
        Description copied from interface: Matrix
        Print the matrix to a stream. Row and column names are also printed to facilitate debugging.
        Parameters:
        out - the stream
        rowNames - row names
        columnNames - column names
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object