jsat.linear
Class SubMatrix
- java.lang.Object
-
- jsat.linear.Matrix
-
- jsat.linear.GenericMatrix
-
- jsat.linear.SubMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class SubMatrix extends GenericMatrix
This class allows for the selection of an area of a matrix to operate on independently. Mutable matrix operations perform on this sub matrix, will be visible in the base matrix given. This allows for easy implementation of blocking algorithms, but care must be taken to not create and use two sub matrices that overlap and are altered simultaneously.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SubMatrix(Matrix baseMatrix, int firstRow, int firstColumn, int toRow, int toCol)Creates a new matrix that is a sub view of the given base matrix.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidchangeSize(int newRows, int newCols)This method alters the size of a matrix, either adding or subtracting rows from the internal structure of the matrix.intcols()Returns the number of columns stored in this matrixdoubleget(int i, int j)Returns the value stored at at the matrix position Ai,jMatrixgetBaseMatrix()Returns the matrix that is the base for this sub matrix.VecgetColumnView(int j)Obtains a vector that is backed by this, at very little memory cost.intgetFirstColumn()Returns the column offset used from the base matrixintgetFirstRow()Returns the row offset used from the base matrixVecgetRowView(int r)Obtains a vector that is backed by this, at very little memory cost.booleanisSparce()Returnstrueif the matrix is sparse,falseotherwiseintrows()Returns the number of rows stored in this matrixvoidset(int i, int j, double value)Sets the value stored at at the matrix position Ai,j-
Methods inherited from class jsat.linear.GenericMatrix
clone, lup, lup, multiply, multiply, multiply, multiplyTranspose, multiplyTranspose, mutableAdd, mutableAdd, mutableAdd, mutableAdd, mutableMultiply, mutableMultiply, mutableTranspose, qr, qr, swapRows, transpose, transposeMultiply, transposeMultiply, transposeMultiply, zeroOut
-
Methods inherited from class jsat.linear.Matrix
add, add, add, add, canBeMutated, canMultiply, copyTo, diag, diagMult, diagMult, equals, equals, eye, getColumn, getRow, increment, isSquare, isSymmetric, isSymmetric, multiply, multiply, multiply, multiply, multiply, multiplyTranspose, multiplyTranspose, mutableAdd, mutableAdd, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, nnz, OuterProductUpdate, OuterProductUpdate, pascal, random, sameDimensions, subtract, subtract, subtract, subtract, toString, transpose, transposeMultiply, transposeMultiply, transposeMultiply, updateRow
-
-
-
-
Constructor Detail
-
SubMatrix
public SubMatrix(Matrix baseMatrix, int firstRow, int firstColumn, int toRow, int toCol)
Creates a new matrix that is a sub view of the given base matrix.- Parameters:
baseMatrix- the base matrix to get a view offirstRow- the first row to consider as part of the sub matrix, starting from 0 inclusivefirstColumn- the first column to consider as part of the sub matrix, starting from 0 inclusivetoRow- the last row from the base matrix to consider, exclusivetoCol- the last column from the base matrix to consider, exclusive
-
-
Method Detail
-
getBaseMatrix
public Matrix getBaseMatrix()
Returns the matrix that is the base for this sub matrix.- Returns:
- the matrix that is the base for this sub matrix.
-
getFirstRow
public int getFirstRow()
Returns the row offset used from the base matrix- Returns:
- the row offset used from the base matrix
-
getFirstColumn
public int getFirstColumn()
Returns the column offset used from the base matrix- Returns:
- the column offset used from the base matrix
-
get
public double get(int i, int j)Description copied from class:MatrixReturns the value stored at at the matrix position Ai,j
-
set
public void set(int i, int j, double value)Description copied from class:MatrixSets the value stored at at the matrix position Ai,j
-
getRowView
public Vec getRowView(int r)
Description copied from class:MatrixObtains a vector that is backed by this, at very little memory cost. Mutations to this vector will alter the values stored in the matrix, and vice versa.- Overrides:
getRowViewin classMatrix- Parameters:
r- the row to obtain a view of- Returns:
- a vector backed by the specified row of the matrix
-
getColumnView
public Vec getColumnView(int j)
Description copied from class:MatrixObtains a vector that is backed by this, at very little memory cost. Mutations to this vector will alter the values stored in the matrix, and vice versa.- Overrides:
getColumnViewin classMatrix- Parameters:
j- the column to obtain a view of- Returns:
- a vector backed by the specified row of the matrix
-
rows
public int rows()
Description copied from class:MatrixReturns the number of rows stored in this matrix
-
cols
public int cols()
Description copied from class:MatrixReturns the number of columns stored in this matrix
-
isSparce
public boolean isSparce()
Description copied from class:MatrixReturnstrueif the matrix is sparse,falseotherwise
-
changeSize
public void changeSize(int newRows, int newCols)This method alters the size of a matrix, either adding or subtracting rows from the internal structure of the matrix. Every resize call may cause a new allocation internally, and should not be called for excessive changing of a matrix. All added rows/ columns will have values of zero. If a row / column is removed, it is always the bottom/right most row / column removed. Values of the removed rows / columns will be lost.
When a SubMatrix attempts to change size, it may alter the values of the underlying matrix in an unusual way. If the base matrix is large enough to hold the changed size, then the values in the underlying matrix that this SubMatrix is expanding to encompass will be set to zero. If the underlying matrix is not large enough, change size will be called upon it as well.
When decreasing the number of rows / columns, the SubMatrix will always reduce its view - but never shrink the underling matrix that the view is of.
To expand the size of a SubMatrix without zeroing out the new values, create a new SubMatrix object.- Specified by:
changeSizein classMatrix- Parameters:
newRows- the new number of rows, must be positivenewCols- the new number of columns, must be positive.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG