@mutable.Matrix
This page documents the current 0.3.0 repository behavior. Square-root-dependent APIs use Luna-Flow/arithmetic.Sqrt; Tolerance remains defined by mutable.
Overview
@mutable.Matrixis mutation-oriented.set,swap_rows,swap_cols,map_inplace, row/column view updates, and transpose updates modify the underlying matrix in place.- Public storage is a flat row-major
Array[T]across backends. Backend-specific files differ in execution tuning, not in the public matrix model. - Public access is strict about bounds.
get,set,m[row][col],row_view,col_view, extraction helpers, iterators, and transpose-view access reject out-of-range indices consistently, including zero-row and zero-column edge shapes. swap_rows(i, i)andswap_cols(i, i)are no-op operations. Out-of-range row or column indices panic explicitly instead of relying on accidental storage access.
Core Matrix API
Matrix::make(row, col, f)Builds a matrix from a generator function. Negative dimensions panic.Matrix::new(row, col, elem)Builds a matrix filled withelem. Negative dimensions panic.Matrix::from_2d_array(arr)Creates a matrix from a rectangular 2D array. Ragged input panics.Matrix::from_array(row, col, data)Uses a flat row-major array as matrix storage. Negative dimensions or wrong element count panic.row()/col()Return the stored shape.get(row, col)/set(row, col, elem)Fast random access with explicit bounds checks.m[row][col]Convenience syntax backed byLens[T]. It is valid for read and write, but repeated bulk work should preferrow_view,col_view, or the dedicated row/column helpers.copy()Deep-copies the matrix.map,mapiReturn a transformed matrix.map_inplace,map_row_inplace,map_col_inplaceApply in-place transforms.each,eachi,each_row_col,each_row,each_col,eachi_row,eachi_colTraversal helpers.iter,iter_row,iter_colIterators with checked row/column bounds.row_to_array,col_to_array,row_to_vector,col_to_vector,to_array,to_2d_array,to_vectorMaterialization helpers with checked indices where applicable.transpose()Returns a materialized transpose.to_transpose()Returns a live transpose view.horizontal_combine,vertical_combineConcatenate compatible matrices.
Views And Transpose
row_view(row)/col_view(col)Return live views into the underlying matrix.RowViewandColViewExposeget,set,iter,each,eachi,map_inplace,to_array, andto_vector.TransposeExposes the same matrix-like surface over a live transposed view.Transpose::swap_rowsandTranspose::swap_colsDelegate to the underlying matrix with the same strict bounds semantics.
Algebraic And Numeric API
+,-,*Matrix addition, subtraction, and multiplication.scale(cst),add_constant(cst), unary-Element-wise scalar transforms.identity(size)Identity matrix constructor. Negativesizepanics.pow(power)Square-matrix exponentiation for non-negative integer powers.matrix_power(n)Public wrapper aroundpow(n).trace()Sum of diagonal entries. Requires a square matrix.determinant()Determinant of a square matrix.inverse(),is_invertible()Inversion helpers for square matrices.rank()Rank computed through the current repository algorithm.reduce_row_elimination()In-place-style row reduction on the mutable matrix value.cholesky_decomposition()Cholesky factorization for supported numeric inputs.eigen(),power_method(),eigen_2x2()Current eigen-related APIs for supported numeric cases.is_square(),null(),is_symmetric(),is_positive_definite()Structural and numeric predicates.mean(),variance(),std_dev(),frobenius_norm(),max_element(),min_element()Aggregate numeric helpers.
Notes On Correctness
- Backends are expected to expose the same public semantics. The repository currently keeps separate kernel files for
native,js,wasm, andwasm-gc, so tests and documentation should be read as backend-invariant unless a note says otherwise. - For code shared across
immutandmutable, rely on the common algebraic surface and not on identical mutation semantics.