Documentation of 'smile.math.matrix.SparseMatrix' Java class
SparseMatrix
smile.math.matrix

Class SparseMatrix

  • All Implemented Interfaces:
    java.io.Serializable, MatrixMultiplication<SparseMatrix,SparseMatrix>


    public class SparseMatrix
    extends Matrix
    implements MatrixMultiplication<SparseMatrix,SparseMatrix>
    A sparse matrix is a matrix populated primarily with zeros. Conceptually, sparsity corresponds to systems which are loosely coupled. Huge sparse matrices often appear when solving partial differential equations.

    Operations using standard dense matrix structures and algorithms are slow and consume large amounts of memory when applied to large sparse matrices. Indeed, some very large sparse matrices are infeasible to manipulate with the standard dense algorithms. Sparse data is by nature easily compressed, and this compression almost always results in significantly less computer data storage usage.

    This class employs Harwell-Boeing column-compressed sparse matrix format. Nonzero values are stored in an array (top-to-bottom, then left-to-right-bottom). The row indices corresponding to the values are also stored. Besides, a list of pointers are indexes where each column starts. This format is efficient for arithmetic operations, column slicing, and matrix-vector products. One typically uses SparseDataset for construction of SparseMatrix.

    See Also:
    Serialized Form
    • Constructor Detail

      • SparseMatrix

        public SparseMatrix(int nrows,
                            int ncols,
                            double[] x,
                            int[] rowIndex,
                            int[] colIndex)
        Constructor.
        Parameters:
        nrows - the number of rows in the matrix.
        ncols - the number of columns in the matrix.
        rowIndex - the row indices of nonzero values.
        colIndex - the index of the start of columns.
        x - the array of nonzero values stored column by column.
      • SparseMatrix

        public SparseMatrix(double[][] D)
        Constructor.
        Parameters:
        D - a dense matrix to converted into sparse matrix format.
      • SparseMatrix

        public SparseMatrix(double[][] D,
                            double tol)
        Constructor.
        Parameters:
        D - a dense matrix to converted into sparse matrix format.
        tol - the tolerance to regard a value as zero if |x| < tol.
    • Method Detail

      • nrows

        public int nrows()
        Description copied from class: Matrix
        Returns the number of rows.
        Specified by:
        nrows in class Matrix
      • ncols

        public int ncols()
        Description copied from class: Matrix
        Returns the number of columns.
        Specified by:
        ncols in class Matrix
      • size

        public int size()
        Returns the number of nonzero values.
      • values

        public double[] values()
        Returns all nonzero values.
        Returns:
        all nonzero values
      • get

        public double get(int i,
                          int j)
        Description copied from class: Matrix
        Returns the entry value at row i and column j.
        Specified by:
        get in class Matrix
      • ax

        public double[] ax(double[] x,
                           double[] y)
        Description copied from class: Matrix
        y = A * x
        Specified by:
        ax in class Matrix
        Returns:
        y
      • axpy

        public double[] axpy(double[] x,
                             double[] y)
        Description copied from class: Matrix
        y = A * x + y
        Specified by:
        axpy in class Matrix
        Returns:
        y
      • axpy

        public double[] axpy(double[] x,
                             double[] y,
                             double b)
        Description copied from class: Matrix
        y = A * x + b * y
        Specified by:
        axpy in class Matrix
        Returns:
        y
      • atx

        public double[] atx(double[] x,
                            double[] y)
        Description copied from class: Matrix
        y = A' * x
        Specified by:
        atx in class Matrix
        Returns:
        y
      • atxpy

        public double[] atxpy(double[] x,
                              double[] y)
        Description copied from class: Matrix
        y = A' * x + y
        Specified by:
        atxpy in class Matrix
        Returns:
        y
      • atxpy

        public double[] atxpy(double[] x,
                              double[] y,
                              double b)
        Description copied from class: Matrix
        y = A' * x + b * y
        Specified by:
        atxpy in class Matrix
        Returns:
        y
      • diag

        public double[] diag()
        Description copied from class: Matrix
        Returns the diagonal elements.
        Overrides:
        diag in class Matrix

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.