maspack.matrix
Class DenseMatrixBase

java.lang.Object
  extended by maspack.matrix.MatrixBase
      extended by maspack.matrix.DenseMatrixBase
All Implemented Interfaces:
DenseMatrix, LinearTransformNd, Matrix
Direct Known Subclasses:
AffineTransform2dBase, AffineTransform3dBase, Matrix1x1, Matrix1x3, Matrix1x6, Matrix2dBase, Matrix2x3, Matrix2x6, Matrix3dBase, Matrix3x1, Matrix3x2, Matrix3x4, Matrix3x6, Matrix4dBase, Matrix4x3, Matrix6dBase, Matrix6x1, Matrix6x2, Matrix6x3, MatrixBlockBase, MatrixNd

public abstract class DenseMatrixBase
extends MatrixBase
implements DenseMatrix

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
DenseMatrixBase()
           
 
Method Summary
 void add(DenseMatrixBase M)
          Adds matrix M to this matrix provided dimensions match
 void checkConsistency()
          Check that the internal structures of this matrix are consistent.
 void set(double[] values)
          Sets the elements of this matrix from an array of doubles.
 void set(double[][] values)
          Sets the elements of this matrix from a 2-dimensional array of doubles.
 void set(double[] values, int[] indices, int numValues)
          Sets the elements of this matrix from an array of doubles and a list of indices.
abstract  void set(int i, int j, double value)
          Sets a single element of this matrix.
 void set(Matrix M)
          Sets the size and values of this matrix to those of another matrix.
 void set(Vector v)
          Sets the size and values of this matrix to correspond to those of vector object.
 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 setColumn(int j, double[] values)
          Sets a column of this matrix from an array of doubles.
 void setColumn(int j, Vector v)
          Sets a column of this matrix from a Vector.
 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 setRow(int i, double[] values)
          Set a row of this matrix from an array of doubles.
 void setRow(int i, Vector v)
          Sets a row of this matrix from a Vector.
 void setSubMatrix(int baseRow, int baseCol, Matrix Msrc)
          Sets a submatrix of this matrix object.
 
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.Matrix
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, setSize, toString, trace, write, write, write
 

Constructor Detail

DenseMatrixBase

public DenseMatrixBase()
Method Detail

set

public abstract void set(int i,
                         int j,
                         double value)
Sets a single element of this matrix.

Specified by:
set in interface DenseMatrix
Parameters:
i - element row index
j - element column index
value - element value

set

public void set(double[] values)
Sets the elements of this matrix from an array of doubles. The elements in the array should be stored using row-major order, so that element (i,j) is stored at location i*colSize()+j.

Specified by:
set in interface DenseMatrix
Parameters:
values - array from which values are copied

set

public void set(double[][] values)
Sets the elements of this matrix from a 2-dimensional array of doubles.

Parameters:
values - array from which values are copied
Throws:
java.lang.IllegalArgumentException - values has inconsistent row sizes
ImproperSizeException - dimensions of values do not match the size of this matrix

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

set

public void set(Vector v)
Sets the size and values of this matrix to correspond to those of vector object.

Specified by:
set in interface DenseMatrix
Parameters:
v - vector whose size and values are copied

set

public void set(double[] values,
                int[] indices,
                int numValues)
Sets the elements of this matrix from an array of doubles and a list of indices. Each value should be associated with two (i,j) index values, which, for the k-th value, are given by indices[k*2] and indices[k*2+1], respectively. All non-specified elements are set to zero.

Specified by:
set in interface Matrix
Parameters:
values - explicit values for specific matrix locations
indices - i and j indices for each explicit value
numValues - number of explicit values

setColumn

public void setColumn(int j,
                      double[] values)
Sets a column of this matrix from an array of doubles.

Specified by:
setColumn in interface DenseMatrix
Parameters:
j - column index
values - array from which column values are copied

setRow

public void setRow(int i,
                   double[] values)
Set a row of this matrix from an array of doubles.

Specified by:
setRow in interface DenseMatrix
Parameters:
i - row index
values - array from which the row is copied

setColumn

public void setColumn(int j,
                      Vector v)
Sets a column of this matrix from a Vector.

Specified by:
setColumn in interface DenseMatrix
Parameters:
j - column index
v - vector from which the column is copied

setRow

public void setRow(int i,
                   Vector v)
Sets a row of this matrix from a Vector.

Specified by:
setRow in interface DenseMatrix
Parameters:
i - row index
v - vector from which the row is copied

setSubMatrix

public void setSubMatrix(int baseRow,
                         int baseCol,
                         Matrix Msrc)
                  throws ImproperSizeException
Sets a submatrix of this matrix object. The first row and column of the submatrix are given by baseRow and baseCol, and the new values are given by the matrix object Msrc. The size of the submatrix is determined by the dimensions of Msrc.

Specified by:
setSubMatrix in interface DenseMatrix
Parameters:
baseRow - index of the first row of the submatrix
baseCol - index of the first column of the submatrix
Msrc - new values for the submatrix.
Throws:
ImproperSizeException - if baseRow or baseCol are negative, or if the submatrix exceeds the current matrix bounds
See Also:
MatrixNd.copySubMatrix(int, int, int, int, maspack.matrix.Matrix, int, int)

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.

checkConsistency

public void checkConsistency()
Check that the internal structures of this matrix are consistent. Used for testing.

Specified by:
checkConsistency in interface Matrix

add

public void add(DenseMatrixBase M)
Adds matrix M to this matrix provided dimensions match

Parameters:
M - matrix to add to this