maspack.matrix
Class MatrixBase

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

public abstract class MatrixBase
extends java.lang.Object
implements LinearTransformNd, Matrix

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
MatrixBase()
           
 
Method Summary
abstract  int colSize()
          Number of columns in the matrix associated with this transformation.
 boolean containsNaN()
          Returns true if any element of this matrix is not a number.
 double determinant()
          Returns the determinant of this matrix, which must be square
 boolean epsilonEquals(Matrix M1, double epsilon)
          Returns true if the elements of this matrix equal those of matrix M1within a prescribed tolerance epsilon.
 boolean equals(Matrix M1)
          Returns true if the elements of this matrix exactly equal those of matrix M1.
 double frobeniusNorm()
          Returns the Frobenius norm of this matrix.
 void get(double[] values)
          Copies the elements of this matrix into an array of doubles.
 void get(double[][] values)
          Copies the elements of this matrix into a 2-dimensional array of doubles.
abstract  double get(int i, int j)
          Gets a single element of this matrix.
 int getCCSIndices(int[] rowIdxs, int[] colOffs, Matrix.Partition part)
          Gets the compressed column storage (CCS) indices for this matrix.
 int getCCSIndices(int[] rowIdxs, int[] colOffs, Matrix.Partition part, int numRows, int numCols)
          Gets the compressed column storage (CCS) indices for a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns.
 int getCCSValues(double[] vals, Matrix.Partition part)
          Gets the compressed column storage (CCS) values for this matrix, in column-major order.
 int getCCSValues(double[] vals, Matrix.Partition part, int numRows, int numCols)
          Gets the compressed column storage (CCS) values for a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns.
 void getColumn(int j, double[] values)
          Copies a column of this matrix into an array of doubles.
 void getColumn(int j, double[] values, int off)
          Copies a column of this matrix into an array of doubles, starting at a specified offset.
 void getColumn(int j, Vector v)
          Copies a column of this matrix into a Vector.
 int getCRSIndices(int[] colIdxs, int[] rowOffs, Matrix.Partition part)
          Gets the compressed row storage (CRS) indices for this matrix.
 int getCRSIndices(int[] colIdxs, int[] rowOffs, Matrix.Partition part, int numRows, int numCols)
          Gets the compressed row storage (CRS) indices for a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns.
 int getCRSValues(double[] vals, Matrix.Partition part)
          Gets the compressed row storage (CRS) values for this matrix, in row-major order.
 int getCRSValues(double[] vals, Matrix.Partition part, int numRows, int numCols)
          Gets the compressed row storage (CRS) values for a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns.
static java.lang.String getDefaultFormat()
          Returns the default format string used in toString.
 void getRow(int i, double[] values)
          Copies a row of this matrix into an array of doubles.
 void getRow(int i, double[] values, int off)
          Copies a row of this matrix into an array of doubles, starting at a specified offset.
 void getRow(int i, Vector v)
          Copies a row of this matrix into a Vector.
 java.lang.String getSize()
          Returns a string indicating the size of this matrix.
 void getSubMatrix(int baseRow, int baseCol, DenseMatrix Mdest)
          Gets a submatrix of this matrix object.
 boolean hasNaN()
          Returns true if one or more elements of this matrix is NaN.
 java.lang.String idString()
           
 double infinityNorm()
          Returns the infinity norm of this matrix.
 boolean isFixedSize()
          Returns true if this matrix is of fixed size.
 boolean isSymmetric(double tol)
          Returns true if this matrix is symmetric within a given tolerance.
 void mul(VectorNd vr, VectorNd v1)
          Applies this transformation to vector v1 and returns the result in vr.
 void mul(VectorNd vr, VectorNd v1, int nr, int nc)
          Multiplies a submatrix of this matrix by the column vector v1 and places the result in the vector vr.
 void mul(VectorNd vr, VectorNd v1, int r0, int nr, int c0, int nc)
          Multiplies a submatrix of this matrix by the column vector v1 and places the result in the vector vr.
 void mulAdd(VectorNd vr, VectorNd v1)
          Multiplies this matrix by the column vector v1 and adds the result to the vector vr.
 void mulAdd(VectorNd vr, VectorNd v1, int nr, int nc)
          Multiplies a submatrix of this matrix by the column vector v1 and adds the result to the vector vr.
 void mulAdd(VectorNd vr, VectorNd v1, int r0, int nr, int c0, int nc)
          Multiplies a submatrix of this matrix by the column vector v1 and adds the result to the vector vr.
 void mulTranspose(VectorNd vr, VectorNd v1)
          Multiplies the transpose of this matrix by the vector v1 and places the result in vr.
 void mulTranspose(VectorNd vr, VectorNd v1, int nr, int nc)
          Multiplies a submatrix of the transpose of this matrix by the column vector v1 and places the result in the vector vr.
 void mulTranspose(VectorNd vr, VectorNd v1, int r0, int nr, int c0, int nc)
          Multiplies a submatrix of the transpose of this matrix by the column vector v1 and places the result in the vector vr.
 void mulTransposeAdd(VectorNd vr, VectorNd v1)
          Multiplies the transpose of this matrix by the vector v1 and adds the result to vr.
 void mulTransposeAdd(VectorNd vr, VectorNd v1, int nr, int nc)
          Multiplies a submatrix of the transpose of this matrix by the column vector v1 and adds the result to the vector vr.
 void mulTransposeAdd(VectorNd vr, VectorNd v1, int r0, int nr, int c0, int nc)
          Multiplies a submatrix of the transpose of this matrix by the column vector v1 and adds the result to the vector vr.
 int numNonZeroVals()
          Returns the number of non-zero values in this matrix object.
 int numNonZeroVals(Matrix.Partition part, int numRows, int numCols)
          Returns the number of non-zero values for a specified partition of a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns.
 double oneNorm()
          Returns the 1 norm of this matrix.
abstract  int rowSize()
          Number of rows in the matrix associated with this transformation.
 void scan(ReaderTokenizer rtok)
          Sets the contents of this matrix to values read from a ReaderTokenizer.
 void setCRSValues(double[] vals, int[] colIdxs, int[] rowOffs)
          Sets the contents of this matrix given a set of values in compressed row storage (CRS).
static void setDefaultFormat(java.lang.String fmtStr)
          Sets the default format string used in toString.
 void setSize(int numRows, int numCols)
          Sets the size of this matrix.
 java.lang.String toString()
          Returns a String representation of this matrix, using the default format returned by getDefaultFormat.
 java.lang.String toString(NumberFormat fmt)
          Returns a String representation of this matrix, in which each element is formatted using a C printf style format as decribed by the parameter NumberFormat.
 java.lang.String toString(java.lang.String fmtStr)
          Returns a String representation of this matrix, in which each element is formatted using a C printf style format string.
 double trace()
          Returns the trace of this matrix, which must be square
 void write(java.io.PrintWriter pw, NumberFormat fmt)
          Writes the contents of this matrix to a PrintWriter.
 void write(java.io.PrintWriter pw, NumberFormat fmt, Matrix.WriteFormat wfmt)
          Writes the contents of this matrix to a PrintWriter.
 void write(java.io.PrintWriter pw, NumberFormat fmt, Matrix.WriteFormat wfmt, int numRows, int numCols)
          Writes the contents of a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns.
 void write(java.io.PrintWriter pw, java.lang.String msg, Matrix.WriteFormat wfmt)
          Writes the contents of this matrix to a PrintWriter.
 java.io.PrintWriter write(java.lang.String fileName, java.lang.String msg, Matrix.WriteFormat wfmt)
          Writes the contents of this matrix to a specified file, and returns the PrintWriter that was created to do the writing.
 void writeToFile(java.lang.String fileName, java.lang.String fmtStr)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface maspack.matrix.Matrix
checkConsistency, set, set, setCCSValues, setCRSValues
 

Constructor Detail

MatrixBase

public MatrixBase()
Method Detail

setDefaultFormat

public static void setDefaultFormat(java.lang.String fmtStr)
Sets the default format string used in toString. For a description of the format string syntax, see NumberFormat.

Parameters:
fmtStr - new format string
Throws:
java.lang.IllegalArgumentException - if the format string is invalid
See Also:
getDefaultFormat()

getDefaultFormat

public static java.lang.String getDefaultFormat()
Returns the default format string used in toString. If unset, this string is "%g". For a description of the format string syntax, see NumberFormat.

Returns:
Default format string

rowSize

public abstract int rowSize()
Number of rows in the matrix associated with this transformation. This will equal the size of the output vector in mul.

Specified by:
rowSize in interface LinearTransformNd
Specified by:
rowSize in interface Matrix
Returns:
number of rows

colSize

public abstract int colSize()
Number of columns in the matrix associated with this transformation. This will equal the size of the input vector in mul.

Specified by:
colSize in interface LinearTransformNd
Specified by:
colSize in interface Matrix
Returns:
number of columns

get

public abstract double get(int i,
                           int j)
Gets a single element of this matrix.

Specified by:
get in interface Matrix
Parameters:
i - element row index
j - element column index
Returns:
element value

get

public void get(double[] values)
Copies the elements of this matrix into an array of doubles. The elements are stored using row-major order, so that element (i,j) is stored at location i*colSize()+j.

Specified by:
get in interface Matrix
Parameters:
values - array into which values are copied

get

public void get(double[][] values)
Copies the elements of this matrix into a 2-dimensional array of doubles.

Parameters:
values - array into 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

getColumn

public void getColumn(int j,
                      double[] values)
Copies a column of this matrix into an array of doubles.

Specified by:
getColumn in interface Matrix
Parameters:
j - column index
values - array into which the column is copied

getColumn

public void getColumn(int j,
                      double[] values,
                      int off)
Copies a column of this matrix into an array of doubles, starting at a specified offset.

Specified by:
getColumn in interface Matrix
Parameters:
j - column index
values - array into which the column is copied
off - offset in values where copying should begin

getRow

public void getRow(int i,
                   double[] values)
Copies a row of this matrix into an array of doubles.

Specified by:
getRow in interface Matrix
Parameters:
i - row index
values - array into which the row is copied

getRow

public void getRow(int i,
                   double[] values,
                   int off)
Copies a row of this matrix into an array of doubles, starting at a specified offset.

Specified by:
getRow in interface Matrix
Parameters:
i - row index
values - array into which the row is copied
off - offset in values where copying should begin

getColumn

public void getColumn(int j,
                      Vector v)
Copies a column of this matrix into a Vector.

Specified by:
getColumn in interface Matrix
Parameters:
j - column index
v - vector into which the column is copied

getRow

public void getRow(int i,
                   Vector v)
Copies a row of this matrix into a Vector.

Specified by:
getRow in interface Matrix
Parameters:
i - row index
v - vector into which the row is copied

isFixedSize

public boolean isFixedSize()
Returns true if this matrix is of fixed size. If this matrix is not of fixed size, then it can be resized dynamically, either explicitly using setSize, or implicitly when used as a result for various matrix operations.

Specified by:
isFixedSize in interface Matrix
Returns:
true if this matrix is of fixed size
See Also:
Matrix.setSize(int, int)

setSize

public void setSize(int numRows,
                    int numCols)
Sets the size of this matrix. This operation is only supported if isFixedSize returns false.

Specified by:
setSize in interface Matrix
Parameters:
numRows - new row size
numCols - new column size
See Also:
Matrix.isFixedSize()

determinant

public double determinant()
                   throws ImproperSizeException
Returns the determinant of this matrix, which must be square

Specified by:
determinant in interface Matrix
Returns:
matrix determinant
Throws:
ImproperSizeException - if the matrix is not square

trace

public double trace()
             throws ImproperSizeException
Returns the trace of this matrix, which must be square

Specified by:
trace in interface Matrix
Returns:
matrix trace
Throws:
ImproperSizeException - if the matrix is not square

epsilonEquals

public boolean epsilonEquals(Matrix M1,
                             double epsilon)
Returns true if the elements of this matrix equal those of matrix M1within a prescribed tolerance epsilon.

Specified by:
epsilonEquals in interface Matrix
Parameters:
M1 - matrix to compare with
epsilon - comparison tolerance
Returns:
false if the matrices are not equal within the specified tolerance, or have different sizes

equals

public boolean equals(Matrix M1)
Returns true if the elements of this matrix exactly equal those of matrix M1.

Specified by:
equals in interface Matrix
Parameters:
M1 - matrix to compare with
Returns:
false if the matrices are not equal or have different sizes

oneNorm

public double oneNorm()
Returns the 1 norm of this matrix. This is equal to the maximum of the vector 1-norm of each column.

Specified by:
oneNorm in interface Matrix
Returns:
1 norm of this matrix

infinityNorm

public double infinityNorm()
Returns the infinity norm of this matrix. This is equal to the maximum of the vector 1-norm of each row.

Specified by:
infinityNorm in interface Matrix
Returns:
infinity norm of this matrix

frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius norm of this matrix. This is equal to the square root of the sum of the squares of each element.

Specified by:
frobeniusNorm in interface Matrix
Returns:
Frobenius norm of this matrix

toString

public java.lang.String toString()
Returns a String representation of this matrix, using the default format returned by getDefaultFormat.

Overrides:
toString in class java.lang.Object
Returns:
String representation of this matrix
See Also:
toString(String)

idString

public java.lang.String idString()

toString

public java.lang.String toString(java.lang.String fmtStr)
Returns a String representation of this matrix, in which each element is formatted using a C printf style format string. For a description of the format string syntax, see NumberFormat. Note that when called numerous times, toString(NumberFormat) will be more efficient because the NumberFormat will not need to be recreated each time from a specification string.

Parameters:
fmtStr - numeric format specification
Returns:
String representation of this vector

toString

public java.lang.String toString(NumberFormat fmt)
Returns a String representation of this matrix, in which each element is formatted using a C printf style format as decribed by the parameter NumberFormat.

Specified by:
toString in interface Matrix
Parameters:
fmt - numeric format
Returns:
String representation of this vector

writeToFile

public void writeToFile(java.lang.String fileName,
                        java.lang.String fmtStr)

write

public java.io.PrintWriter write(java.lang.String fileName,
                                 java.lang.String msg,
                                 Matrix.WriteFormat wfmt)
                          throws java.io.IOException
Writes the contents of this matrix to a specified file, and returns the PrintWriter that was created to do the writing.

Parameters:
fileName - Path name for the file to written
msg - Optional message - if not null, is printed on a separate line preceeding the matrix information.
wfmt - specifies the matrix output format
Returns:
PrintWriter used to do the writing
Throws:
java.io.IOException

write

public void write(java.io.PrintWriter pw,
                  java.lang.String msg,
                  Matrix.WriteFormat wfmt)
           throws java.io.IOException
Writes the contents of this matrix to a PrintWriter.

Parameters:
pw - PrintWriter to write the matrix to
msg - Optional message - if not null, is printed on a separate line preceeding the matrix information.
wfmt - specifies the matrix output format
Throws:
java.io.IOException

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt)
           throws java.io.IOException
Writes the contents of this matrix to a PrintWriter. Element values are written in a dense-format row-major order, one row per line, separated by spaces. Each value is formatted using a C printf style as described by the parameter NumberFormat.

Specified by:
write in interface Matrix
Parameters:
pw - PrintWriter to write this matrix to
fmt - numeric format
Throws:
java.io.IOException

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt,
                  Matrix.WriteFormat wfmt)
           throws java.io.IOException
Writes the contents of this matrix to a PrintWriter. The overall write format is specified by wfmt, while the values themselves are formatted using a C printf style as decribed by the parameter NumberFormat.

Specified by:
write in interface Matrix
Parameters:
pw - PrintWriter to write this matrix to
fmt - numeric format
wfmt - specifies the general output format
Throws:
java.io.IOException

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt,
                  Matrix.WriteFormat wfmt,
                  int numRows,
                  int numCols)
           throws java.io.IOException
Writes the contents of a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns. The overall write format is specified by wfmt, while the values themselves are formatted using a C printf style as decribed by the parameter NumberFormat.

Specified by:
write in interface Matrix
Parameters:
pw - PrintWriter to write this matrix to
fmt - numeric format
wfmt - specifies the general output format
numRows - number of rows delimiting the sub-matrix
numCols - number of columns delimiting the sub-matrix
Throws:
java.io.IOException

scan

public void scan(ReaderTokenizer rtok)
          throws java.io.IOException
Sets the contents of this matrix to values read from a ReaderTokenizer. Matrix elements may be specified in either a dense or sparse format.

For the dense format, the input should consist of a sequence of numbers, arranged in row-major order, separated by white space, and optionally surrounded by square brackets [ ].

If the input is not surrounded by square brackets, then the number of values should equal the current number of elements in this matrix, as defined by the product of rowSize and colSize.

If the input is surrounded by square brackets, then the matrix dimensions are determined by the input itself: rows should be separated by either semicolons or a newline, the number of values in each row should be the same, and rows are read until a closing square bracket is detected. The resulting input should either match this matrix's dimensions, or this matrix should be resizable to accomodate those dimensions. For example,

 [ 1.2  4   5
   6    3.1 0 ]
 
defines a 2 x 3 matrix.

For the sparse format, the input should be surrounded by square brackets, and each element value is specified as a triple ( i j value ), enclosed in parentheses. No particular ordering is required for the i or j indices, and unspecified elements are set to zero. The entire set of elements should be surrounded by square brackets. For example,

 [ ( 0 0 1.2 )
   ( 0 1 4 )
   ( 0 2 5 )
   ( 1 0 6 )
   ( 1 1 3.1) ]
 
defines that same 2 x 3 matrix given in the previous example.

Specified by:
scan in interface Matrix
Parameters:
rtok - Tokenizer from which matrix values are read. Number parsing should be enabled
Throws:
java.io.IOException

containsNaN

public boolean containsNaN()
Returns true if any element of this matrix is not a number.

Returns:
true if any element is NaN

mul

public void mul(VectorNd vr,
                VectorNd v1)
Applies this transformation to vector v1 and returns the result in vr.

Specified by:
mul in interface LinearTransformNd
Specified by:
mul in interface Matrix
Parameters:
vr - vector in which result is returned
v1 - vector to transform

mul

public void mul(VectorNd vr,
                VectorNd v1,
                int nr,
                int nc)
Multiplies a submatrix of this matrix by the column vector v1 and places the result in the vector vr. The submatrix is defined by the first nr rows and nc columns of this matrix. If M represents this matrix, this is equivalent to computing
  vr = M[0:nr-1][0:nc-1] v1
 
The vector vr is resized if it is not sufficiently large.

Specified by:
mul in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by
nr - number of initial rows of this matrix to use
nc - number of initial columns of this matrix to use

mul

public void mul(VectorNd vr,
                VectorNd v1,
                int r0,
                int nr,
                int c0,
                int nc)
Multiplies a submatrix of this matrix by the column vector v1 and places the result in the vector vr. The submatrix is defined by the nr rows and nc columns of this matrix starting at r0 and c0, respectively. If M represents this matrix, this is equivalent to computing
  vr = M[r0:r0+nr-1][c0:c0+nc-1] v1
 
The vector vr is resized if it is not sufficiently large.

Specified by:
mul in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by
r0 - initial row of the submatrix
nr - number of rows in the submatrix
c0 - initial column of the submatrix
nc - number of columns in the submatrix

mulAdd

public void mulAdd(VectorNd vr,
                   VectorNd v1)
Multiplies this matrix by the column vector v1 and adds the result to the vector vr. If M represents this matrix, this is equivalent to computing
  vr += M v1
 

Specified by:
mulAdd in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by

mulAdd

public void mulAdd(VectorNd vr,
                   VectorNd v1,
                   int nr,
                   int nc)
Multiplies a submatrix of this matrix by the column vector v1 and adds the result to the vector vr. The submatrix is defined by the first nr rows and nc columns of this matrix. If M represents this matrix, this is equivalent to computing
  vr += M[0:nr-1][0:nc-1] v1
 

Specified by:
mulAdd in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by
nr - number of initial rows of this matrix to use
nc - number of initial columns of this matrix to use

mulAdd

public void mulAdd(VectorNd vr,
                   VectorNd v1,
                   int r0,
                   int nr,
                   int c0,
                   int nc)
Multiplies a submatrix of this matrix by the column vector v1 and adds the result to the vector vr. The submatrix is defined by the nr rows and nc columns of this matrix starting at r0 and c0, respectively. If M represents this matrix, this is equivalent to computing
  vr += M[r0:r0+nr-1][c0:c0+nc-1] v1
 

Specified by:
mulAdd in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by
r0 - initial row of the submatrix
nr - number of rows in the submatrix
c0 - initial column of the submatrix
nc - number of columns in the submatrix

mulTranspose

public void mulTranspose(VectorNd vr,
                         VectorNd v1)
Multiplies the transpose of this matrix by the vector v1 and places the result in vr. If M represents this matrix, this is equivalent to computing
  vr = v1 M
 
The vector vr is resized if it is not sufficiently large.

Specified by:
mulTranspose in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by

mulTranspose

public void mulTranspose(VectorNd vr,
                         VectorNd v1,
                         int nr,
                         int nc)
Multiplies a submatrix of the transpose of this matrix by the column vector v1 and places the result in the vector vr. The submatrix is defined by the first nr rows and nc columns of the transpose of this matrix. If M represents this matrix, this is equivalent to computing
  vr = v1 M[0:nc-1][0:nr-1]
 
The vector vr is resized if it is not sufficiently large.

Specified by:
mulTranspose in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by
nr - number of initial rows of the transpose of this matrix to use
nc - number of initial columns of the transpose of this matrix to use

mulTranspose

public void mulTranspose(VectorNd vr,
                         VectorNd v1,
                         int r0,
                         int nr,
                         int c0,
                         int nc)
Multiplies a submatrix of the transpose of this matrix by the column vector v1 and places the result in the vector vr. The submatrix is defined by the nr rows and nc columns of the transpose of this matrix starting at r0 and c0, respectively. If M represents this matrix, this is equivalent to
  vr = v1 M[c0:c0+nc-1][r0:r0+nr-1]
 
The vector vr is resized if it is not sufficiently large.

Specified by:
mulTranspose in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by
r0 - initial row of the submatrix
nr - number of rows in the submatrix
c0 - initial column of the submatrix
nc - number of columns in the submatrix

mulTransposeAdd

public void mulTransposeAdd(VectorNd vr,
                            VectorNd v1)
Multiplies the transpose of this matrix by the vector v1 and adds the result to vr. If M represents this matrix, this is equivalent to computing
  vr += v1 M
 

Specified by:
mulTransposeAdd in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by

mulTransposeAdd

public void mulTransposeAdd(VectorNd vr,
                            VectorNd v1,
                            int nr,
                            int nc)
Multiplies a submatrix of the transpose of this matrix by the column vector v1 and adds the result to the vector vr. The submatrix is defined by the first nr rows and nc columns of the transpose of this matrix. If M represents this matrix, this is equivalent to computing
  vr += v1 M[0:nc-1][0:nr-1]
 

Specified by:
mulTransposeAdd in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by
nr - number of initial rows of the transpose of this matrix to use
nc - number of initial columns of the transpose of this matrix to use

mulTransposeAdd

public void mulTransposeAdd(VectorNd vr,
                            VectorNd v1,
                            int r0,
                            int nr,
                            int c0,
                            int nc)
Multiplies a submatrix of the transpose of this matrix by the column vector v1 and adds the result to the vector vr. The submatrix is defined by the nr rows and nc columns of the transpose of this matrix starting at r0 and c0, respectively. If M represents this matrix, this is equivalent to
  vr += v1 M[c0:c0+nc-1][r0:r0+nr-1]
 

Specified by:
mulTransposeAdd in interface Matrix
Parameters:
vr - result vector
v1 - vector to multiply by
r0 - initial row of the submatrix
nr - number of rows in the submatrix
c0 - initial column of the submatrix
nc - number of columns in the submatrix

hasNaN

public boolean hasNaN()
Returns true if one or more elements of this matrix is NaN.

Returns:
true if one or more elements is NaN

getCRSIndices

public int getCRSIndices(int[] colIdxs,
                         int[] rowOffs,
                         Matrix.Partition part)
Gets the compressed row storage (CRS) indices for this matrix. Indices are 1-based and the matrix is traversed in row-major order. For a detailed decsription of the CRS format, see setCRSValues().

Specified by:
getCRSIndices in interface Matrix
Parameters:
colIdxs - returns the column indices of each non-zero element, in row-major order. This array must have a length equal at least to the number of non-zero elements.
rowOffs - returns the row start offsets into colIdxs, followed by nvals+1, where nvals is the number of non-zero elements. This array must have a length equal at least to nrows+1, where nrows is the number of rows in this matrix.
part - specifies what portion of the matrix to store; must be either Full or UpperTriangular
Returns:
number of non-zero elements

getCRSIndices

public int getCRSIndices(int[] colIdxs,
                         int[] rowOffs,
                         Matrix.Partition part,
                         int numRows,
                         int numCols)
Gets the compressed row storage (CRS) indices for a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns. Indices are 1-based and supplied in row-major order. For a detailed decsription of the CRS format, see setCRSValues(). Some matrix types may place restrictions on the sub-matrix; for instance, a block-structured matrix may require that the sub-matrix be block aligned.

Specified by:
getCRSIndices in interface Matrix
Parameters:
colIdxs - returns the column indices of each non-zero element, in row-major order. This array must have a length equal at least to the number of non-zero elements.
rowOffs - returns the row start offsets into colIdxs, followed by nvals+1, where nvals is the number of non-zero elements in the sub-matrix. This array must have a length equal at least to nrows+1, where nrows is the number of rows in the sub-matrix.
part - specifies what portion of the sub-matrix to store; must be either Full or UpperTriangular
numRows - number of rows delimiting the sub-matrix
numCols - number of columns delimiting the sub-matrix
Returns:
number of non-zero elements

getCRSValues

public int getCRSValues(double[] vals,
                        Matrix.Partition part)
Gets the compressed row storage (CRS) values for this matrix, in row-major order. For a detailed decsription of the CRS format, see setCRSValues().

Specified by:
getCRSValues in interface Matrix
Parameters:
vals - returns the value of each non-zero element. This array must have a length equal at least to the number of non-zero elements.
part - specifies what portion of the matrix to store; must be either Full or UpperTriangular
Returns:
number of non-zero elements

getCRSValues

public int getCRSValues(double[] vals,
                        Matrix.Partition part,
                        int numRows,
                        int numCols)
Gets the compressed row storage (CRS) values for a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns. Values are supplied in row-major order. For a detailed decsription of the CRS format, see setCRSValues(). Some matrix types may place restrictions on the sub-matrix; for instance, a block-structured matrix may require that the sub-matrix be block aligned.

Specified by:
getCRSValues in interface Matrix
Parameters:
vals - returns the value of each non-zero element. This array must have a length equal at least to the number of non-zero elements in the sub-matrix.
part - specifies what portion of the sub-matrix to store; must be either Full or UpperTriangular
numRows - number of rows delimiting the sub-matrix
numCols - number of columns delimiting the sub-matrix
Returns:
number of non-zero elements

setCRSValues

public void setCRSValues(double[] vals,
                         int[] colIdxs,
                         int[] rowOffs)
Sets the contents of this matrix given a set of values in compressed row storage (CRS).

Parameters:
vals - non-zero element values
colIdxs - column indices for each non-zero element
rowOffs - location within vals ( and colIdxs) corresponding to the first non-zero element in each row

getCCSIndices

public int getCCSIndices(int[] rowIdxs,
                         int[] colOffs,
                         Matrix.Partition part)
Gets the compressed column storage (CCS) indices for this matrix. Indices are 1-based and the matrix is traversed in column-major order. For a detailed decsription of the CCS format, see setCCSValues().

Specified by:
getCCSIndices in interface Matrix
Parameters:
rowIdxs - returns the row indices of each non-zero element, in column-major order. This array must have a length equal at least to the number of non-zero elements.
colOffs - returns the column start offsets into rowIdxs, followed by nvals+1, where nvals is the number of non-zero elements. This array must have a length equal at least to ncols+1, where ncols is the number of columns in this matrix.
part - specifies what portion of the matrix to store; must be either Full or LowerTriangular
Returns:
number of non-zero elements

getCCSIndices

public int getCCSIndices(int[] rowIdxs,
                         int[] colOffs,
                         Matrix.Partition part,
                         int numRows,
                         int numCols)
Gets the compressed column storage (CCS) indices for a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns. Indices are 1-based and supplied in column-major order. For a detailed decsription of the CCS format, see setCCSValues(). Some matrix types may place restrictions on the sub-matrix; for instance, a block-structured matrix may require that the sub-matrix be block aligned.

Specified by:
getCCSIndices in interface Matrix
Parameters:
rowIdxs - returns the row indices of each non-zero element, in column-major order. This array must have a length equal at least to the number of non-zero elements.
colOffs - returns the column start offsets into rowIdxs, followed by nvals+1, where nvals is the number of non-zero elements in the sub-matrix. This array must have a length equal at least to ncol+1, where ncols is the number of columns in the sub-matrix.
part - specifies what portion of the sub-matrix to store; must be either Full or LowerTriangular
numRows - number of rows delimiting the sub-matrix
numCols - number of columns delimiting the sub-matrix
Returns:
number of non-zero elements

getCCSValues

public int getCCSValues(double[] vals,
                        Matrix.Partition part)
Gets the compressed column storage (CCS) values for this matrix, in column-major order. For a detailed decsription of the CCS format, see setCCSValues().

Specified by:
getCCSValues in interface Matrix
Parameters:
vals - returns the value of each non-zero element. This array must have a length equal at least to the number of non-zero elements.
part - specifies what portion of the matrix to store; must be either Full or LowerTriangular
Returns:
number of non-zero elements

getCCSValues

public int getCCSValues(double[] vals,
                        Matrix.Partition part,
                        int numRows,
                        int numCols)
Gets the compressed column storage (CCS) values for a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns. Values are supplied in column-major order. For a detailed decsription of the CCS format, see setCCSValues(). Some matrix types may place restrictions on the sub-matrix; for instance, a block-structured matrix may require that the sub-matrix be block aligned.

Specified by:
getCCSValues in interface Matrix
Parameters:
vals - returns the value of each non-zero element. This array must have a length equal at least to the number of non-zero elements in the sub-matrix.
part - specifies what portion of the sub-matrix to store; must be either Full or LowerTriangular
numRows - number of rows delimiting the sub-matrix
numCols - number of columns delimiting the sub-matrix
Returns:
number of non-zero elements

getSubMatrix

public void getSubMatrix(int baseRow,
                         int baseCol,
                         DenseMatrix Mdest)
                  throws ImproperSizeException
Gets a submatrix of this matrix object. The first row and column of the submatrix are given by baseRow and baseCol, and the values are written into the matrix object Mdest. The size of the submatrix is determined by the dimensions of Mdest.

Specified by:
getSubMatrix in interface Matrix
Parameters:
baseRow - first row of the submatrix
baseCol - first column of the submatrix
Mdest - destination for submatrix values
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)

isSymmetric

public boolean isSymmetric(double tol)
Returns true if this matrix is symmetric within a given tolerance. Specifically, each off-diagonal element must equal it's transposed counterpart within the given tolerance.

Specified by:
isSymmetric in interface Matrix
Parameters:
tol - tolerance for checking equality of off-diagonal elements

numNonZeroVals

public int numNonZeroVals()
Returns the number of non-zero values in this matrix object. For dense matrices, this will simply be the product of the number of rows times the number of columns.

Specified by:
numNonZeroVals in interface Matrix
Returns:
number of non-zero values

numNonZeroVals

public int numNonZeroVals(Matrix.Partition part,
                          int numRows,
                          int numCols)
Returns the number of non-zero values for a specified partition of a principal sub-matrix of this matrix delimited by the first numRows rows and the first numCols columns. If the matrix is dense and the partition is Full, then this will simply be the product of the number of rows times the number of columns.

Specified by:
numNonZeroVals in interface Matrix
Parameters:
part - matrix parition to be examined
numRows - number of rows delimiting the sub-matrix
numCols - number of columns delimiting the sub-matrix
Returns:
number of non-zero values

getSize

public java.lang.String getSize()
Returns a string indicating the size of this matrix.

Specified by:
getSize in interface Matrix
Returns:
size of the matrix, in string form