gov.sandia.cognition.math.matrix.mtj
Class SparseRowMatrix

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.math.AbstractRing<Matrix>
          extended by gov.sandia.cognition.math.matrix.AbstractMatrix
              extended by gov.sandia.cognition.math.matrix.mtj.AbstractMTJMatrix
                  extended by gov.sandia.cognition.math.matrix.mtj.AbstractSparseMatrix
                      extended by gov.sandia.cognition.math.matrix.mtj.SparseRowMatrix
All Implemented Interfaces:
Matrix, Vectorizable, Ring<Matrix>, CloneableSerializable, Serializable, Cloneable, Iterable<MatrixEntry>
Direct Known Subclasses:
SparseMatrix

@CodeReview(reviewer="Justin Basilico",
            date="2006-07-27",
            changesNeeded=false,
            comments="Looks good.")
public class SparseRowMatrix
extends AbstractSparseMatrix

A sparse matrix, represented as a collection of sparse row vectors. Generally, this is the fastest sparse matrix for premultiplying against a vector.

Since:
1.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
protected SparseRowMatrix(no.uib.cipr.matrix.sparse.FlexCompRowMatrix internalMatrix)
          Creates a SparseRowMatrix based on the appropriate MTJ matrix, does NOT create a copy of internalMatrix.
protected SparseRowMatrix(int numRows, int numColumns)
          Creates a new empty instance of SparseRowMatrix.
protected SparseRowMatrix(Matrix matrix)
          Copy constructor for general matrices, copies over nonzero values.
protected SparseRowMatrix(SparseRowMatrix matrix)
          Copy constructor for SparseRowMatrix matrices
 
Method Summary
 void compact()
          Compact the memory used by the matrix, getting rid of any zero elements
 no.uib.cipr.matrix.sparse.FlexCompRowMatrix getInternalMatrix()
          Gets the internal MTJ matrix that this class is wrapping.
 SparseVector getRow(int rowIndex)
          Gets the specified row of the matrix, using MTJ's internal routine to speed things up.
 SparseRowMatrix getSubMatrix(int minRow, int maxRow, int minColumn, int maxColumn)
          Gets the embedded submatrix inside of the Matrix, specified by the inclusive, zero-based indices such that the result matrix will have size (maxRow-minRow+1) x (maxColum-minCcolumn+1)
 void setRow(int rowIndex, SparseVector rowVector)
          Sets the specified row of the matrix using rowVector, using MTJ's internal routine to speed things up.
 SparseRowMatrix times(AbstractMTJMatrix matrix)
          Matrix multiplication of this and matrix, operates like the "*" operator in Matlab
 SparseColumnMatrix transpose()
          Returns the transpose of this
 
Methods inherited from class gov.sandia.cognition.math.matrix.mtj.AbstractSparseMatrix
getColumn, isSparse, pseudoInverse, setElement, solve, times, toString, toString
 
Methods inherited from class gov.sandia.cognition.math.matrix.mtj.AbstractMTJMatrix
clone, convertFromVector, convertToVector, dotTimesEquals, dotTimesEquals, equals, getElement, getNumColumns, getNumRows, getSubMatrixInto, identity, inverse, isSquare, isSymmetric, iterator, logDeterminant, minusEquals, minusEquals, normFrobenius, plusEquals, plusEquals, rank, scaledMinusEquals, scaledPlusEquals, scaledPlusEquals, scaleEquals, setInternalMatrix, solve, solve, solve, times, times, timesInto, timesInto, transposeInto, zero
 
Methods inherited from class gov.sandia.cognition.math.matrix.AbstractMatrix
assertSameDimensions, checkMultiplicationDimensions, checkSameDimensions, dotDivide, dotDivideEquals, equals, equals, getColumnInto, getRowInto, hashCode, isSymmetric, isZero, pseudoInverse, rank, setColumn, setRow, setSubMatrix, sumOfColumns, sumOfRows, toArray, trace
 
Methods inherited from class gov.sandia.cognition.math.AbstractRing
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.math.Ring
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
 

Constructor Detail

SparseRowMatrix

protected SparseRowMatrix(int numRows,
                          int numColumns)
Creates a new empty instance of SparseRowMatrix.

Parameters:
numRows - Number of rows in the matrix.
numColumns - Number of columns in the matrix.

SparseRowMatrix

protected SparseRowMatrix(SparseRowMatrix matrix)
Copy constructor for SparseRowMatrix matrices

Parameters:
matrix - Matrix from which to copy the internal MTJ matrix.

SparseRowMatrix

protected SparseRowMatrix(Matrix matrix)
Copy constructor for general matrices, copies over nonzero values.

Parameters:
matrix - Matrix from which to copy the nonzero elements into this.

SparseRowMatrix

protected SparseRowMatrix(no.uib.cipr.matrix.sparse.FlexCompRowMatrix internalMatrix)
Creates a SparseRowMatrix based on the appropriate MTJ matrix, does NOT create a copy of internalMatrix.

Parameters:
internalMatrix - New internal matrix for this, no copy made.
Method Detail

getInternalMatrix

public no.uib.cipr.matrix.sparse.FlexCompRowMatrix getInternalMatrix()
Description copied from class: AbstractMTJMatrix
Gets the internal MTJ matrix that this class is wrapping.

Overrides:
getInternalMatrix in class AbstractMTJMatrix
Returns:
Internal MTJ matrix.

transpose

public SparseColumnMatrix transpose()
Description copied from interface: Matrix
Returns the transpose of this

Returns:
Matrix whose elements are equivalent to: this.getElement(i, j) == this.transpose().getElement(j, i) for any valid i, j.

times

public SparseRowMatrix times(AbstractMTJMatrix matrix)
Description copied from class: AbstractMTJMatrix
Matrix multiplication of this and matrix, operates like the "*" operator in Matlab

Specified by:
times in class AbstractMTJMatrix
Parameters:
matrix - this.getNumColumns()==matrix.getNumRows()
Returns:
Matrix multiplication of this and matrix, will this.getNumRows() rows and matrix.getNumColumns() columns

getSubMatrix

public SparseRowMatrix getSubMatrix(int minRow,
                                    int maxRow,
                                    int minColumn,
                                    int maxColumn)
Description copied from interface: Matrix
Gets the embedded submatrix inside of the Matrix, specified by the inclusive, zero-based indices such that the result matrix will have size (maxRow-minRow+1) x (maxColum-minCcolumn+1)

Parameters:
minRow - Zero-based index into the rows of the Matrix, must be less than or equal to maxRow
maxRow - Zero-based index into the rows of the Matrix, must be greater than or equal to minRow
minColumn - Zero-based index into the rows of the Matrix, must be less than or equal to maxColumn
maxColumn - Zero-based index into the rows of the Matrix, must be greater than or equal to minColumn
Returns:
the Matrix of dimension (maxRow-minRow+1)x(maxColumn-minColumn+1)

getRow

public SparseVector getRow(int rowIndex)
Gets the specified row of the matrix, using MTJ's internal routine to speed things up.

Specified by:
getRow in interface Matrix
Overrides:
getRow in class AbstractSparseMatrix
Parameters:
rowIndex - Zero-based row index.
Returns:
SparseVector with the same dimensions as this has columns.

setRow

public void setRow(int rowIndex,
                   SparseVector rowVector)
Sets the specified row of the matrix using rowVector, using MTJ's internal routine to speed things up.

Parameters:
rowIndex - Zero-based row index.
rowVector - SparseVector containing the elements to replace in this.

compact

public void compact()
Description copied from class: AbstractSparseMatrix
Compact the memory used by the matrix, getting rid of any zero elements

Specified by:
compact in class AbstractSparseMatrix