maspack.matrix
Class SparseMatrixCRS

java.lang.Object
  extended by maspack.matrix.MatrixBase
      extended by maspack.matrix.SparseMatrixBase
          extended by maspack.matrix.SparseMatrixCRS
All Implemented Interfaces:
LinearTransformNd, Matrix, SparseMatrix

public class SparseMatrixCRS
extends SparseMatrixBase
implements LinearTransformNd

Implements general sparse matrix using CRS (compressed row storage) format. The structure of the matrix, and the number of nonzero entries, is fixed. This code uses some ideas from Csparse, the sparse matrix package by Tim Davis. IMPORTANT: the internal values of the column indices and row offsets, stored as myCols and myRowOffs, are ZERO-based, as opposed to the convention used by getCRSIndices() and setCRSValues(), in which they are ONE-based.


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
SparseMatrixCRS()
          Creates an empty sparse matrix with 0 size.
SparseMatrixCRS(double[] vals, int[] cols, int[] rowOffs)
          Creates a sparse matrix from CRS data.
SparseMatrixCRS(int numRows, int numCols)
          Creates an empty sparse matrix with a specified size.
SparseMatrixCRS(Matrix M)
          Creates a sparse matrix from an existing general matrix.
 
Method Summary
 void add(int i, int j, double v)
           
 void add(SparseMatrixCRS M)
          Adds this matrix to M and places the result in this matrix.
 void add(SparseMatrixCRS M1, SparseMatrixCRS M2)
          Adds matrix M1 to M2 and places the result in this matrix.
 void addScaledRow(VectorNd v, double s, int i)
          Adds s times the i-th row to the vector v.
 void checkConsistency()
          Check that the internal structures of this matrix are consistent.
 int colSize()
          Number of columns in the matrix associated with this transformation.
 void combine(double a, SparseMatrixCRS M1, double b, SparseMatrixCRS M2)
          Forms the combination a M1 + b M2 and places the result in this matrix.
 double dotRow(int i, VectorNd v)
          Returns the dot product of the i-th row with a vector v.
 double dotRowSelf(int i)
          Returns the dot product of the i-th row with itself.
 void ensureCapacity(int newcap)
          Ensures that the nonzero storage capacity of this matrix is at least n.
 double get(int i, int j)
          Gets a single element of this matrix.
 int getCapacity()
          Returns the nonzero storage capacity of 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, 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.
 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, 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.
 int getNonzeroElements(double[] values)
          Returns the nonzero element values in row-major order.
 boolean isFixedSize()
          Returns true if this matrix is of fixed size.
 void mul(SparseMatrixCRS M)
          Multiplies this matrix by M and places the result in this matrix.
 void mul(SparseMatrixCRS M1, SparseMatrixCRS M2)
          Multiplies matrix M1 by M2 and places the result in this matrix.
 void mulTranspose(SparseMatrixCRS M)
          Multiplies this matrix by the transpose of M and places the result in this matrix.
 void mulTransposeBoth(SparseMatrixCRS M1, SparseMatrixCRS M2)
          Multiplies the transpose of matrix M1 by the transpose of M2 and places the result in this matrix.
 void mulTransposeLeft(SparseMatrixCRS M1, SparseMatrixCRS M2)
          Multiplies the transpose of matrix M1 by M2 and places the result in this matrix.
 void mulTransposeRight(SparseMatrixCRS M1, SparseMatrixCRS M2)
          Multiplies matrix M1 by the transpose of M2 and places the result in this matrix.
 void negate()
          Negates this matrix in place.
 void negate(SparseMatrixCRS M)
          Sets this matrix to the negative of another matrix M.
 int numNonzeroElements()
          Returns the number of nonzero elements in this matrix.
 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.
 int rowSize()
          Number of rows in the matrix associated with this transformation.
 void scale(double s)
          Scales the elements of this matrix by s.
 void scale(double s, SparseMatrixCRS M)
          Scales the elements of matrix M1 by s and places the results in this matrix.
 void scaledAdd(double s, SparseMatrixCRS M1, SparseMatrixCRS M2)
          Computes s M1 + M2 and places the result in this matrix.
 void set(double[] values, int[] indices, int numVals)
          Sets the elements of this matrix from an array of doubles and a list of indices.
 void set(int i, int j, double value)
           
 void set(Matrix M)
          Sets the values of this matrix from an existing general matrix M.
 void set(Matrix M, Matrix.Partition part)
          Sets the values of this matrix from an existing general matrix M, assuming the supplied partition type
 void setCRSValues(double[] vals, int[] colIdxs, int[] rowOffs, int numVals, int numRows, Matrix.Partition part)
          Sets the contents of this matrix given a set of values in compressed row storage (CRS).
 void setDiagonal(double[] vals)
          Sets this matrix to a diagonal matrix whose diagonal elements are specified by an array.
 void setIdentity()
          Sets this matrix to the identity matrix.
 void setNonzeroElements(double[] values)
          Sets the existing nonzero element values, in row-major order.
 void setRandom()
          Sets this matrix to have a random sparsity structure and values, with between one and four nonzero elements per row.
 void setRandomValues()
          Sets the nonzero elements of this matrix to random values in the range -0.5 (inclusive) to 0.5 (exclusive).
 void setRandomValues(double lower, double upper, java.util.Random generator)
          Sets the nonzero elements of this matrix to random values in a specified range.
 void setSize(int numRows, int numCols)
          Sets the size of this matrix.
 void setZero()
          Sets the elements of this matrix to zero.
 void sub(SparseMatrixCRS M)
          Subtracts M from this matrix.
 void sub(SparseMatrixCRS M1, SparseMatrixCRS M2)
          Subtracts M1 from M2 and places the result in this matrix.
 java.lang.String toString()
          Returns a String representation of this sparse matrix.
 java.lang.String toString(NumberFormat fmt)
          Returns a String representation of this sparse matrix.
 java.lang.String toString(java.lang.String fmtStr)
          Returns a String representation of this sparse matrix.
 void transpose()
          Sets this matrix its transpose, changing its size and sparsity structure if necessary.
 void transpose(SparseMatrixCRS M)
          Sets this matrix to the transpose of M, changing the size and sparsity structure of this matrix if necessary.
 void trimCapacity()
          Trims the nonzero storage capacity of this matrix to fit the exact number of nonzeros.
 void zeroColumn(int j)
           
 void zeroRow(int i)
           
 
Methods inherited from class maspack.matrix.SparseMatrixBase
setCCSValues, setRandom, setRandom
 
Methods inherited from class maspack.matrix.MatrixBase
containsNaN, determinant, epsilonEquals, equals, frobeniusNorm, get, get, getCCSIndices, getCCSValues, getColumn, getColumn, getColumn, getCRSIndices, getCRSValues, getDefaultFormat, getRow, getRow, getRow, getSize, getSubMatrix, hasNaN, idString, infinityNorm, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, oneNorm, scan, setCRSValues, setDefaultFormat, 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.LinearTransformNd
mul
 
Methods inherited from interface maspack.matrix.Matrix
determinant, epsilonEquals, equals, frobeniusNorm, get, getCCSIndices, getCCSValues, getColumn, getColumn, getColumn, getCRSIndices, getCRSValues, getRow, getRow, getRow, getSize, getSubMatrix, infinityNorm, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, oneNorm, scan, trace, write, write, write
 

Constructor Detail

SparseMatrixCRS

public SparseMatrixCRS()
Creates an empty sparse matrix with 0 size.


SparseMatrixCRS

public SparseMatrixCRS(int numRows,
                       int numCols)
Creates an empty sparse matrix with a specified size.

Parameters:
numRows - number of rows
numCols - number of columns

SparseMatrixCRS

public SparseMatrixCRS(Matrix M)
Creates a sparse matrix from an existing general matrix.

Parameters:
M - matrix to copy

SparseMatrixCRS

public SparseMatrixCRS(double[] vals,
                       int[] cols,
                       int[] rowOffs)
Creates a sparse matrix from CRS data. The number of columns is determined from the column data.

Parameters:
vals - if non-null, gives all the nonzero values, in row order
cols - column index for each value, in row order.
rowOffs - gives the starting offset of each row into the cols and vals arrays
Throws:
java.lang.IllegalArgumentException - if the specified storgae format is inconsistent
Method Detail

setSize

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

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

ensureCapacity

public void ensureCapacity(int newcap)
Ensures that the nonzero storage capacity of this matrix is at least n.

Parameters:
newcap - desired storage capacity

getCapacity

public int getCapacity()
Returns the nonzero storage capacity of this matrix

Returns:
nonzero storage capacity

trimCapacity

public void trimCapacity()
Trims the nonzero storage capacity of this matrix to fit the exact number of nonzeros.


rowSize

public 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
Specified by:
rowSize in class MatrixBase
Returns:
number of rows

colSize

public 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
Specified by:
colSize in class MatrixBase
Returns:
number of columns

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
Overrides:
isFixedSize in class MatrixBase
Returns:
true if this matrix is of fixed size
See Also:
Matrix.setSize(int, int)

get

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

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

getNonzeroElements

public int getNonzeroElements(double[] values)
Returns the nonzero element values in row-major order. The values are placed into an array of doubles. It is assumed that i and j values of these elements are known.

Parameters:
values - collects the nonzero element values
Returns:
number of nonzero elements
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the array is not large enough to store all the values

setNonzeroElements

public void setNonzeroElements(double[] values)
Sets the existing nonzero element values, in row-major order. New values are supplied by an array of doubles.

Parameters:
values - new values for the nonzero elements
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the array is not large enough to provide all the values

numNonzeroElements

public int numNonzeroElements()
Returns the number of nonzero elements in this matrix.

Returns:
number of nonzero elements

set

public void set(int i,
                int j,
                double value)

set

public void set(double[] values,
                int[] indices,
                int numVals)
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 - nonzero values for specific matrix locations
indices - i and j indices for each explicit value
numVals - number of explicit values

set

public void set(Matrix M,
                Matrix.Partition part)
Sets the values of this matrix from an existing general matrix M, assuming the supplied partition type

Parameters:
M - matrix used to set values
part - partition type

set

public void set(Matrix M)
Sets the values of this matrix from an existing general matrix M.

Specified by:
set in interface Matrix
Overrides:
set in class SparseMatrixBase
Parameters:
M - matrix used to set values

setIdentity

public void setIdentity()
Sets this matrix to the identity matrix. If this matrix matrix is not square, then element (i,j) is set to 1 if i and j are equal, and 0 otherwise.

This method does not trim matrix capacity.


setDiagonal

public void setDiagonal(double[] vals)
Sets this matrix to a diagonal matrix whose diagonal elements are specified by an array.

This method does not trim matrix capacity.

Parameters:
vals - diagonal elements for this matrix
Throws:
ImproperSizeException - if the length of diag does not equal the minimum matrix dimension

setZero

public void setZero()
Sets the elements of this matrix to zero. This method does not trim matrix capacity.


setRandom

public void setRandom()
Sets this matrix to have a random sparsity structure and values, with between one and four nonzero elements per row.


setRandomValues

public void setRandomValues()
Sets the nonzero elements of this matrix to random values in the range -0.5 (inclusive) to 0.5 (exclusive).


setRandomValues

public void setRandomValues(double lower,
                            double upper,
                            java.util.Random generator)
Sets the nonzero elements of this matrix to random values in a specified range.

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

mul

public void mul(SparseMatrixCRS M)
Multiplies this matrix by M and places the result in this matrix. This matrix is resized if necessary.

Parameters:
M - right-hand matrix
Throws:
ImproperSizeException - if this matrix and M do not conform

mul

public void mul(SparseMatrixCRS M1,
                SparseMatrixCRS M2)
         throws ImproperSizeException
Multiplies matrix M1 by M2 and places the result in this matrix. This matrix is resized if necessary.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Throws:
ImproperSizeException - if this matrix and M1 and M2 do not conform.

mulTranspose

public void mulTranspose(SparseMatrixCRS M)
Multiplies this matrix by the transpose of M and places the result in this matrix. This matrix is resized if necessary.

Parameters:
M - right-hand matrix
Throws:
ImproperSizeException - if this matrix and the transpose of M do not conform

mulTransposeRight

public void mulTransposeRight(SparseMatrixCRS M1,
                              SparseMatrixCRS M2)
                       throws ImproperSizeException
Multiplies matrix M1 by the transpose of M2 and places the result in this matrix. This matrix is resized if necessary.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Throws:
ImproperSizeException - if M1 and the transpose M2 do not comform

mulTransposeLeft

public void mulTransposeLeft(SparseMatrixCRS M1,
                             SparseMatrixCRS M2)
                      throws ImproperSizeException
Multiplies the transpose of matrix M1 by M2 and places the result in this matrix. This matrix is resized if necessary.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Throws:
ImproperSizeException - if M1 and the transpose M2 do not comform

mulTransposeBoth

public void mulTransposeBoth(SparseMatrixCRS M1,
                             SparseMatrixCRS M2)
                      throws ImproperSizeException
Multiplies the transpose of matrix M1 by the transpose of M2 and places the result in this matrix. This matrix is resized if necessary.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Throws:
ImproperSizeException - if M1 and the transpose M2 do not comform

dotRowSelf

public double dotRowSelf(int i)
Returns the dot product of the i-th row with itself.

Parameters:
i - row index
Returns:
dot product of row i with itself

dotRow

public double dotRow(int i,
                     VectorNd v)
Returns the dot product of the i-th row with a vector v.

Parameters:
i - row index
v - vector to take dot product with
Returns:
dot product of row i with v

addScaledRow

public void addScaledRow(VectorNd v,
                         double s,
                         int i)
Adds s times the i-th row to the vector v.

Parameters:
v - vector to add scaled row to
s - scaling factor
i - row index

add

public void add(SparseMatrixCRS M)
Adds this matrix to M and places the result in this matrix.

Parameters:
M - right-hand matrix
Throws:
ImproperSizeException - if this matrix and M have different sizes.

add

public void add(SparseMatrixCRS M1,
                SparseMatrixCRS M2)
Adds matrix M1 to M2 and places the result in this matrix. This matrix is resized if necessary.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Throws:
ImproperSizeException - if matrices M1 and M2 have different sizes.

scaledAdd

public void scaledAdd(double s,
                      SparseMatrixCRS M1,
                      SparseMatrixCRS M2)
Computes s M1 + M2 and places the result in this matrix. This matrix is resized if necessary.

Parameters:
s - scaling factor
M1 - matrix to be scaled
M2 - matrix to be added
Throws:
ImproperSizeException - if matrices M1 and M2 have different sizes

sub

public void sub(SparseMatrixCRS M)
Subtracts M from this matrix.

Parameters:
M - matrix to subtract
Throws:
ImproperSizeException - if this matrix and M have different sizes.

sub

public void sub(SparseMatrixCRS M1,
                SparseMatrixCRS M2)
Subtracts M1 from M2 and places the result in this matrix. This matrix is resized if necessary.

Parameters:
M1 - left-hand matrix
M2 - right-hand matrix
Throws:
ImproperSizeException - if matrices M1 and M2 have different sizes.

combine

public void combine(double a,
                    SparseMatrixCRS M1,
                    double b,
                    SparseMatrixCRS M2)
Forms the combination a M1 + b M2 and places the result in this matrix. This matrix is resized if necessary.

Parameters:
a - scaling factor for M1
M1 - left-hand matrix
b - scaling factor for M2
M2 - right-hand matrix
Throws:
ImproperSizeException - if matrices M1 and M2 have different sizes.

negate

public void negate()
Negates this matrix in place.


negate

public void negate(SparseMatrixCRS M)
Sets this matrix to the negative of another matrix M. This matrix is resized if necessary.

Parameters:
M - matrix to be

scale

public void scale(double s)
Scales the elements of this matrix by s.

Specified by:
scale in interface SparseMatrix
Parameters:
s - scaling factor

scale

public void scale(double s,
                  SparseMatrixCRS M)
Scales the elements of matrix M1 by s and places the results in this matrix. This matrix is resized if necessary.

Parameters:
s - scaling factor
M - matrix to be scaled

transpose

public void transpose()
Sets this matrix its transpose, changing its size and sparsity structure if necessary.


transpose

public void transpose(SparseMatrixCRS M)
Sets this matrix to the transpose of M, changing the size and sparsity structure of this matrix if necessary.

Parameters:
M - matrix to take the transpose of

toString

public java.lang.String toString()
Returns a String representation of this sparse matrix. Each explicit element is output in row-major order as a tuple ( i j value), one tuple per line. Elements which are not printed are zero.

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

toString

public java.lang.String toString(java.lang.String fmtStr)
Returns a String representation of this sparse matrix. The output format is the same as that produced by toString, except that elements values are themselves formatted using a C printf style format string. For a description of the format string syntax, see NumberFormat.

Overrides:
toString in class MatrixBase
Parameters:
fmtStr - numeric format specification
Returns:
String representation of this matrix

toString

public java.lang.String toString(NumberFormat fmt)
Returns a String representation of this sparse matrix. The output format is the same as that produced by toString, except that elements values are themselves formatted using a C printf style as decribed by the parameter NumberFormat. When called numerous times, this routine can be more efficient than toString(String), because the NumberFormat does not need to be recreated each time from a specification string.

Specified by:
toString in interface Matrix
Overrides:
toString in class MatrixBase
Parameters:
fmt - numeric format
Returns:
String representation of this matrix

numNonZeroVals

public int numNonZeroVals(Matrix.Partition part,
                          int numRows,
                          int numCols)
Description copied from class: MatrixBase
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
Overrides:
numNonZeroVals in class MatrixBase
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

setCRSValues

public void setCRSValues(double[] vals,
                         int[] colIdxs,
                         int[] rowOffs,
                         int numVals,
                         int numRows,
                         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
Overrides:
setCRSValues in class SparseMatrixBase
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.
numVals - number of non-zero values
numRows - 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.

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
Overrides:
getCRSIndices in class MatrixBase
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,
                        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
Overrides:
getCRSValues in class MatrixBase
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

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
Overrides:
getCCSIndices in class MatrixBase
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,
                        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
Overrides:
getCCSValues in class MatrixBase
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

checkConsistency

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

Specified by:
checkConsistency in interface Matrix

zeroRow

public void zeroRow(int i)

zeroColumn

public void zeroColumn(int j)

add

public void add(int i,
                int j,
                double v)