public class SparseBlockMatrix extends SparseMatrixBase implements Clonable
| Modifier and Type | Class and Description |
|---|---|
static class |
SparseBlockMatrix.PrintFormat |
Matrix.Partition, Matrix.WriteFormat| Modifier and Type | Field and Description |
|---|---|
static int |
warningLevel |
INDEFINITE, POSITIVE_DEFINITE, SPD, SYMMETRIC| Constructor and Description |
|---|
SparseBlockMatrix() |
SparseBlockMatrix(int[] rowColSizes) |
SparseBlockMatrix(int[] rowSizes,
int[] colSizes) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(SparseBlockMatrix M) |
void |
add(SparseBlockMatrix M,
int numBlkRows,
int numBlkCols) |
int |
addBlock(int bi,
int bj,
MatrixBlock blk) |
void |
addCol(int size) |
void |
addCols(int[] sizes,
int num) |
void |
addNumNonZerosByCol(int[] offsets,
int idx,
Matrix.Partition part,
int numRows,
int numCols) |
void |
addNumNonZerosByRow(int[] offsets,
int idx,
Matrix.Partition part) |
void |
addNumNonZerosByRow(int[] offsets,
int idx,
Matrix.Partition part,
int numRows,
int numCols) |
void |
addRow(int size) |
void |
addRows(int[] sizes,
int num) |
boolean |
blockStructureEquals(int[] struct)
Returns
true if the block structure of this matrix
matches the structure described by struct, which should
have the same length and format as the array returned by
getBlockStructure(). |
boolean |
blockStructureEquals(SparseBlockMatrix M1)
Returns true if the structure of this SparseBlockMatrix matches
that of another.
|
static SparseBlockMatrix |
buildKKTSystem(SparseBlockMatrix M,
SparseBlockMatrix GT) |
void |
checkConsistency()
Check that the internal structures of this matrix are consistent.
|
SparseBlockMatrix |
clone()
Creates a clone of this SparseBlockMatrix, along with clones of all the
associated MatrixBlocks.
|
int |
colSize()
Number of columns in the matrix associated with this transformation.
|
int |
colSize(int numBlkCols) |
SparseBlockMatrix |
createSubMatrix(int[] irows,
int[] icols) |
SparseBlockMatrix |
createSubMatrix(int numBlockRows,
int numBlockCols) |
boolean |
elementIsNonZero(int i,
int j) |
MatrixBlock |
firstBlockInCol(int bj) |
MatrixBlock |
firstBlockInRow(int bi) |
double |
frobeniusNormSquared()
Returns the squared Frobenius norm of this matrix.
|
double |
get(int i,
int j)
Gets a single element of this matrix.
|
int |
getAlignedBlockCol(int j)
If a specified element column index is aligned with the beginning of a
block column, then this method returns the corresponding block column
index.
|
int |
getAlignedBlockRow(int i)
If a specified element row index is aligned with the beginning of a block
row, then this method returns the corresponding block row index.
|
MatrixBlock |
getBlock(int bi,
int bj) |
int |
getBlockCCSIndices(int[] rowIdxs,
int rowOff,
int[] offsets,
Matrix.Partition part) |
int |
getBlockCCSIndices(int[] rowIdxs,
int rowOff,
int[] offsets,
Matrix.Partition part,
int numRows,
int numCols) |
void |
getBlockCCSValues(double[] vals,
int[] offsets,
Matrix.Partition part) |
int |
getBlockCCSValues(double[] vals,
int[] offsets,
Matrix.Partition part,
int numRows,
int numCols) |
int |
getBlockCol(int j)
Returns the block column index corresponding to an element column index.
|
int |
getBlockColOffset(int bj) |
int |
getBlockColSize(int bj) |
int |
getBlockCRSIndices(int[] colIdxs,
int colOff,
int[] offsets,
Matrix.Partition part) |
int |
getBlockCRSIndices(int[] colIdxs,
int colOff,
int[] offsets,
Matrix.Partition part,
int numRows,
int numCols) |
int |
getBlockCRSValues(double[] vals,
int[] offsets,
Matrix.Partition part) |
int |
getBlockCRSValues(double[] vals,
int[] offsets,
Matrix.Partition part,
int numRows,
int numCols) |
java.lang.String |
getBlockPattern() |
int |
getBlockRow(int i)
Returns the block row index corresponding to an element row index.
|
int |
getBlockRowOffset(int bi) |
int |
getBlockRowSize(int bi) |
int[] |
getBlockStructure()
Returns an integer array that uniquely describes the block structure 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. |
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,
int nrows) |
static int[] |
getComp(int[] idxs,
int size) |
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. |
MatrixBlock |
getElementBlock(int i,
int j) |
static int[] |
getRange(int idx,
int numIdxs) |
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.
|
SparseBlockMatrix |
getSubMatrix(int bi,
int bj,
int numBlkRows,
int numBlkCols,
SparseBlockMatrix dest)
Ian TODO
|
int |
getSubMatrixColSize(int[] icols) |
void |
getSubMatrixColumn(int j,
double[] values,
int off,
int[] irows) |
void |
getSubMatrixRow(int i,
double[] values,
int off,
int[] icols) |
int |
getSubMatrixRowSize(int[] irows) |
boolean |
isVerticallyLinked() |
double |
maxNorm()
Returns the max-norm of this matrix.
|
void |
mulSubMatrixVec(double[] res,
double[] vec,
int[] irows,
int[] icols) |
int |
numBlockCols() |
int |
numBlockRows() |
int |
numBlocks() |
int |
numNonZeroVals()
Returns the number of non-zero values in this matrix object.
|
int |
numNonZeroVals(Matrix.Partition part) |
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. |
void |
perturb(double tol) |
void |
printBlocks(java.io.PrintStream ps) |
void |
removeAllBlocks() |
MatrixBlock |
removeBlock(int bi,
int bj) |
boolean |
removeBlock(MatrixBlock oldBlk) |
int |
rowSize()
Number of rows in the matrix associated with this transformation.
|
int |
rowSize(int numBlkRows) |
void |
scale(double s) |
void |
scaledAdd(double s,
SparseBlockMatrix M) |
void |
scaledAdd(double s,
SparseBlockMatrix M,
int numBlkRows,
int numBlkCols) |
void |
scanBlocks(ReaderTokenizer rtok)
Sets the sizing and contents of the matrix to values read from
a ReaderTokenizer.
|
void |
set(double[] values,
int[] indices,
int nvals)
Sets the elements of this matrix from an array of doubles and a list of
indices.
|
void |
set(int i,
int j,
double val) |
void |
set(Matrix M)
Sets the size and values of this matrix to those of another matrix.
|
void |
set(SparseBlockMatrix M)
Sets this SparseBlockMatrix to a copy of another SparseBlockMatrix.
|
void |
setColCapacity(int newCap) |
void |
setRandomValues()
Sets the nonzero elements of this matrix to random values
in the range -0.5 (inclusive) to 0.5 (exclusive).
|
void |
setRandomValues(boolean symmetric)
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,
boolean symmetric)
Sets the nonzero elements of this matrix to random values
in a specified range.
|
void |
setRowCapacity(int newCap) |
void |
setSubMatrix(SparseBlockMatrix M,
int[] irows,
int[] icols) |
boolean |
setSymmetric()
Sets the current matrix S to (1/2)(S+S^T), making it symmetric.
|
void |
setSymmetric(SparseBlockMatrix M)
Sets the current matrix to (1/2)(M+M^T).
|
void |
setVerticallyLinked(boolean enable) |
void |
setZero() |
void |
sub(SparseBlockMatrix M) |
void |
sub(SparseBlockMatrix M,
int numBlkRows,
int numBlkCols) |
java.lang.String |
toString(java.lang.String fmtStr,
int nrows,
int ncols) |
boolean |
valueIsNonZero(int i,
int j) |
void |
writeBlocks(java.io.PrintWriter pw) |
void |
writeBlocks(java.io.PrintWriter pw,
NumberFormat fmt)
Writes the contents of this matrix to a PrintWriter, using a sparse
block structure.
|
void |
zeroColumn(int j) |
void |
zeroRow(int i) |
setCCSValues, setCRSValues, setRandom, setRandomcontainsNaN, determinant, epsilonEquals, equals, frobeniusNorm, get, get, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getDefaultFormat, getRow, getSize, getSubMatrix, hasNaN, idString, infinityNorm, isFixedSize, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, oneNorm, scan, setCRSValues, setDefaultFormat, setSize, toString, toString, toString, trace, write, write, write, write, write, write, writeToFileequals, getClass, hashCode, notify, notifyAll, wait, wait, waitdeterminant, epsilonEquals, equals, frobeniusNorm, get, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getRow, getSize, getSubMatrix, infinityNorm, isFixedSize, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, oneNorm, scan, setSize, toString, toString, trace, write, write, writepublic SparseBlockMatrix()
public SparseBlockMatrix(int[] rowColSizes)
public SparseBlockMatrix(int[] rowSizes,
int[] colSizes)
public void setRowCapacity(int newCap)
public void addRow(int size)
public void addRows(int[] sizes,
int num)
public void setColCapacity(int newCap)
public void addCol(int size)
public void addCols(int[] sizes,
int num)
public int getBlockRowOffset(int bi)
public int getBlockRowSize(int bi)
public int getBlockColOffset(int bj)
public int getBlockColSize(int bj)
public int numBlocks()
public int addBlock(int bi,
int bj,
MatrixBlock blk)
public boolean removeBlock(MatrixBlock oldBlk)
public MatrixBlock removeBlock(int bi, int bj)
public void removeAllBlocks()
public MatrixBlock getBlock(int bi, int bj)
public MatrixBlock firstBlockInRow(int bi)
public MatrixBlock firstBlockInCol(int bj)
public int rowSize()
MatrixBasemul.rowSize in interface LinearTransformNdrowSize in interface MatrixrowSize in class MatrixBasepublic int rowSize(int numBlkRows)
public int numBlockRows()
public int numBlockCols()
public int colSize(int numBlkCols)
public int colSize()
MatrixBasemul.colSize in interface LinearTransformNdcolSize in interface MatrixcolSize in class MatrixBasepublic boolean elementIsNonZero(int i,
int j)
public boolean valueIsNonZero(int i,
int j)
public MatrixBlock getElementBlock(int i, int j)
public double get(int i,
int j)
MatrixBaseget in interface Matrixget in class MatrixBasei - element row indexj - element column indexpublic void set(int i,
int j,
double val)
public void set(double[] values,
int[] indices,
int nvals)
Matrixindices[k*2] and
indices[k*2+1], respectively. All non-specified elements
are set to zero.public int numNonZeroVals()
MatrixBasenumNonZeroVals in interface MatrixnumNonZeroVals in class MatrixBasepublic int numNonZeroVals(Matrix.Partition part)
public int numNonZeroVals(Matrix.Partition part, int numRows, int numCols)
MatrixBasenumRows 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.numNonZeroVals in interface MatrixnumNonZeroVals in class MatrixBasepart - matrix parition to be examinednumRows - number of rows delimiting the sub-matrixnumCols - number of columns delimiting the sub-matrixpublic void setZero()
public void scale(double s)
scale in interface SparseMatrixpublic int getBlockRow(int i)
i - element row indexpublic int getBlockCol(int j)
j - element column indexpublic int getAlignedBlockRow(int i)
i - element row indexpublic SparseBlockMatrix getSubMatrix(int bi, int bj, int numBlkRows, int numBlkCols, SparseBlockMatrix dest)
public int getAlignedBlockCol(int j)
j - element column indexpublic int getCRSIndices(int[] colIdxs,
int[] rowOffs,
Matrix.Partition part,
int numRows,
int numCols)
numRows rows and the
first numCols columns. The sub-matrix must be
block-aligned. Indices are 0-based and the sub-matrix is traversed in
row-major order.getCRSIndices in interface MatrixgetCRSIndices in class MatrixBasecolIdxs - returns the column indices 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.rowOffs - returns the offsets into colIdxs corresponding to the first
non-zero element in each row. This array must have a length equal at least
to the number of rows in the sub-matrix.part - specifies what portion of the sub-matrix to store; must be either
Full or
UpperTriangularnumRows - number of rows delimiting the sub-matrixnumCols - number of columns delimiting the sub-matrixpublic int getCRSValues(double[] vals,
Matrix.Partition part,
int numRows,
int numCols)
numRows rows and the
first numCols columns. The sub-matrix must be
block-aligned, and it is traversed in row-major order.getCRSValues in interface MatrixgetCRSValues in class MatrixBasevals - 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
UpperTriangularnumRows - number of rows delimiting the sub-matrixnumCols - number of columns delimiting the sub-matrixpublic int getBlockCRSIndices(int[] colIdxs,
int colOff,
int[] offsets,
Matrix.Partition part)
public int getBlockCRSIndices(int[] colIdxs,
int colOff,
int[] offsets,
Matrix.Partition part,
int numRows,
int numCols)
public int getBlockCRSValues(double[] vals,
int[] offsets,
Matrix.Partition part)
public int getBlockCRSValues(double[] vals,
int[] offsets,
Matrix.Partition part,
int numRows,
int numCols)
public void addNumNonZerosByRow(int[] offsets,
int idx,
Matrix.Partition part)
public void addNumNonZerosByRow(int[] offsets,
int idx,
Matrix.Partition part,
int numRows,
int numCols)
public int getCCSIndices(int[] rowIdxs,
int[] colOffs,
Matrix.Partition part,
int numRows,
int numCols)
numRows
rows and the first numCols columns. The sub-matrix must be
block-aligned. Indices are 0-based and the sub-matrix is traversed in
column-major order.getCCSIndices in interface MatrixgetCCSIndices in class MatrixBaserowIdxs - returns the row indices 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.colOffs - returns the offsets into rowIdxs corresponding to the first
non-zero element in each column. This array must have a length equal at
least to the number of columns in the sub-matrix.part - specifies what portion of the sub-matrix to store; must be either
Full or
LowerTriangularnumRows - number of rows delimiting the sub-matrixnumCols - number of columns delimiting the sub-matrixpublic int getCCSValues(double[] vals,
Matrix.Partition part,
int numRows,
int numCols)
numRows rows and the
first numCols columns. The sub-matrix must be block aligned
and it is traversed in column-major order.getCCSValues in interface MatrixgetCCSValues in class MatrixBasevals - 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
LowerTriangularnumRows - number of rows delimiting the sub-matrixnumCols - number of columns delimiting the sub-matrixpublic int getBlockCCSIndices(int[] rowIdxs,
int rowOff,
int[] offsets,
Matrix.Partition part)
public int getBlockCCSIndices(int[] rowIdxs,
int rowOff,
int[] offsets,
Matrix.Partition part,
int numRows,
int numCols)
public void getBlockCCSValues(double[] vals,
int[] offsets,
Matrix.Partition part)
public int getBlockCCSValues(double[] vals,
int[] offsets,
Matrix.Partition part,
int numRows,
int numCols)
public void addNumNonZerosByCol(int[] offsets,
int idx,
Matrix.Partition part,
int numRows,
int numCols)
public void add(SparseBlockMatrix M)
public void add(SparseBlockMatrix M, int numBlkRows, int numBlkCols)
public void sub(SparseBlockMatrix M)
public void sub(SparseBlockMatrix M, int numBlkRows, int numBlkCols)
public void scaledAdd(double s,
SparseBlockMatrix M)
public void scaledAdd(double s,
SparseBlockMatrix M,
int numBlkRows,
int numBlkCols)
public boolean setSymmetric()
public void setSymmetric(SparseBlockMatrix M)
M - input matrixpublic java.lang.String toString(java.lang.String fmtStr,
int nrows,
int ncols)
public java.lang.String getBlockPattern()
public void printBlocks(java.io.PrintStream ps)
public void setRandomValues()
public void setRandomValues(boolean symmetric)
symmetric - if true, sets transposed values to the same value
(ignored if the matrix is not square or does not have identical
row and block sizes).public void setRandomValues(double lower,
double upper,
java.util.Random generator,
boolean symmetric)
lower - lower random value (inclusive)upper - upper random value (exclusive)generator - random number generatorsymmetric - if true, sets transposed values to the same value
(ignored if the matrix is not square or does not have identical
row and block sizes).public void set(Matrix M)
SparseMatrixBaseset in interface Matrixset in class SparseMatrixBaseM - matrix whose size and values are copiedpublic void set(SparseBlockMatrix M)
M - matrix to be copiedpublic SparseBlockMatrix clone()
public void getRow(int i,
double[] values)
MatrixBasegetRow in interface MatrixgetRow in class MatrixBasei - row indexvalues - array into which the row is copiedpublic void getRow(int i,
double[] values,
int off)
MatrixBasegetRow in interface MatrixgetRow in class MatrixBasei - row indexvalues - array into which the row is copiedoff - offset in values where copying should beginpublic void zeroRow(int i)
public void getColumn(int j,
double[] values)
MatrixBasegetColumn in interface MatrixgetColumn in class MatrixBasej - column indexvalues - array into which the column is copiedpublic void getColumn(int j,
double[] values,
int off,
int nrows)
public void zeroColumn(int j)
public void checkConsistency()
checkConsistency in interface Matrixpublic void perturb(double tol)
public void setVerticallyLinked(boolean enable)
public boolean isVerticallyLinked()
public static SparseBlockMatrix buildKKTSystem(SparseBlockMatrix M, SparseBlockMatrix GT)
public SparseBlockMatrix createSubMatrix(int numBlockRows, int numBlockCols)
public SparseBlockMatrix createSubMatrix(int[] irows, int[] icols)
public void setSubMatrix(SparseBlockMatrix M, int[] irows, int[] icols)
public void getSubMatrixRow(int i,
double[] values,
int off,
int[] icols)
public void getSubMatrixColumn(int j,
double[] values,
int off,
int[] irows)
public void mulSubMatrixVec(double[] res,
double[] vec,
int[] irows,
int[] icols)
public int getSubMatrixRowSize(int[] irows)
public int getSubMatrixColSize(int[] icols)
public static int[] getRange(int idx,
int numIdxs)
public static int[] getComp(int[] idxs,
int size)
public void writeBlocks(java.io.PrintWriter pw)
throws java.io.IOException
java.io.IOExceptionpublic void writeBlocks(java.io.PrintWriter pw,
NumberFormat fmt)
throws java.io.IOException
[ ]. The opening bracket
is then followed by two integer vectors, each contained within
square brackets, giving the number of rows in each block row and
the number of columns in each block column. This is then followed
by the blocks, presented in row-major order, with each
individual block written using the format
[ bi bj nr nc xx xx xx xx xx xx xx xx xx ]where
bi and bj give the block row and column
indices, nr and nc give the number
of rows and columns in the block, and xx denotes the
individual numeric values in dense format. The latter are
formatted using a C printf style as
described by the parameter NumberFormat.pw - PrintWriter to write this matrix tofmt - numeric formatjava.io.IOExceptionpublic void scanBlocks(ReaderTokenizer rtok) throws java.io.IOException
writeBlocks.rtok - ReaderTokenizer from which values are read.java.io.IOExceptionpublic int[] getBlockStructure()
getBlockStructure() for another matrix, then the block structure of the
two matrices are equal.
The size of the array is
2 + 2*numBlockRows + numBlockCols + numBlockswhere
numBlockRows, numBlockCols,
and numBlocks are the values returned by
numBlockRows(), numBlockCols(), and numBlocks().
The contents of the array are:
quantity number of values
--------------------------------------------------------------------
number of block rows 1
number of block columns 1
block row size for each block row numBlockRows
block col size for each block column numBlockCols
number of blocks in each block row numBlockRows
block column index of each block (row major order) numBlocks
public boolean blockStructureEquals(int[] struct)
true if the block structure of this matrix
matches the structure described by struct, which should
have the same length and format as the array returned by
getBlockStructure().struct - block structure descriptionpublic boolean blockStructureEquals(SparseBlockMatrix M1)
M1 - matrix to compare withpublic double frobeniusNormSquared()
frobeniusNormSquared in interface MatrixfrobeniusNormSquared in class MatrixBasepublic double maxNorm()
MatrixmaxNorm in interface MatrixmaxNorm in class MatrixBase