Interface Matrix

  • All Known Implementing Classes:
    AbstractMatrix, DenseMatrix, SparseMatrix

    public interface Matrix
    Interface for all double typed matrix implementation. It has been designed to be generic enough to allow dense and sparse matrix implementations. In the case of sparse matrix additional usage constraint could be added and specified in the javadoc for instance in the order a matrix has to be filled.
    Author:
    Geoffroy Jamgotchian
    • Method Detail

      • createFromColumn

        static Matrix createFromColumn​(double[] c,
                                       MatrixFactory matrixFactory)
        Utility method for creating a single column matrix from a java array.
        Parameters:
        c - a column array
        matrixFactory - matrix factory to allow creating the matrix with different implementations.
        Returns:
        the single column matrix
      • createFromRow

        static Matrix createFromRow​(double[] r,
                                    MatrixFactory matrixFactory)
        Utility method for creating a single row matrix from a java array.
        Parameters:
        r - a row array
        matrixFactory - matrix factory to allow creating the matrix with different implementations.
        Returns:
        the single row matrix
      • getRowCount

        int getRowCount()
        Get row count.
        Returns:
        row count
      • getColumnCount

        int getColumnCount()
        Get column count.
        Returns:
        column count
      • set

        void set​(int i,
                 int j,
                 double value)
        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

        void add​(int i,
                 int j,
                 double value)
        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

        Matrix.Element addAndGetElement​(int i,
                                        int j,
                                        double value)
        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

        int addAndGetIndex​(int i,
                           int j,
                           double value)
        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

        void setAtIndex​(int index,
                        double value)
        Set value at element index index.
        Parameters:
        index - element index
        value - the value to set at element index index
      • setQuickAtIndex

        void setQuickAtIndex​(int index,
                             double value)
        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

        void addAtIndex​(int index,
                        double value)
        Add value at element index index.
        Parameters:
        index - element index
        value - the value to add at element index index
      • addQuickAtIndex

        void addQuickAtIndex​(int index,
                             double value)
        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

        void reset()
        Fill matrix with zeros.
      • decomposeLU

        LUDecomposition decomposeLU()
        Get LU decomposition utility class for this matrix.
        Returns:
        LU decomposition utility class for this matrix
      • times

        Matrix times​(Matrix other,
                     double scalar)
        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
      • times

        Matrix times​(Matrix other)
        Multiply the matrix by another one. The resulting matrix has the same implementation as this matrix.
        Parameters:
        other - the other matrix
        Returns:
        the result of the multiplication of this matrix by the other one
      • add

        Matrix add​(Matrix other,
                   double alpha,
                   double beta)
        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
      • add

        Matrix add​(Matrix other)
        Addition the matrix with another one (this + other). The resulting matrix has the same implementation as this matrix.
        Parameters:
        other - the other matrix
        Returns:
        the result of the addition of this matrix and the other one
      • toDense

        DenseMatrix toDense()
        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

        SparseMatrix toSparse()
        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

        Matrix to​(MatrixFactory factory)
        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
      • copy

        Matrix copy​(MatrixFactory factory)
        Copy this matrix using another implementation. This method is not allowed to return this.
        Parameters:
        factory - a matrix factory to create the copy.
        Returns:
        a copy of the matrix
      • transpose

        Matrix transpose()
        Calculate the transposed matrix.
        Returns:
        the transposed matrix
      • print

        void print​(PrintStream out,
                   List<String> rowNames,
                   List<String> columnNames)
        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
      • print

        void print​(PrintStream out)
        Print the matrix to a stream.
        Parameters:
        out - the stream