maspack.matrix
Class SparseMatrixBase

java.lang.Object
  extended by maspack.matrix.MatrixBase
      extended by maspack.matrix.SparseMatrixBase
All Implemented Interfaces:
LinearTransformNd, Matrix, SparseMatrix
Direct Known Subclasses:
SparseBlockMatrix, SparseMatrixCRS, SparseMatrixNd

public abstract class SparseMatrixBase
extends MatrixBase
implements SparseMatrix

Base implementation of Matrix.


Nested Class Summary
 
Nested classes/interfaces inherited from interface maspack.matrix.Matrix
Matrix.Partition, Matrix.WriteFormat
 
Field Summary
 
Fields inherited from interface maspack.matrix.Matrix
INDEFINITE, POSITIVE_DEFINITE, SPD, SYMMETRIC
 
Constructor Summary
SparseMatrixBase()
           
 
Method Summary
 void set(Matrix M)
          Sets the size and values of this matrix to those of another matrix.
 void setCCSValues(double[] vals, int[] rowIdxs, int[] colOffs, int nvals, int ncols, Matrix.Partition part)
          Sets the contents of this matrix given a set of values in compressed column storage (CCS).
 void setCRSValues(double[] vals, int[] colIdxs, int[] rowOffs, int nvals, int nrows, Matrix.Partition part)
          Sets the contents of this matrix given a set of values in compressed row storage (CRS).
 void setRandom(double lower, double upper, java.util.Random generator)
          Sets this matrix to have a random sparsity structure and values, with between one and four nonzero elements per row.
 void setRandom(double lower, double upper, java.util.Random generator, boolean symmetric)
          Sets this matrix to have a random sparsity structure and values, with between one and four nonzero elements per row.
 
Methods inherited from class maspack.matrix.MatrixBase
colSize, containsNaN, determinant, epsilonEquals, equals, frobeniusNorm, get, get, get, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getColumn, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getDefaultFormat, getRow, getRow, getRow, getSize, getSubMatrix, hasNaN, idString, infinityNorm, isFixedSize, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, oneNorm, rowSize, scan, setCRSValues, setDefaultFormat, setSize, toString, toString, toString, trace, write, write, write, write, write, writeToFile
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface maspack.matrix.SparseMatrix
scale
 
Methods inherited from interface maspack.matrix.Matrix
checkConsistency, colSize, determinant, epsilonEquals, equals, frobeniusNorm, get, get, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getColumn, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getRow, getRow, getRow, getSize, getSubMatrix, infinityNorm, isFixedSize, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, oneNorm, rowSize, scan, set, setSize, toString, trace, write, write, write
 

Constructor Detail

SparseMatrixBase

public SparseMatrixBase()
Method Detail

set

public void set(Matrix M)
Sets the size and values of this matrix to those of another matrix.

Specified by:
set in interface Matrix
Parameters:
M - matrix whose size and values are copied

setCRSValues

public void setCRSValues(double[] vals,
                         int[] colIdxs,
                         int[] rowOffs,
                         int nvals,
                         int nrows,
                         Matrix.Partition part)
Sets the contents of this matrix given a set of values in compressed row storage (CRS). The argument part specifies what portion of the matrix is supplied. If it is Full, then the entire matrix is supplied. If it is Matrix.Partition.UpperTriangular, then only the upper triangular part is assumed to be supplied, and the lower triangular part is set from its transpose (matrix bounds permitting). For Partition.UpperTriangular, supplied entries which are not upper triangular will either be ignored or generate an exception.

All specified data must fit within the current matrix bounds; the matrix is not resized.

CRS data takes the form of three arrays:

vals
An array giving the values of all the non-zero elements in the sparse matrix, in row-major order.
colIdxs
An array giving the column indices of all the non-zero elements in the sparse matrix, in row-major order. The indices are 1-based, so that 1 denotes the first column.
rowOffs
An array of size nrows+1, where nrows is the number of matrix rows, giving the offsets into vals and colIdxs corresponding to the first non-zero element in each row. All values are 1-based, so that first offset value is 1, the second offset value is n+1, where n is the number of non-zero elements in the first row, etc. The final value is set to nvals+1, where nvals is the number of non-zero elements in the matrix.
CRS index data is 1-based because this is the most standard form used by solvers and matrix formats.

Specified by:
setCRSValues in interface Matrix
Parameters:
vals - non-zero element values. This array must have a length equal at least to nvals.
colIdxs - column indices for each non-zero element. This array must have a length equal at least to nvals.
rowOffs - row start offsets into vals and colIdxs. This array must have a length equal at least to nrows+1, where nrows is the number of rows in this matrix.
nvals - number of non-zero values
nrows - number of specified rows. Indicates the maximum value of rowOffs that will be used; will not resize matrix.
part - must be either Full or UpperTriangular.

setCCSValues

public void setCCSValues(double[] vals,
                         int[] rowIdxs,
                         int[] colOffs,
                         int nvals,
                         int ncols,
                         Matrix.Partition part)
Sets the contents of this matrix given a set of values in compressed column storage (CCS). The argument part specifies what portion of the matrix is supplied. If it is Full, then the entire matrix is supplied. If it is Matrix.Partition.LowerTriangular, then only the lower triangular part is assumed to be supplied, and the upper triangular part is set from its transpose (matrix bounds permitting). For Partition.LowerTriangular, supplied entries which are not lower triangular will either be ignored or generate an exception.

All specified data must fit within the current matrix bounds; the matrix is not resized.

CCCS data takes the form of three arrays:

vals
An array giving the values of all the non-zero elements in the sparse matrix, in column-major order.
rowIdxs
An array giving the row indices of all the non-zero elements in the sparse matrix, in column-major order. The indices are 1-based, so that 1 denotes the first row.
colOffs
An array of size ncols+1, where ncols is the number of matrix columns, giving the offsets into vals and colIdxs corresponding to the first non-zero element in each column. All values are 1-based, so that first offset value is 1, the second offset value is n+1, where n is the number of non-zero elements in the first column, etc. The final value is set to nvals+1, where nvals is the number of non-zero elements in the matrix.
CCS index data is 1-based because this is the most standard form used by solvers and matrix formats.

Specified by:
setCCSValues in interface Matrix
Parameters:
vals - non-zero element values. This array must have a length equal at least to nvals.
rowIdxs - row indices for each non-zero element. This array must have a length equal at least to nvals.
colOffs - column start offsets into vals and rowIdxs. This array must have a length equal at least to ncols+1, where ncols is the number of columns in this matrix.
nvals - number of non-zero values
ncols - number of specified columns. Indicates the maximum value of colOffs that will be used; will not resize matrix.
part - must be either Full or LowerTriangular.

setRandom

public void setRandom(double lower,
                      double upper,
                      java.util.Random generator)
Sets this matrix to have a random sparsity structure and values, with between one and four nonzero elements per row.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)
generator - random number generator

setRandom

public void setRandom(double lower,
                      double upper,
                      java.util.Random generator,
                      boolean symmetric)
Sets this matrix to have a random sparsity structure and values, with between one and four nonzero elements per row.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)
generator - random number generator
symmetric - ensure that the resulting structure and values are symmetric. Ignored if the matrix is not square.