public class FMatrixSparseCSC extends java.lang.Object implements FMatrixSparse
Compressed Column (CC) sparse matrix format. Only non-zero elements are stored.
Format:
Row indexes for column j are stored in rol_idx[col_idx[j]] to rol_idx[col_idx[j+1]-1]. The values
for the corresponding elements are stored at data[col_idx[j]] to data[col_idx[j+1]-1].
Row indexes must be specified in chronological order.
Modifier and Type | Field and Description |
---|---|
int[] |
col_idx
Stores the range of indexes in the non-zero lists that belong to each column.
|
boolean |
indicesSorted
Flag that's used to indicate of the row indices are sorted or not.
|
int |
numCols
Number of columns in the matrix
|
int |
numRows
Number of rows in the matrix
|
int |
nz_length
Length of data.
|
int[] |
nz_rows
Specifies which row a specific non-zero value corresponds to.
|
float[] |
nz_values
Storage for non-zero values.
|
Constructor and Description |
---|
FMatrixSparseCSC(FMatrixSparseCSC original) |
FMatrixSparseCSC(int numRows,
int numCols)
Constructor with a default arrayLength of zero.
|
FMatrixSparseCSC(int numRows,
int numCols,
int arrayLength)
Specifies shape and number of non-zero elements that can be stored.
|
Modifier and Type | Method and Description |
---|---|
void |
colsum(int[] histogram)
Given the histogram of columns compute the col_idx for the matrix.
|
FMatrixSparseCSC |
copy()
Creates an exact copy of the matrix
|
void |
copyStructure(FMatrixSparseCSC orig)
Copies the non-zero structure of orig into "this"
|
FMatrixSparseCSC |
createLike()
Creates a new matrix with the same shape as this matrix
|
float |
get(int row,
int col)
Returns the value of value of the specified matrix element.
|
int |
getNumCols()
Returns the number of columns in this matrix.
|
int |
getNumElements()
Returns the number of elements in this matrix, which is the number of rows
times the number of columns.
|
int |
getNumRows()
Returns the number of rows in this matrix.
|
MatrixType |
getType()
Returns the type of matrix
|
void |
growMaxColumns(int desiredColumns,
boolean preserveValue)
Increases the maximum number of columns in the matrix.
|
void |
growMaxLength(int arrayLength,
boolean preserveValue)
Increases the maximum size of the data array so that it can store sparse data up to 'length'.
|
boolean |
isAssigned(int row,
int col)
Is the specified element explicitly assigned a value
|
boolean |
isFull()
Returns true if number of non-zero elements is the maximum size
|
boolean |
isIndicesSorted()
If the indices has been sorted or not
|
int |
nz_index(int row,
int col)
Returns the index in nz_rows for the element at (row,col) if it already exists in the matrix.
|
void |
print()
Prints the matrix to standard out.
|
void |
printNonZero()
Prints to standard out the non-zero elements only.
|
void |
remove(int row,
int col)
If the specified element is non-zero it is removed from the structure
|
void |
reshape(int numRows,
int numCols,
int arrayLength)
Reshapes the matrix so that it can store a matrix with the specified dimensions and the number of
non-zero elements.
|
void |
set(int row,
int col,
float val)
Sets the value of the specified matrix element.
|
void |
set(Matrix original)
Sets this matrix to be identical to the 'original' matrix passed in.
|
void |
shrinkArrays()
Reduces the size of internal data structures to their minimal size.
|
void |
sortIndices(SortCoupledArray_F32 sorter)
Sorts the row indices in ascending order.
|
float |
unsafe_get(int row,
int col)
Same as
FMatrix.get(int, int) but does not perform bounds check on input parameters. |
void |
unsafe_set(int row,
int col,
float val)
Same as
FMatrix.set(int, int, float) but does not perform bounds check on input parameters. |
void |
zero()
Sets all elements to zero by removing the sparse graph
|
public float[] nz_values
public int nz_length
public int[] nz_rows
indicesSorted
flag.public int[] col_idx
public int numRows
public int numCols
public boolean indicesSorted
public FMatrixSparseCSC(int numRows, int numCols)
numRows
- Number of rowsnumCols
- Number of columnspublic FMatrixSparseCSC(int numRows, int numCols, int arrayLength)
numRows
- Number of rowsnumCols
- Number of columnsarrayLength
- Initial maximum number of non-zero elements that can be in the matrixpublic FMatrixSparseCSC(FMatrixSparseCSC original)
public int getNumRows()
Matrix
getNumRows
in interface Matrix
public int getNumCols()
Matrix
getNumCols
in interface Matrix
public FMatrixSparseCSC copy()
Matrix
public FMatrixSparseCSC createLike()
Matrix
createLike
in interface Matrix
public void set(Matrix original)
Matrix
public void print()
Matrix
public void printNonZero()
FMatrixSparse
printNonZero
in interface FMatrixSparse
public boolean isAssigned(int row, int col)
FMatrixSparse
isAssigned
in interface FMatrixSparse
row
- the rowcol
- the columnpublic float get(int row, int col)
FMatrix
public float unsafe_get(int row, int col)
FMatrix
FMatrix.get(int, int)
but does not perform bounds check on input parameters. This results in about a 25%
speed increase but potentially sacrifices stability and makes it more difficult to track down simple errors.
It is not recommended that this function be used, except in highly optimized code where the bounds are
implicitly being checked.unsafe_get
in interface FMatrix
row
- Matrix element's row index..col
- Matrix element's column index.public int nz_index(int row, int col)
row
- row coordinatecol
- column coordinatepublic void set(int row, int col, float val)
FMatrix
public void unsafe_set(int row, int col, float val)
FMatrix
FMatrix.set(int, int, float)
but does not perform bounds check on input parameters. This results in about a 25%
speed increase but potentially sacrifices stability and makes it more difficult to track down simple errors.
It is not recommended that this function be used, except in highly optimized code where the bounds are
implicitly being checked.unsafe_set
in interface FMatrix
row
- Matrix element's row index..col
- Matrix element's column index.val
- The element's new value.public void remove(int row, int col)
FMatrixSparse
remove
in interface FMatrixSparse
row
- the rowcol
- the columnpublic void zero()
FMatrixSparse
zero
in interface FMatrixSparse
public int getNumElements()
FMatrix
getNumElements
in interface FMatrix
public void reshape(int numRows, int numCols, int arrayLength)
FMatrixSparse
reshape
in interface FMatrixSparse
numRows
- number of rowsnumCols
- number of columnsarrayLength
- Array length for storing non-zero elements.public void shrinkArrays()
FMatrixSparse
shrinkArrays
in interface FMatrixSparse
public void growMaxLength(int arrayLength, boolean preserveValue)
arrayLength
- Desired maximum length of sparse datapreserveValue
- If true the old values will be copied into the new arrays. If false that step will be skipped.public void growMaxColumns(int desiredColumns, boolean preserveValue)
desiredColumns
- Desired number of columns.preserveValue
- If the array needs to be expanded should it copy the previous values?public void colsum(int[] histogram)
histogram
- histogram of column values in the sparse matrix. modified, see above.public void sortIndices(SortCoupledArray_F32 sorter)
sorter
- (Optional) Used to sort rows. If null a new instance will be declared internally.public void copyStructure(FMatrixSparseCSC orig)
orig
- Matrix who's structure is to be copiedpublic boolean isIndicesSorted()
public boolean isFull()
public MatrixType getType()
Matrix