koblas

Matrix

interface Matrix(source)

Mutable matrix contract with a fixed logical shape.

Inheritors

Properties

cols

abstract val cols: Int(source)

Number of columns.

rows

abstract val rows: Int(source)

Number of rows.

Functions

get

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

The entry at row (i), column (j). Throws IndexOutOfBoundsException outside the shape, whatever the storage.

set

abstract operator fun set(i: Int, j: Int, v: Double)(source)

Writes v to A(i, j). Throws IndexOutOfBoundsException outside the shape.

toArray

Materialise into a fresh Array<DoubleArray> of rows, independent of the internal storage.

Link copied to clipboard
fun Matrix.columnView(column: Int): Vector

A writable vector view of column. Mutations update this matrix; the vector's indices are local rows. Built-in containers return DenseVector or SparseVector; other implementations use Matrix.get and Matrix.set. Use Vector.copy for independent storage.

Link copied to clipboard

An independent copy of the logical entries. Sparse storage keeps its pattern, including stored zeros; dense views and custom matrices produce owning dense storage. No backing arrays are shared.

Link copied to clipboard
fun Matrix.copyFrom(source: Matrix)

Copies source into this matrix, requiring equal shapes before writing. Inputs may share storage; overlapping or opaque sources are snapshotted first. Entries outside a destination view are untouched.

Link copied to clipboard
inline fun Matrix.forEachColumns(block: (column: Vector) -> Unit)

Visits writable column views in column order, including empty columns. Mutations through a callback's vector update this matrix. Concrete containers retain their dense or sparse callback type for calls to KoblasEngine; through Matrix, callbacks use the generic Vector contract. Returns no new matrix.

Link copied to clipboard
inline fun Matrix.forEachStored(block: (row: Int, col: Int, value: Double) -> Unit)

Visits stored entries as (row, column, value), columns first and rows ascending within each column. SparseMatrix visits only stored positions, including stored zeros; other implementations visit every entry. Dense views report local indices and exclude padding. Empty matrices invoke no callbacks.

Link copied to clipboard
fun Matrix.norm(type: Norm = Norm.Frobenius): Double

Matrix norm of type: Norm.Frobenius is the rescaled square root of the sum of squared entries, Norm.One is the largest absolute column sum, Norm.Infinity is the largest absolute row sum, and Norm.MaxAbs is the maximum absolute entry. A matrix with either dimension empty has norm zero.

Link copied to clipboard

Plain sum of all entries. Dense storage uses KoblasEngine.sum through the default koblas engine, sparse storage sums only its stored values, and custom matrices are read through Matrix.get. An empty matrix sums to zero. Summation order and rounding depend on the storage and engine.

Sums along axis into a fresh dense vector: axis = 0 reduces rows and returns Matrix.cols column sums; axis = 1 reduces columns and returns Matrix.rows row sums. A zero-length reduced dimension contributes zero to each result. The result owns its storage.

Link copied to clipboard

Fresh transposed matrix. Sparse storage remains CSC and preserves stored zeros; other implementations produce dense storage. Views transpose only their logical entries. For products, prefer the transpose flags on KoblasEngine.gemv and KoblasEngine.gemm to avoid materializing the transpose.