Package org.ejml.data
Class DMatrixSparseCSC
java.lang.Object
org.ejml.data.DMatrixSparseCSC
- All Implemented Interfaces:
Serializable,DMatrix,DMatrixSparse,Matrix,MatrixSparse,ReshapeMatrix
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.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.ejml.data.DMatrixSparse
DMatrixSparse.CoordinateRealValue -
Field Summary
FieldsModifier and TypeFieldDescriptionint[]Stores the range of indexes in the non-zero lists that belong to each column.booleanFlag that's used to indicate of the row indices are sorted or not.intNumber of columns in the matrixintNumber of rows in the matrixintLength of data.int[]Specifies which row a specific non-zero value corresponds to.double[]Storage for non-zero values. -
Constructor Summary
ConstructorsConstructorDescriptionDMatrixSparseCSC(int numRows, int numCols) Constructor with a default arrayLength of zero.DMatrixSparseCSC(int numRows, int numCols, int arrayLength) Specifies shape and number of non-zero elements that can be stored.DMatrixSparseCSC(DMatrixSparseCSC original) -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates an exact copy of the matrixvoidCopies the non-zero structure of orig into "this"create(int numRows, int numCols) Creates a new matrix of the same type with the specified shapeCreates an iterator which will go through each non-zero value in the sparse matrix.Creates a new matrix with the same shape as this matrixdoubleget(int row, int col) Returns the value of value of the specified matrix element.doubleget(int row, int col, double fallBackValue) Returns the value of value of the specified matrix element.intReturns the number of non-zero elements.intReturns the number of columns in this matrix.intReturns the number of rows in this matrix.getType()Returns the type of matrixvoidgrowMaxColumns(int desiredColumns, boolean preserveValue) Increases the maximum number of columns in the matrix.voidgrowMaxLength(int arrayLength, boolean preserveValue) Increases the maximum size of the data array so that it can store sparse data up to 'length'.voidhistogramToStructure(int[] histogram) Given the histogram of columns compute the col_idx for the matrix.booleanisAssigned(int row, int col) Is the specified element explicitly assigned a valuebooleanisFull()Returns true if number of non-zero elements is the maximum sizebooleanIf the indices has been sorted or notintnz_index(int row, int col) Returns the index in nz_rows for the element at (row,col) if it already exists in the matrix.voidprint()Prints the matrix to standard out using standard formatting.voidPrints the matrix to standard out with the specified formatting.voidPrints to standard out the non-zero elements only.voidremove(int row, int col) If the specified element is non-zero it is removed from the structurevoidreshape(int numRows, int numCols) Changes the number of rows and columns in the matrix.voidreshape(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.voidset(int row, int col, double val) Sets the value of the specified matrix element.voidSets this matrix to be identical to the 'original' matrix passed in.voidReduces the size of internal data structures to their minimal size.voidsortIndices(@Nullable SortCoupledArray_F64 sorter) Sorts the row indices in ascending order.doubleunsafe_get(int row, int col) Same asDMatrix.get(int, int)but does not perform bounds check on input parameters.doubleunsafe_get(int row, int col, double fallBackValue) Same asDMatrixSparse.get(int, int, double)but does not perform bounds check on input parameters.voidunsafe_set(int row, int col, double val) Same asMatrix.setTo(org.ejml.data.Matrix)but does not perform bounds check on input parameters.voidzero()Sets all values inside the matrix to zeroMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.ejml.data.DMatrix
getNumElements
-
Field Details
-
nz_values
public double[] nz_valuesStorage for non-zero values. Only valid up to length-1. -
nz_length
public int nz_lengthLength of data. Number of non-zero values in the matrix -
nz_rows
public int[] nz_rowsSpecifies which row a specific non-zero value corresponds to. If they are sorted or not with in each column is specified by theindicesSortedflag. -
col_idx
public int[] col_idxStores the range of indexes in the non-zero lists that belong to each column. Column 'i' corresponds to indexes col_idx[i] to col_idx[i+1]-1, inclusive. -
numRows
public int numRowsNumber of rows in the matrix -
numCols
public int numColsNumber of columns in the matrix -
indicesSorted
public boolean indicesSortedFlag that's used to indicate of the row indices are sorted or not.
-
-
Constructor Details
-
DMatrixSparseCSC
public DMatrixSparseCSC(int numRows, int numCols) Constructor with a default arrayLength of zero.- Parameters:
numRows- Number of rowsnumCols- Number of columns
-
DMatrixSparseCSC
public DMatrixSparseCSC(int numRows, int numCols, int arrayLength) Specifies shape and number of non-zero elements that can be stored.- Parameters:
numRows- Number of rowsnumCols- Number of columnsarrayLength- Initial maximum number of non-zero elements that can be in the matrix
-
DMatrixSparseCSC
-
-
Method Details
-
getNumRows
public int getNumRows()Description copied from interface:MatrixReturns the number of rows in this matrix.- Specified by:
getNumRowsin interfaceMatrix- Returns:
- Number of rows.
-
getNumCols
public int getNumCols()Description copied from interface:MatrixReturns the number of columns in this matrix.- Specified by:
getNumColsin interfaceMatrix- Returns:
- Number of columns.
-
copy
Description copied from interface:MatrixCreates an exact copy of the matrix -
createLike
Description copied from interface:MatrixCreates a new matrix with the same shape as this matrix- Specified by:
createLikein interfaceMatrix
-
setTo
Description copied from interface:MatrixSets this matrix to be identical to the 'original' matrix passed in. -
print
public void print()Description copied from interface:MatrixPrints the matrix to standard out using standard formatting. This is the same as calling print("%e") -
print
Description copied from interface:MatrixPrints the matrix to standard out with the specified formatting. -
printNonZero
public void printNonZero()Description copied from interface:MatrixSparsePrints to standard out the non-zero elements only.- Specified by:
printNonZeroin interfaceMatrixSparse
-
isAssigned
public boolean isAssigned(int row, int col) Description copied from interface:MatrixSparseIs the specified element explicitly assigned a value- Specified by:
isAssignedin interfaceMatrixSparse- Parameters:
row- the rowcol- the column- Returns:
- true if it has been assigned a value or false if not
-
get
public double get(int row, int col) Description copied from interface:DMatrixReturns the value of value of the specified matrix element. -
get
public double get(int row, int col, double fallBackValue) Description copied from interface:DMatrixSparseReturns the value of value of the specified matrix element.- Specified by:
getin interfaceDMatrixSparse- Parameters:
row- Matrix element's row index..col- Matrix element's column index.fallBackValue- Value to return, if the matrix element is not assigned- Returns:
- The specified element's value.
-
unsafe_get
public double unsafe_get(int row, int col) Description copied from interface:DMatrixSame asDMatrix.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.- Specified by:
unsafe_getin interfaceDMatrix- Parameters:
row- Matrix element's row index..col- Matrix element's column index.- Returns:
- The specified element's value.
-
unsafe_get
public double unsafe_get(int row, int col, double fallBackValue) Description copied from interface:DMatrixSparseSame asDMatrixSparse.get(int, int, double)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.- Specified by:
unsafe_getin interfaceDMatrixSparse- Parameters:
row- Matrix element's row index..col- Matrix element's column index.fallBackValue- Value to return, if the matrix element is not assigned- Returns:
- The specified element's value or the fallBackValue, if the element is not assigned.
-
nz_index
public 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. If not then -1 is returned.- Parameters:
row- row coordinatecol- column coordinate- Returns:
- nz_row index or -1 if the element does not exist
-
set
public void set(int row, int col, double val) Description copied from interface:DMatrixSets the value of the specified matrix element. -
unsafe_set
public void unsafe_set(int row, int col, double val) Description copied from interface:DMatrixSame asMatrix.setTo(org.ejml.data.Matrix)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.- Specified by:
unsafe_setin interfaceDMatrix- Parameters:
row- Matrix element's row index..col- Matrix element's column index.val- The element's new value.
-
remove
public void remove(int row, int col) Description copied from interface:MatrixSparseIf the specified element is non-zero it is removed from the structure- Specified by:
removein interfaceMatrixSparse- Parameters:
row- the rowcol- the column
-
zero
public void zero()Description copied from interface:MatrixSets all values inside the matrix to zero- Specified by:
zeroin interfaceMatrix- Specified by:
zeroin interfaceMatrixSparse
-
create
Description copied from interface:MatrixCreates a new matrix of the same type with the specified shape -
getNonZeroLength
public int getNonZeroLength()Description copied from interface:MatrixSparseReturns the number of non-zero elements.- Specified by:
getNonZeroLengthin interfaceMatrixSparse
-
reshape
public void reshape(int numRows, int numCols, int arrayLength) Description copied from interface:MatrixSparseReshapes the matrix so that it can store a matrix with the specified dimensions and the number of non-zero elements. The reshaped matrix will be empty.- Specified by:
reshapein interfaceMatrixSparse- Parameters:
numRows- number of rowsnumCols- number of columnsarrayLength- Array length for storing non-zero elements.
-
reshape
public void reshape(int numRows, int numCols) Description copied from interface:MatrixSparseChanges the number of rows and columns in the matrix. The graph structure is flushed and the matrix will be empty/all zeros. Similar toMatrixSparse.reshape(int, int, int), but the storage for non-zero elements is not changed- Specified by:
reshapein interfaceMatrixSparse- Specified by:
reshapein interfaceReshapeMatrix- Parameters:
numRows- number of rowsnumCols- number of columns
-
shrinkArrays
public void shrinkArrays()Description copied from interface:MatrixSparseReduces the size of internal data structures to their minimal size. No information is lost but the arrays will change- Specified by:
shrinkArraysin interfaceMatrixSparse
-
growMaxLength
public void growMaxLength(int arrayLength, boolean preserveValue) Increases the maximum size of the data array so that it can store sparse data up to 'length'. The class parameter nz_length is not modified by this function call.- Parameters:
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.
-
growMaxColumns
public void growMaxColumns(int desiredColumns, boolean preserveValue) Increases the maximum number of columns in the matrix.- Parameters:
desiredColumns- Desired number of columns.preserveValue- If the array needs to be expanded should it copy the previous values?
-
histogramToStructure
public void histogramToStructure(int[] histogram) Given the histogram of columns compute the col_idx for the matrix. nz_length is automatically set and nz_values will grow if needed.- Parameters:
histogram- histogram of column values in the sparse matrix. modified, see above.
-
sortIndices
Sorts the row indices in ascending order.- Parameters:
sorter- (Optional) Used to sort rows. If null a new instance will be declared internally.
-
copyStructure
Copies the non-zero structure of orig into "this"- Parameters:
orig- Matrix who's structure is to be copied
-
isIndicesSorted
public boolean isIndicesSorted()If the indices has been sorted or not- Returns:
- true if sorted or false if not sorted
-
isFull
public boolean isFull()Returns true if number of non-zero elements is the maximum size- Returns:
- true if no more non-zero elements can be added
-
getType
Description copied from interface:MatrixReturns the type of matrix -
createCoordinateIterator
Description copied from interface:DMatrixSparseCreates an iterator which will go through each non-zero value in the sparse matrix. Order is not defined and is implementation specific- Specified by:
createCoordinateIteratorin interfaceDMatrixSparse
-