Package de.labathome.trustconstr.matrix
Class SparseMatrix
java.lang.Object
de.labathome.trustconstr.matrix.Matrix
de.labathome.trustconstr.matrix.SparseMatrix
Sparse matrix backed by a Dictionary-of-Keys (DOK) representation:
a
HashMap keyed by the encoded (row, col) index. Supports
cheap incremental setAsDouble(double, long, long) (the equivalent of scipy's
lil_matrix build phase) and converts to
CSRMatrix for compute-heavy
paths via toCSR().
Compute kernels (mtimes(Matrix), plus(Matrix) etc.)
materialise to dense or convert to CSR internally -- no attempt is made to
keep results sparse. The trust-constr port only relies on sparsity in a
handful of well-known places (Jacobian storage and the AUGMENTED_SYSTEM
KKT factorization, both of which already drop into the CSR fast paths).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classStatic factories that produceSparseMatrixinstances. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()copy()divide(double alpha) doublegetAsDouble(long row, long col) longlongbooleanisSparse()intnnz()doublenorm2()doublenormInf()voidsetAsDouble(double v, long row, long col) times(double alpha) toCSR()Materialise this sparse matrix to aCSRMatrix(canonical CSR form: column indices sorted within each row, no explicit zeros).Methods inherited from class de.labathome.trustconstr.matrix.Matrix
absInPlace, doubleValue, equalsContent, fill, getSize, isColumnVector, isRowVector, mapAdd, minus, normF, plus, rank, selectColumns, solve, subMatrix, toColumnArray, toDoubleArray
-
Constructor Details
-
SparseMatrix
public SparseMatrix(int rows, int cols) Allocate a fresh empty sparse matrix.- Parameters:
rows- number of rowscols- number of columns
-
-
Method Details
-
isSparse
public boolean isSparse() -
getRowCount
public long getRowCount()- Specified by:
getRowCountin classMatrix- Returns:
- number of rows
-
getColumnCount
public long getColumnCount()- Specified by:
getColumnCountin classMatrix- Returns:
- number of columns
-
getAsDouble
public double getAsDouble(long row, long col) - Specified by:
getAsDoublein classMatrix- Parameters:
row- 0-based row indexcol- 0-based column index- Returns:
- entry at
(row, col)
-
setAsDouble
public void setAsDouble(double v, long row, long col) - Specified by:
setAsDoublein classMatrix- Parameters:
v- value to storerow- 0-based row indexcol- 0-based column index
-
nnz
public int nnz()- Returns:
- number of stored (non-zero) entries
-
toCSR
Materialise this sparse matrix to aCSRMatrix(canonical CSR form: column indices sorted within each row, no explicit zeros).- Returns:
- a CSR view of the same content
-
copy
-
mtimes
-
plus
-
minus
-
times
-
times
-
divide
-
divide
-
transpose
-
abs
-
norm2
public double norm2() -
normInf
public double normInf()
-