Class R064CSC
java.lang.Object
org.ojalgo.matrix.store.AbstractStore<Double>
org.ojalgo.matrix.store.FactoryStore<Double>
org.ojalgo.matrix.store.CompressedSparseR064
org.ojalgo.matrix.store.R064CSC
- All Implemented Interfaces:
Group, Group.Additive<MatrixStore<Double>>, NormedVectorSpace<MatrixStore<Double>, Double>, Operation, Operation.Addition<MatrixStore<Double>>, Operation.Multiplication<MatrixStore<Double>>, Operation.Subtraction<MatrixStore<Double>>, ScalarOperation, ScalarOperation.Addition<MatrixStore<Double>, Double>, ScalarOperation.Division<MatrixStore<Double>, Double>, ScalarOperation.Multiplication<MatrixStore<Double>, Double>, ScalarOperation.Subtraction<MatrixStore<Double>, Double>, VectorSpace<MatrixStore<Double>, Double>, Matrix2D<Double, MatrixStore<Double>>, ElementsSupplier<Double>, MatrixStore<Double>, SparseStructure2D, Access1D<Double>, Access1D.Aggregatable<Double>, Access1D.Collectable<Double,Mutate1D>, Access1D.Sliceable<Double>, Access1D.Visitable<Double>, Access2D<Double>, Access2D.Aggregatable<Double>, Access2D.Collectable<Double, TransformableRegion<Double>>, Access2D.Sliceable<Double>, Access2D.Visitable<Double>, Operate2D<Double, ElementsSupplier<Double>>, Structure1D, Structure2D, Structure2D.Logical<Access2D<Double>, MatrixStore<Double>>, Structure2D.ReducibleTo1D<ElementsSupplier<Double>>
A compressed sparse column (CSC) matrix store implementation for double precision values. This format is
efficient for column-wise operations and matrix-vector multiplication.
The CSC format uses three arrays to store the matrix:
- values[] - stores the non-zero values
- rowIndices[] - stores the row index for each non-zero value
- columnPointers[] - stores the starting position in values/rowIndices arrays for each column
This format is particularly efficient for:
- Column-wise access and operations
- Matrix-vector multiplication
- Iterating over non-zero elements column by column
SparseStore,
RowsSupplier and ColumnsSupplier feature direct conversion to R064CSC. In
particular ColumnsSupplier could be of interest in this case. Furthermore, R064CSC.Builder
is provided for incrementally constructing a CSC matrix.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for constructingR064CSRinstances.static final classNested classes/interfaces inherited from interface Access2D
Access2D.Aggregatable<N>, Access2D.Collectable<N,R>, Access2D.ColumnView<N>, Access2D.ElementView<N>, Access2D.RowView<N>, Access2D.SelectionView<N>, Access2D.Sliceable<N>, Access2D.Visitable<N> Nested classes/interfaces inherited from interface Group
Group.Additive<T>, Group.Multiplicative<T>Nested classes/interfaces inherited from interface Operation
Operation.Addition<T>, Operation.Division<T>, Operation.Multiplication<T>, Operation.Subtraction<T>Nested classes/interfaces inherited from interface ScalarOperation
ScalarOperation.Addition<T,N>, ScalarOperation.Division<T, N>, ScalarOperation.Multiplication<T, N>, ScalarOperation.Subtraction<T, N> Nested classes/interfaces inherited from interface Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.Logical<S,B>, Structure1D.LongIndex, Structure1D.LoopCallback Nested classes/interfaces inherited from interface Structure2D
Structure2D.IntRowColumn, Structure2D.Logical<S,B>, Structure2D.LongRowColumn, Structure2D.ReducibleTo1D<R>, Structure2D.Reshapable, Structure2D.RowColumnKey<R, C>, Structure2D.RowColumnMapper<R, C> -
Field Summary
Fields inherited from class CompressedSparseR064
indices, pointers, values -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbtran(R064CSC mtrxL, int r, PhysicalStore<Double> arg) Assumes mtrxL is unit lower/left triangular, with the unit diagonal not stored.static voidcalculateInfinityColumnNorms(R064CSC matrix, double[] norms) static voidcalculateInfinityRowNorms(R064CSC matrix, double[] norms) static voidcalculateInfinitySymmetricNorms(R064CSC matrix, double[] norms) Algorithm assumes that the matrix is symmetric, and only a triangular part is stored.copyCSC()Creates a deep copy of this CSC matrix store.doubledoubleValue(int row, int col) Gets the value at the specified row and column.intfirstInColumn(int col) The default value is simply0, and if all elements are zeros thenthis.countRows().intfirstInRow(int row) The default value is simply0, and if all elements are zeros thenthis.countColumns().static voidftran(R064CSC mtrxL, int r, PhysicalStore<Double> arg) Assumes mtrxL is unit lower/left triangular, with the unit diagonal not stored.intlimitOfColumn(int col) The default value is simplythis.countRows(), and if all elements are zeros then0.intlimitOfRow(int row) The default value is simplythis.countColumns(), and if all elements are zeros then0.static voidTransposed matrix-vector multiplication: data' = left' * right (A'x = y invalid input: '<'-> x'A = y')static voidGeneral matrix-vector multiplication: data = left * rightvoidmultiply(Access1D<Double> right, TransformableRegion<Double> target) Performs matrix-vector multiplication using the CSC format.static voidmultiplySymmetric(double[] data, R064CSC matrix, double[] vector) For a symmetric matrix A, the matrix-vector products A * x and x * A are equal.static R064CSC.Builderstatic R064CSC.BuildernewBuilder(int dim) static R064CSC.BuildernewBuilder(int nbRows, int nbCols) nonzeros()Similar toAccess1D.elements()but avoids elements that are structurally known to be zero.static voidScales all non-zero entries of a sparse matrix by a scalar.static voidscaleColumns(R064CSC matrix, double[] scalars) static voidtoCSC()toCSR()Methods inherited from class CompressedSparseR064
capacity, countNonzeros, getMethods inherited from class AbstractStore
buildColumn, buildColumn, buildColumn, buildRow, buildRow, buildRow, cast, countColumns, countRows, getColDim, getComponentType, getMaxDim, getMinDim, getRowDim, isPrimitive, multiplyBoth, toStringMethods inherited from interface Access1D
asCollectable1D, asKeyed1D, asList, axpy, dot, select, supplyTo, toList, toRawCopy1DMethods inherited from interface Access1D.Collectable
collectMethods inherited from interface Access1D.Visitable
visitAll, visitRangeMethods inherited from interface Access2D
asCollectable2D, asKeyed2D, byteValue, byteValue, byteValue, byteValue, columns, doubleValue, doubleValue, doubleValue, elements, floatValue, floatValue, floatValue, floatValue, get, intValue, intValue, intValue, intValue, longValue, longValue, longValue, longValue, rows, shortValue, shortValue, shortValue, shortValue, toRawCopy2DMethods inherited from interface Access2D.Aggregatable
aggregateColumn, aggregateDiagonal, aggregateRow, reduceColumns, reduceRowsMethods inherited from interface Access2D.Collectable
collectMethods inherited from interface Access2D.Sliceable
sliceColumn, sliceDiagonal, sliceRowMethods inherited from interface Access2D.Visitable
visitColumn, visitColumn, visitDiagonal, visitDiagonal, visitOne, visitRow, visitRowMethods inherited from interface ElementsSupplier
onAny, onColumns, onColumns, onMatching, onMatching, onRows, onRowsMethods inherited from interface MatrixStore
above, above, above, add, add, add, aggregateAll, aggregateColumn, aggregateDiagonal, aggregateRange, aggregateRow, below, below, below, bidiagonal, column, column, columns, columns, conjugate, copy, diagonal, diagonally, divide, divide, equals, get, get, hermitian, hessenberg, indexOfLargest, isHermitian, isNormal, isSmall, isSmall, left, left, left, limits, logical, multiply, multiply, multiply, negate, norm, offsets, onAll, operate, power, premultiply, reduceColumns, reduceRows, repeat, right, right, right, row, row, rows, rows, select, select, signum, sliceColumn, sliceDiagonal, sliceRange, sliceRow, subtract, subtract, subtract, superimpose, superimpose, supplyTo, supplyTo, symmetric, toScalar, triangular, tridiagonal, visitOneMethods inherited from interface Operate2D
onAll, onAll, onAll, onAll, onAll, onCompatible, onCompatibleMethods inherited from interface ScalarOperation.Addition
addMethods inherited from interface ScalarOperation.Division
divideMethods inherited from interface ScalarOperation.Multiplication
multiplyMethods inherited from interface ScalarOperation.Subtraction
subtractMethods inherited from interface SparseStructure2D
density
-
Constructor Details
-
R064CSC
public R064CSC(int nbRows, int nbCols, double[] elementValues, int[] rowIndices, int[] columnPointers) Creates a new CSC matrix store.- Parameters:
elementValues- The non-zero valuesrowIndices- The row index for each non-zero valuecolumnPointers- The starting position in elementValues/rowIndices for each columnrows- The number of rows in the matrixcols- The number of columns in the matrix
-
R064CSC
public R064CSC(int nbRows, int nbCols, int capacity) - Parameters:
nbRows- The number of rowsnbCols- The number of columnscapacity- The maximum number of non-zero elements
-
-
Method Details
-
btran
Assumes mtrxL is unit lower/left triangular, with the unit diagonal not stored. -
calculateInfinityColumnNorms
-
calculateInfinityRowNorms
-
calculateInfinitySymmetricNorms
Algorithm assumes that the matrix is symmetric, and only a triangular part is stored.This implementation does NOT reset the norms array! If that array contains non-zero values those will be taken into account when calculating the norms.
-
ftran
Assumes mtrxL is unit lower/left triangular, with the unit diagonal not stored. -
multiply
Transposed matrix-vector multiplication: data' = left' * right (A'x = y invalid input: '<'-> x'A = y') -
multiply
General matrix-vector multiplication: data = left * rightThe data array will be completely overwritten. No need to pre-fill it with zeros.
- Parameters:
data- The array to store the resultleft- The left matrix in CSC formatright- The right vector
-
multiplySymmetric
For a symmetric matrix A, the matrix-vector products A * x and x * A are equal. This method implements that assuming the matrix is symmetric but only stores the upper/right triangle. -
newBuilder
-
newBuilder
-
newBuilder
-
scale
Scales all non-zero entries of a sparse matrix by a scalar. -
scaleColumns
-
scaleRows
-
copyCSC
Creates a deep copy of this CSC matrix store. -
doubleValue
public double doubleValue(int row, int col) Gets the value at the specified row and column. Returns 0.0 if the element is not stored (i.e., is zero).- Parameters:
row- The row indexcol- The column index- Returns:
- The value at the specified position, or 0.0 if not stored
-
firstInColumn
public int firstInColumn(int col) Description copied from interface:Structure2DThe default value is simply0, and if all elements are zeros thenthis.countRows().- Parameters:
col- The column index- Returns:
- The row index of the first non-zero element in the specified column
-
firstInRow
public int firstInRow(int row) Description copied from interface:Structure2DThe default value is simply0, and if all elements are zeros thenthis.countColumns().- Returns:
- The column index of the first non-zero element in the specified row
-
limitOfColumn
public int limitOfColumn(int col) Description copied from interface:Structure2DThe default value is simplythis.countRows(), and if all elements are zeros then0.- Specified by:
limitOfColumnin interfaceStructure2D- Overrides:
limitOfColumnin classAbstractStore<Double>- Returns:
- The row index of the first zero element, after all non-zeros, in the specified column (index of the last non-zero + 1)
-
limitOfRow
public int limitOfRow(int row) Description copied from interface:Structure2DThe default value is simplythis.countColumns(), and if all elements are zeros then0.- Specified by:
limitOfRowin interfaceStructure2D- Overrides:
limitOfRowin classAbstractStore<Double>- Returns:
- The column index of the first zero element, after all non-zeros, in the specified row (index of the last non-zero + 1)
-
multiply
Performs matrix-vector multiplication using the CSC format. This implementation is optimized for the CSC format by iterating over non-zero elements column by column and accumulating the results.- Parameters:
right- The vector to multiply withtarget- The target vector to store the result
-
nonzeros
Description copied from interface:Access1DSimilar toAccess1D.elements()but avoids elements that are structurally known to be zero. (That does not eliminate all zero-values from this view.) With an arbitrary (dense) unstructured implementation theAccess1D.nonzeros()andAccess1D.elements()methods do the same thing! Only some specific implementations are able to actually exploit structure/sparsity to view fewer elements. -
toCSC
-
toCSR
-
transpose
- Returns:
- A transposed matrix instance.
-