koblas

SparseMatrix

@Serializable
@SerialName(value = "SparseMatrix")
class SparseMatrix : MatrixStorage(source)

Compressed-sparse-column form: column j occupies colPointers(j) until colPointers(j + 1) of rowIndices and values, rows strictly ascending. A stored zero is preserved, and a 64-bit-index host library needs a widening copy.

Use copyColumnPointers, copyRowIndices, or forEachInColumn for safe structural access. colPointers and rowIndices are live zero-copy escape hatches for specialized kernels and require UnsafeKoblasApi; mutating them can invalidate the CSC structure. values remains live so coefficients can be updated without rebuilding the pattern; do not use the matrix as a hash-map key while mutating it.

Types

Link copied to clipboard
object Companion

Factories for sparse matrices.

Properties

colPointers

cols

open override val cols: Int(source)

nnz

val nnz: Int(source)

Number of stored nonzeros.

rowIndices

rows

open override val rows: Int(source)

values

Functions

copyColumnPointers

A copy of the CSC column start offsets, of length cols + 1.

copyRowIndices

A copy of the stored row indices, parallel to values.

equals

open operator override fun equals(other: Any?): Boolean(source)

Structural equality over the shape and the CSC arrays, so two matrices differing only in which explicit zeros they store are not equal.

forEachInColumn

inline fun forEachInColumn(j: Int, action: (row: Int, value: Double) -> Unit)(source)

Visits the stored entries of column j as (row, value), rows ascending.

get

open operator override fun get(i: Int, j: Int): Double(source)

Reads entry (i, j), or 0.0 where nothing is stored. A binary search over the column, so O(log nnzⱼ) and fine for a probe; sweep with forEachInColumn instead.

hashCode

open override fun hashCode(): Int(source)

toArray

open override fun toArray(): Array<DoubleArray>(source)

Materialises into a fresh rows × cols array of rows; unstored entries stay zero.

toString

open override fun toString(): String(source)
Link copied to clipboard

Column j as a fresh sparse vector. Runs in O(nnzⱼ) time and allocates copies of its stored indices and values, so later mutations to the returned vector's indices or values cannot affect this matrix. Explicitly stored zeros are preserved.

Link copied to clipboard
@JvmName(name = "subtract")
operator fun SparseMatrix.minus(other: SparseMatrix): SparseMatrix

A - B, allocating an owned CSC structural union.

Link copied to clipboard
@JvmName(name = "add")
operator fun SparseMatrix.plus(other: SparseMatrix): SparseMatrix

A + B, allocating an owned CSC structural union.

Link copied to clipboard

Row i as a fresh sparse vector whose stored positions are the source columns. Runs in O(nnz) time, scanning every stored entry in the matrix to gather the ones in this row, and allocates arrays sized to its stored entries. The returned vector is independent of this matrix, and explicitly stored zeros are preserved.

Link copied to clipboard

Fresh CSC matrix holding A + alpha * x * xT in its lower or upper triangle. The other triangle is copied unchanged. Unlike dense com.eignex.koblas.dense.DenseBlas.syr, this is not in place: a rank update can introduce entries that the source CSC pattern has no room to store.

Link copied to clipboard

Fresh CSC matrix holding A + alpha * (x * yT + y * xT) in its lower or upper triangle. The other triangle is copied unchanged. This structural counterpart of dense com.eignex.koblas.dense.DenseBlas.syr2 never mutates its source, because newly nonzero entries may require CSC fill.

Link copied to clipboard
@JvmName(name = "multiplyMatrices")
operator fun Matrix.times(other: Matrix): Matrix

Allocating product through koblas: two sparse operands give CSC storage, any other pairing dense.

@JvmName(name = "multiply")
operator fun SparseMatrix.times(other: DenseMatrix): DenseMatrix

A * B for a sparse left operand and dense right operand, allocating dense storage.

@JvmName(name = "multiply")
operator fun SparseMatrix.times(other: SparseMatrix): SparseMatrix

A * B for two sparse matrices, allocating the discovered CSC structure.

Link copied to clipboard

Fresh transposed matrix, still CSC, which makes this the CSC-to-CSR conversion as well. Explicitly stored zeros survive, since the transpose is structural rather than arithmetic.

Link copied to clipboard

Fresh matrix with column column replaced by entering, still CSC. The replacement is structural, so an explicitly stored zero in entering survives as one.