Class DenseMatrix

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Double>
    Direct Known Subclasses:
    Basic1DMatrix, Basic2DMatrix

    public abstract class DenseMatrix
    extends Matrix
    • Constructor Detail

      • DenseMatrix

        public DenseMatrix​(int rows,
                           int columns)
    • Method Detail

      • zero

        public static DenseMatrix zero​(int rows,
                                       int columns)
        Creates a zero DenseMatrix of the given shape: rows x columns.
      • constant

        public static DenseMatrix constant​(int rows,
                                           int columns,
                                           double constant)
        Creates a constant DenseMatrix of the given shape and value.
      • diagonal

        public static DenseMatrix diagonal​(int size,
                                           double diagonal)
        Creates a diagonal DenseMatrix of the given size whose diagonal elements are equal to diagonal.
      • unit

        public static DenseMatrix unit​(int rows,
                                       int columns)
        Creates an unit DenseMatrix of the given shape: rows x columns.
      • identity

        public static DenseMatrix identity​(int size)
        Creates an identity DenseMatrix of the given size.
      • random

        public static DenseMatrix random​(int rows,
                                         int columns,
                                         java.util.Random random)
        Creates a random DenseMatrix of the given shape: rows x columns.
      • randomSymmetric

        public static DenseMatrix randomSymmetric​(int size,
                                                  java.util.Random random)
        Creates a random symmetric DenseMatrix of the given size.
      • from1DArray

        public static DenseMatrix from1DArray​(int rows,
                                              int columns,
                                              double[] array)
        Creates a DenseMatrix of the given 1D array w/o copying the underlying array.
      • from2DArray

        public static DenseMatrix from2DArray​(double[][] array)
        Creates a DenseMatrix of the given 2D array w/o copying the underlying array.
      • fromCSV

        public static DenseMatrix fromCSV​(java.lang.String csv)
        Parses DenseMatrix from the given CSV string.
        Parameters:
        csv - the CSV string representing a matrix
        Returns:
        a parsed matrix
      • fromMatrixMarket

        public static DenseMatrix fromMatrixMarket​(java.lang.String mm)
        Parses DenseMatrix from the given Matrix Market string.
        Parameters:
        mm - the string in Matrix Market format
        Returns:
        a parsed matrix
      • toArray

        public abstract double[][] toArray()
        Converts this dense matrix to double array.
        Returns:
        an array representation of this matrix
      • getRow

        public Vector getRow​(int i)
        Description copied from class: Matrix
        Copies the specified row of this matrix into the vector.
        Specified by:
        getRow in class Matrix
        Parameters:
        i - the row index
        Returns:
        the row represented as vector
      • getColumn

        public Vector getColumn​(int j)
        Description copied from class: Matrix
        Copies the specified column of this matrix into the vector.
        Specified by:
        getColumn in class Matrix
        Parameters:
        j - the column index
        Returns:
        the column represented as vector
      • apply

        public <T> T apply​(MatrixOperation<T> operation)
        Description copied from class: Matrix
        Pipes this matrix to a given operation.
        Specified by:
        apply in class Matrix
        Type Parameters:
        T - the result type
        Parameters:
        operation - the matrix operation (an operation that takes a matrix and returns T)
        Returns:
        the result of an operation applied to this matrix
      • apply

        public <T> T apply​(MatrixMatrixOperation<T> operation,
                           Matrix that)
        Description copied from class: Matrix
        Pipes this matrix to a given operation.
        Specified by:
        apply in class Matrix
        Type Parameters:
        T - the result type
        Parameters:
        operation - the matrix-matrix operation (an operation that takes two matrices and returns T)
        that - the right hand matrix of the given operation
        Returns:
        the result of an operation applied to this matrix
      • apply

        public <T> T apply​(MatrixVectorOperation<T> operation,
                           Vector that)
        Description copied from class: Matrix
        Pipes this matrix to a given operation.
        Specified by:
        apply in class Matrix
        Type Parameters:
        T - the result type
        Parameters:
        operation - the matrix-vector operation (an operation that takes matrix and vector and returns T)
        that - the right hand vector of the given operation
        Returns:
        the result of an operation applied to this matrix
      • toMatrixMarket

        public java.lang.String toMatrixMarket​(java.text.NumberFormat formatter)
        Description copied from class: Matrix
        Converts this matrix into the Matrix Market string using the given number formatter.
        Specified by:
        toMatrixMarket in class Matrix
        Returns:
        a string in Matrix Market format representing this matrix;