Package de.labathome.trustconstr.sparse
Class CSCMatrix
java.lang.Object
de.labathome.trustconstr.sparse.CSCMatrix
Compressed Sparse Column matrix.
Storage analogue of
scipy.sparse.csc_array. Layout mirrors
CSRMatrix with rows and columns swapped:
indptr.length == cols + 1 indptr[j] .. indptr[j+1] is the half-open range ofWithin a column the entries are kept sorted by row index. The CSC format is needed by trust-constr in two places:indices/dataentries belonging to column j. indices[k] is the row of the k-th stored entry (0 ≤ indices[k] < rows). data[k] is the value of the k-th stored entry.
- The KKT projection block (
projections.py:99) is materialised in CSC becausescipy.sparse.linalg.factorizedprefers it. A^Tof a CSR Jacobian is naturally CSC of the same data.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCSCMatrix(int rows, int cols, int[] indptr, int[] indices, double[] data) Construct from raw CSC triplets. -
Method Summary
Modifier and TypeMethodDescriptionintcols()double[]data()static CSCMatrixeye(int n) n x nidentity in CSC.static CSCMatrixfromDense(double[][] dense) Build CSC from a dense 2D array; column-major scan, but the input is still given as row-majordense[i][j].int[]indices()int[]indptr()double[]matvec(double[] x) Matrix-vector producty = A x.multiply(double s) Element-wise scalar multiply (allocates a new matrix).intnnz()double[]rmatvec(double[] x) Transposed matrix-vector producty = A^T x.introws()toCSR()Convert to CSR of the same matrix (not the transpose).double[][]toDense()Materialise as a dense[rows][cols]array.Transpose.
-
Constructor Details
-
CSCMatrix
public CSCMatrix(int rows, int cols, int[] indptr, int[] indices, double[] data) Construct from raw CSC triplets. Inputs are defensively copied. See the class-level invariants for shape and ordering requirements.- Parameters:
rows- number of rowscols- number of columnsindptr- column pointer array, lengthcols + 1indices- row index for each stored entrydata- value for each stored entry
-
-
Method Details
-
rows
public int rows()- Returns:
- number of rows
-
cols
public int cols()- Returns:
- number of columns
-
nnz
public int nnz()- Returns:
- number of stored (structural) non-zero entries
-
indptr
public int[] indptr()- Returns:
- defensive copy of the column pointer array
-
indices
public int[] indices()- Returns:
- defensive copy of the row index array
-
data
public double[] data()- Returns:
- defensive copy of the value array
-
fromDense
Build CSC from a dense 2D array; column-major scan, but the input is still given as row-majordense[i][j].- Parameters:
dense-[m][n]row-major dense values- Returns:
- CSC matrix with the same non-zero pattern as
dense
-
toDense
public double[][] toDense()Materialise as a dense[rows][cols]array.- Returns:
- fresh row-major dense view
-
eye
n x nidentity in CSC.- Parameters:
n- dimension; must be non-negative- Returns:
- the
n x nidentity matrix
-
matvec
public double[] matvec(double[] x) Matrix-vector producty = A x. -
rmatvec
public double[] rmatvec(double[] x) Transposed matrix-vector producty = A^T x. -
multiply
Element-wise scalar multiply (allocates a new matrix).- Parameters:
s- scalar factor- Returns:
s * this
-
transpose
Transpose. Same nnz, rows and columns swapped. The natural output is CSR because a CSC column traversal ofAis a CSR row traversal ofA^T.- Returns:
A^Tas aCSRMatrix
-
toCSR
Convert to CSR of the same matrix (not the transpose).- Returns:
- CSR representation of this matrix
-