Class CCSMatrix
java.lang.Object
org.la4j.Matrix
org.la4j.matrix.SparseMatrix
org.la4j.matrix.ColumnMajorSparseMatrix
org.la4j.matrix.sparse.CCSMatrix
This is a CCS (Compressed Column Storage) matrix class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[]private static final byteprivate static final intprivate int[]private double[]Fields inherited from class SparseMatrix
cardinality -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate intalign(int cardinality) blankOfShape(int rows, int columns) Creates the blank matrix (a zero matrix with same size) of this matrix of the given shape:rowsxcolumns.static CCSMatrixReturns a column-major matrix iterator.copyOfShape(int rows, int columns) Copies this matrix into the new matrix with specified dimensions:rowsandcolumns.static CCSMatrixdiagonal(int size, double diagonal) voideach(MatrixProcedure procedure) Applies givenprocedureto each element of this matrix.voideachInColumn(int j, VectorProcedure procedure) Applies givenprocedureto each element of specified column of this matrix.voideachNonZero(MatrixProcedure procedure) Applies givenprocedureto each non-zero element of this matrix.voideachNonZeroInColumn(int j, VectorProcedure procedure) Applies the givenprocedureto each non-zero element of the specified column of this matrix.static CCSMatrixfrom1DArray(int rows, int columns, double[] array) Creates a newCCSMatrixfrom the given 1Darraywith compressing (copying) the underlying array.static CCSMatrixfrom2DArray(double[][] array) Creates a newCCSMatrixfrom the given 2Darraywith compressing (copying) the underlying array.static CCSMatrixfromBinary(byte[] array) DecodesCCSMatrixfrom the given bytearray.static CCSMatrixParsesCCSMatrixfrom the given CSV string.static CCSMatrixParsesCCSMatrixfrom the given Matrix Market string.getColumn(int j) Copies the specified column of this matrix into the vector.doublegetOrElse(int i, int j, double defaultValue) Gets the specified element, or adefaultValueif there is no actual element at (i,j) in this sparse matrix.getRow(int i) Copies the specified row of this matrix into the vector.private voidgrowUp()static CCSMatrixidentity(int size) Creates an identityCCSMatrixof the givensize.private voidinsert(int k, int i, int j, double value) iteratorOfColumn(int j) Returns a vector iterator of the given column {code j}.doublemax()Searches for the maximum value of the elements of this matrix.doublemaxInColumn(int j) Searches for the maximum value of specified column in this matrix.doublemin()Searches for the minimum value of the elements of this matrix.doubleminInColumn(int j) Searches for the minimum value of specified column in this matrix.booleannonZeroAt(int i, int j) Whether or not the specified element is not zero.Returns a non-zero column-major matrix iterator.nonZeroIteratorOfColumn(int j) Returns a non-zero vector iterator of the given columnj.static CCSMatrixstatic CCSMatrixrandomSymmetric(int size, double density, Random random) Creates a random symmetricCCSMatrixof the givensize.private voidremove(int k, int j) private intsearchForRowIndex(int i, int left, int right) select(int[] rowIndices, int[] columnIndices) Returns a CCSMatrix with the selected rows and columns.voidset(int i, int j, double value) Sets the specified element of this matrix to givenvalue.voidsetAll(double value) Sets all elements of this matrix to the givenvalue.<T extends Matrix>
Tto(MatrixFactory<T> factory) Converts this matrix using the givenfactory.byte[]toBinary()Encodes this matrix into a byte array.voidupdateAt(int i, int j, MatrixFunction function) Updates the specified element of this matrix by applying givenfunction.static CCSMatrixzero(int rows, int columns) static CCSMatrixzero(int rows, int columns, int capacity) Methods inherited from class ColumnMajorSparseMatrix
apply, apply, apply, isRowMajor, iterator, nonZeroIterator, rotate, transposeMethods inherited from class SparseMatrix
add, capacity, cardinality, density, eachNonZeroInRow, ensureCardinalityIsCorrect, foldNonZero, foldNonZeroInColumn, foldNonZeroInColumns, foldNonZeroInRow, foldNonZeroInRows, get, isColumnMajor, isZeroAt, multiply, nonZeroIteratorOfRow, nonZeroRowMajorIterator, toMatrixMarketMethods inherited from class Matrix
add, blank, blankOfColumns, blankOfRows, columns, constant, copy, copyOfColumns, copyOfRows, determinant, diagonalProduct, divide, eachInRow, ensureDimensionsAreCorrect, ensureIndexesAreInBounds, equals, equals, euclideanNorm, fail, fold, foldColumn, foldColumns, foldRow, foldRows, hadamardProduct, hashCode, infinityNorm, insert, insert, insert, insert, insertColumn, insertRow, is, is, iteratorOfRow, kroneckerProduct, manhattanNorm, maxInRow, minInRow, mkString, mkString, mkString, multiply, multiply, multiplyByItsTranspose, non, non, norm, power, product, random, randomSymmetric, rank, removeColumn, removeFirstColumn, removeFirstRow, removeLastColumn, removeLastRow, removeRow, rowMajorIterator, rows, setColumn, setColumn, setRow, setRow, shuffle, slice, sliceBottomRight, sliceTopLeft, subtract, subtract, sum, swapColumns, swapRows, toColumnMajorSparseMatrix, toColumnVector, toCSV, toCSV, toDenseMatrix, toMatrixMarket, toRowMajorSparseMatrix, toRowVector, toSparseMatrix, toString, trace, transform, transformColumn, transformRow, unit, update, updateColumn, updateRow, withDecompositor, withInverter, withSolverMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
MATRIX_TAG
private static final byte MATRIX_TAG- See Also:
-
MINIMUM_SIZE
private static final int MINIMUM_SIZE- See Also:
-
values
private double[] values -
rowIndices
private int[] rowIndices -
columnPointers
private int[] columnPointers
-
-
Constructor Details
-
CCSMatrix
public CCSMatrix() -
CCSMatrix
public CCSMatrix(int rows, int columns) -
CCSMatrix
public CCSMatrix(int rows, int columns, int capacity) -
CCSMatrix
public CCSMatrix(int rows, int columns, int cardinality, double[] values, int[] rowIndices, int[] columnPointers)
-
-
Method Details
-
zero
-
zero
-
diagonal
-
identity
-
random
-
randomSymmetric
-
from1DArray
-
from2DArray
-
block
-
fromBinary
-
fromCSV
-
fromMatrixMarket
-
getOrElse
public double getOrElse(int i, int j, double defaultValue) Description copied from class:SparseMatrixGets the specified element, or adefaultValueif there is no actual element at (i,j) in this sparse matrix.- Specified by:
getOrElsein classSparseMatrix- Parameters:
i- the element's row indexj- the element's column indexdefaultValue- the default value- Returns:
- the element of this vector or a default value
-
set
-
setAll
-
getColumn
Description copied from class:MatrixCopies the specified column of this matrix into the vector.- Overrides:
getColumnin classSparseMatrix- Parameters:
j- the column index- Returns:
- the column represented as vector
-
getRow
Description copied from class:MatrixCopies the specified row of this matrix into the vector.- Overrides:
getRowin classSparseMatrix- Parameters:
i- the row index- Returns:
- the row represented as vector
-
copyOfShape
Description copied from class:MatrixCopies this matrix into the new matrix with specified dimensions:rowsandcolumns.- Specified by:
copyOfShapein classMatrix- Parameters:
rows- the number of rows in new matrixcolumns- the number of columns in new matrix- Returns:
- the copy of this matrix with new size
-
eachNonZero
Description copied from class:SparseMatrixApplies givenprocedureto each non-zero element of this matrix.- Overrides:
eachNonZeroin classSparseMatrix- Parameters:
procedure- the matrix procedure
-
each
Description copied from class:MatrixApplies givenprocedureto each element of this matrix. -
eachInColumn
Description copied from class:MatrixApplies givenprocedureto each element of specified column of this matrix.- Overrides:
eachInColumnin classMatrix- Parameters:
j- the column indexprocedure- the vector procedure
-
eachNonZeroInColumn
Description copied from class:SparseMatrixApplies the givenprocedureto each non-zero element of the specified column of this matrix.- Overrides:
eachNonZeroInColumnin classSparseMatrix- Parameters:
j- the column index.procedure- theVectorProcedure.
-
updateAt
Description copied from class:MatrixUpdates the specified element of this matrix by applying givenfunction. -
nonZeroAt
public boolean nonZeroAt(int i, int j) Description copied from class:SparseMatrixWhether or not the specified element is not zero.- Specified by:
nonZeroAtin classSparseMatrix- Parameters:
i- element's row indexj- element's column index- Returns:
trueif specified element is not zero,falseotherwise
-
searchForRowIndex
private int searchForRowIndex(int i, int left, int right) -
insert
private void insert(int k, int i, int j, double value) -
remove
private void remove(int k, int j) -
growUp
private void growUp() -
align
private int align(int cardinality) -
max
-
min
-
maxInColumn
public double maxInColumn(int j) Description copied from class:MatrixSearches for the maximum value of specified column in this matrix.- Overrides:
maxInColumnin classMatrix- Parameters:
j- the column index- Returns:
- maximum value of specified column in this matrix
-
minInColumn
public double minInColumn(int j) Description copied from class:MatrixSearches for the minimum value of specified column in this matrix.- Overrides:
minInColumnin classMatrix- Parameters:
j- the column index- Returns:
- minimum value of specified column in this matrix
-
select
Returns a CCSMatrix with the selected rows and columns. -
to
Description copied from class:MatrixConverts this matrix using the givenfactory. -
blankOfShape
Description copied from class:MatrixCreates the blank matrix (a zero matrix with same size) of this matrix of the given shape:rowsxcolumns.- Specified by:
blankOfShapein classMatrix- Returns:
- blank matrix
-
iteratorOrNonZeroColumns
- Specified by:
iteratorOrNonZeroColumnsin classColumnMajorSparseMatrix
-
columnMajorIterator
Description copied from class:MatrixReturns a column-major matrix iterator.- Overrides:
columnMajorIteratorin classMatrix- Returns:
- a column-major matrix iterator.
-
nonZeroColumnMajorIterator
Description copied from class:SparseMatrixReturns a non-zero column-major matrix iterator.- Overrides:
nonZeroColumnMajorIteratorin classSparseMatrix- Returns:
- a non-zero column major matrix iterator.
-
nonZeroIteratorOfColumn
Description copied from class:SparseMatrixReturns a non-zero vector iterator of the given columnj.- Overrides:
nonZeroIteratorOfColumnin classSparseMatrix- Returns:
- a non-zero vector iterator
-
iteratorOfColumn
Description copied from class:MatrixReturns a vector iterator of the given column {code j}.- Overrides:
iteratorOfColumnin classMatrix- Returns:
- a vector iterator
-
toBinary
-