maspack.matrix
Class MatrixBlockBase

java.lang.Object
  extended by maspack.matrix.MatrixBase
      extended by maspack.matrix.DenseMatrixBase
          extended by maspack.matrix.MatrixBlockBase
All Implemented Interfaces:
java.lang.Cloneable, DenseMatrix, LinearTransformNd, Matrix, MatrixBlock, Clonable

public abstract class MatrixBlockBase
extends DenseMatrixBase
implements MatrixBlock

Implements a matrix based on an array of 3x3 sub matrices. Support is provided to assemble these into a sparse 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
 
Method Summary
 void add(Matrix M)
          Adds the contents of a Matrix to this matrix block.
 void addNumNonZerosByCol(int[] offsets, int idx, Matrix.Partition part)
          Adds the number of non-zero entries in each column of this block matrix to the current values stored in the array offsets, starting at the location specified by idx.
static void addNumNonZerosByCol(Matrix M, int[] offsets, int idx, Matrix.Partition part)
          Dense implementation method for addNumNonZerosByColgetBlockCCSIndices(int[],int,Partition).
 void addNumNonZerosByRow(int[] offsets, int idx, Matrix.Partition part)
          Adds the number of non-zero entries in each row of this block matrix to the current values stored in the array offsets, starting at the location specified by idx.
static void addNumNonZerosByRow(Matrix M, int[] offsets, int idx, Matrix.Partition part)
          Dense implementation method for addNumNonZerosByRow(int[],int,Partition).
static MatrixBlock alloc(int nrows, int ncols)
           
 MatrixBlockBase clone()
          Creates a clone of this MatrixBlock, which duplicates the size, storage capacity, and values.
 MatrixBlock down()
          Returns the next matrix block in a block matrix column.
 int getBlockCCSIndices(int[] rowIdxs, int rowOff, int[] offsets, Matrix.Partition part)
          
static int getBlockCCSIndices(MatrixBlock M, int[] rowIdxs, int rowOff, int[] offsets, Matrix.Partition part)
          Dense implementation method for getBlockCCSIndices(int[],int[],Partition).
 int getBlockCCSValues(double[] vals, int[] offsets, Matrix.Partition part)
          Stores the values of non-zero entries for this matrix block.
 int getBlockCol()
          Gets the number of the block column of this matrix block within a SparseBlockMatrix.
 int getBlockCRSIndices(int[] colIdxs, int colOff, int[] offsets, Matrix.Partition part)
          Stores the column indices of the non-zero entries for this matrix block.
static int getBlockCRSIndices(MatrixBlock M, int[] colIdxs, int colOff, int[] offsets, Matrix.Partition part)
           
 int getBlockCRSValues(double[] vals, int[] offsets, Matrix.Partition part)
          Stores the values of non-zero entries for this matrix block.
 int getBlockNumber()
          Gets the number of this block within a SparseBlockMatrix.
 int getBlockRow()
          Gets the number of the block row of this matrix block within a SparseBlockMatrix.
abstract  void mulAdd(double[] y, int yIdx, double[] x, int xidx)
          Pre-multiplies a column vector by this matrix block and adds the result to a set of existing values.
abstract  void mulTransposeAdd(double[] y, int yIdx, double[] x, int xidx)
          Post-multiplies a row vector by this matrix block and adds the result to a set of existing values.
 MatrixBlock next()
          Returns the next matrix block in a block matrix row.
 int numNonZeroVals()
          Returns the number of non-zero values in this matrix object.
 void scale(double s)
          Scales the elements of this matrix block by a scale factor.
 void scaledAdd(double s, Matrix M)
          Adds the scaled contents of a Matrix to this matrix block.
 void setBlockCol(int blkCol)
          Sets the number of the block column of this matrix block within a SparseBlockMatrix.
 void setBlockNumber(int num)
          Sets the number of this block within a SparseBlockMatrix.
 void setBlockRow(int blkRow)
          Sets the number of the block row of this matrix block within a SparseBlockMatrix.
 void setDown(MatrixBlock blk)
          Sets the next matrix block in a block matrix column.
 void setNext(MatrixBlock blk)
          Sets the next matrix block in a block matrix row.
abstract  void setZero()
          Sets the contents of this matrix block to zero.
 void sub(Matrix M)
          Subtract the contents of a Matrix from this matrix block.
 boolean valueIsNonZero(int i, int j)
          Returns true if the value at the specified location is structurally non-zero.
 
Methods inherited from class maspack.matrix.DenseMatrixBase
add, checkConsistency, set, set, set, set, set, set, setCCSValues, setColumn, setColumn, setCRSValues, setRow, setRow, setSubMatrix
 
Methods inherited from class maspack.matrix.MatrixBase
colSize, containsNaN, determinant, epsilonEquals, equals, frobeniusNorm, get, get, get, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getColumn, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getDefaultFormat, getRow, getRow, getRow, getSize, getSubMatrix, hasNaN, idString, infinityNorm, isFixedSize, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, oneNorm, rowSize, scan, setCRSValues, setDefaultFormat, setSize, toString, toString, toString, trace, write, write, write, write, write, writeToFile
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface maspack.matrix.DenseMatrix
set, set, set, setColumn, setColumn, setRow, setRow, setSubMatrix
 
Methods inherited from interface maspack.matrix.Matrix
checkConsistency, colSize, determinant, epsilonEquals, equals, frobeniusNorm, get, get, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getColumn, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getRow, getRow, getRow, getSize, getSubMatrix, infinityNorm, isFixedSize, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, oneNorm, rowSize, scan, set, set, setCCSValues, setCRSValues, setSize, toString, trace, write, write, write
 

Method Detail

next

public MatrixBlock next()
Returns the next matrix block in a block matrix row.

Specified by:
next in interface MatrixBlock
Returns:
next matrix block in a row

setNext

public void setNext(MatrixBlock blk)
Sets the next matrix block in a block matrix row. Reserved for use by maspack.matrix.

Specified by:
setNext in interface MatrixBlock
Parameters:
blk - next matrix block in a row

down

public MatrixBlock down()
Returns the next matrix block in a block matrix column.

Specified by:
down in interface MatrixBlock
Returns:
next matrix block in a column

setDown

public void setDown(MatrixBlock blk)
Sets the next matrix block in a block matrix column. Reserved for use by maspack.matrix.

Specified by:
setDown in interface MatrixBlock
Parameters:
blk - next matrix block in a column

getBlockRow

public int getBlockRow()
Gets the number of the block row of this matrix block within a SparseBlockMatrix.

Specified by:
getBlockRow in interface MatrixBlock
Returns:
block row number for this block

setBlockRow

public void setBlockRow(int blkRow)
Sets the number of the block row of this matrix block within a SparseBlockMatrix. Use of this method is reserved to maspack.matrix.

Specified by:
setBlockRow in interface MatrixBlock
Parameters:
blkRow - row number for this block

getBlockNumber

public int getBlockNumber()
Gets the number of this block within a SparseBlockMatrix. Block numbers are used for fast access. If the block does not belong to a SparseBlockMatrix, then -1 is returned.

Specified by:
getBlockNumber in interface MatrixBlock
Returns:
number for this block

setBlockNumber

public void setBlockNumber(int num)
Sets the number of this block within a SparseBlockMatrix. Use of this method is reserved to maspack.matrix.

Specified by:
setBlockNumber in interface MatrixBlock
Parameters:
num - number for this block

getBlockCol

public int getBlockCol()
Gets the number of the block column of this matrix block within a SparseBlockMatrix.

Specified by:
getBlockCol in interface MatrixBlock
Returns:
block column number for this block

setBlockCol

public void setBlockCol(int blkCol)
Sets the number of the block column of this matrix block within a SparseBlockMatrix. Use of this method is reserved to maspack.matrix.

Specified by:
setBlockCol in interface MatrixBlock
Parameters:
blkCol - column number for this block

setZero

public abstract void setZero()
Sets the contents of this matrix block to zero.

Specified by:
setZero in interface MatrixBlock

scale

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

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

add

public void add(Matrix M)
Adds the contents of a Matrix to this matrix block.

Specified by:
add in interface MatrixBlock
Parameters:
M - matrix to add

scaledAdd

public void scaledAdd(double s,
                      Matrix M)
Adds the scaled contents of a Matrix to this matrix block.

Specified by:
scaledAdd in interface MatrixBlock
Parameters:
s - scaling factor
M - matrix to add

sub

public void sub(Matrix M)
Subtract the contents of a Matrix from this matrix block.

Specified by:
sub in interface MatrixBlock
Parameters:
M - matrix to subtract

mulAdd

public abstract void mulAdd(double[] y,
                            int yIdx,
                            double[] x,
                            int xidx)
Pre-multiplies a column vector by this matrix block and adds the result to a set of existing values. The column vector values are supplied by the argument x, starting at location xIdx, and the result is added to values in y, starting at location yIdx.

Specified by:
mulAdd in interface MatrixBlock
Parameters:
y - accumulates resulting values
yIdx - starting index for accumulating values
x - supplies column vector values
xidx - starting index for column vector values

mulTransposeAdd

public abstract void mulTransposeAdd(double[] y,
                                     int yIdx,
                                     double[] x,
                                     int xidx)
Post-multiplies a row vector by this matrix block and adds the result to a set of existing values. The row vector values are supplied by the argument x, starting at location xIdx, and the result is added to values in y, starting at location yIdx.

Specified by:
mulTransposeAdd in interface MatrixBlock
Parameters:
y - accumulates resulting values
yIdx - starting index for accumulating values
x - supplies row vector values
xidx - starting index for row vector values

getBlockCRSIndices

public static int getBlockCRSIndices(MatrixBlock M,
                                     int[] colIdxs,
                                     int colOff,
                                     int[] offsets,
                                     Matrix.Partition part)

getBlockCRSIndices

public int getBlockCRSIndices(int[] colIdxs,
                              int colOff,
                              int[] offsets,
                              Matrix.Partition part)
Stores the column indices of the non-zero entries for this matrix block. The indices for each row i are stored contiguously within the array colIdxs, starting at a location given by offsets[i]. Indices are 0-based. Upon return, offsets[i] should be incremented by the number of non-zero values in row i.

Specified by:
getBlockCRSIndices in interface MatrixBlock
Parameters:
colIdxs - stores column indices of non-zero entries
colOff - starting column index for the first column of this block
offsets - offsets within colIdxs for storing each row's indices; upon return, should be incremented by the number of non-zero entries in each row.
part - specifies whether to store column indices for the entire block or a specified sub-portion.
Returns:
number of non-zero entries

getBlockCRSValues

public int getBlockCRSValues(double[] vals,
                             int[] offsets,
                             Matrix.Partition part)
Stores the values of non-zero entries for this matrix block. The values for each row i are stored contiguously within the array vals, starting at a location given by offsets[i]. Upon return, offsets[i] should be incremented by the number of non-zero values in row i.

Specified by:
getBlockCRSValues in interface MatrixBlock
Parameters:
vals - stores values of non-zero entries
offsets - offsets within vals for storing each row's values; upon return, should be incremented by the number of non-zero entries in each row.
part - specifies whether to store the entire block or a specified sub-portion.
Returns:
number of non-zero entries

addNumNonZerosByRow

public static void addNumNonZerosByRow(Matrix M,
                                       int[] offsets,
                                       int idx,
                                       Matrix.Partition part)
Dense implementation method for addNumNonZerosByRow(int[],int,Partition).


addNumNonZerosByRow

public void addNumNonZerosByRow(int[] offsets,
                                int idx,
                                Matrix.Partition part)
Adds the number of non-zero entries in each row of this block matrix to the current values stored in the array offsets, starting at the location specified by idx.

Specified by:
addNumNonZerosByRow in interface MatrixBlock
Parameters:
offsets - values to be incremented by the number of non-zero entries in each row
idx - starting location within offsets
part - specifies whether to consider the entire block or a specified sub-portion.

getBlockCCSIndices

public static int getBlockCCSIndices(MatrixBlock M,
                                     int[] rowIdxs,
                                     int rowOff,
                                     int[] offsets,
                                     Matrix.Partition part)
Dense implementation method for getBlockCCSIndices(int[],int[],Partition).


getBlockCCSIndices

public int getBlockCCSIndices(int[] rowIdxs,
                              int rowOff,
                              int[] offsets,
                              Matrix.Partition part)

Specified by:
getBlockCCSIndices in interface MatrixBlock
Parameters:
rowIdxs - stores row indices of non-zero entries
rowOff - starting row index for the first row of this block
offsets - offsets within rowIdxs for storing each column's indices; upon return, should be incremented by the number of non-zero entries in each column.
part - specifies whether to store row indices for the entire block or a specified sub-portion.
Returns:
number of non-zero entries

getBlockCCSValues

public int getBlockCCSValues(double[] vals,
                             int[] offsets,
                             Matrix.Partition part)
Stores the values of non-zero entries for this matrix block. The values for each column j are stored contiguously within the array vals, starting at a location given by offsets[j]. Upon return, offsets[j] should be incremented by the number of non-zero values in column j.

Specified by:
getBlockCCSValues in interface MatrixBlock
Parameters:
vals - stores values of non-zero entries
offsets - offsets within vals for storing each columns's values; upon return, should be incremented by the number of non-zero entries in each column.
part - specifies whether to store the entire block or a specified sub-portion.
Returns:
number of non-zero entries

addNumNonZerosByCol

public static void addNumNonZerosByCol(Matrix M,
                                       int[] offsets,
                                       int idx,
                                       Matrix.Partition part)
Dense implementation method for addNumNonZerosByColgetBlockCCSIndices(int[],int,Partition).


addNumNonZerosByCol

public void addNumNonZerosByCol(int[] offsets,
                                int idx,
                                Matrix.Partition part)
Adds the number of non-zero entries in each column of this block matrix to the current values stored in the array offsets, starting at the location specified by idx.

Specified by:
addNumNonZerosByCol in interface MatrixBlock
Parameters:
offsets - values to be incremented by the number of non-zero entries in each column
idx - starting location within offsets
part - specifies whether to consider the entire block or a specified sub-portion.

valueIsNonZero

public boolean valueIsNonZero(int i,
                              int j)
Returns true if the value at the specified location is structurally non-zero. For dense blocks, this methid will always return true.

Specified by:
valueIsNonZero in interface MatrixBlock
Parameters:
i - row index
j - column index
Returns:
true if the value at (i,j) is structurally non-zero

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
Overrides:
numNonZeroVals in class MatrixBase
Returns:
number of non-zero values

clone

public MatrixBlockBase clone()
Creates a clone of this MatrixBlock, which duplicates the size, storage capacity, and values.

Specified by:
clone in interface MatrixBlock
Specified by:
clone in interface Clonable
Overrides:
clone in class java.lang.Object
Returns:
clone of this MatrixBlock

alloc

public static MatrixBlock alloc(int nrows,
                                int ncols)