Luna-Flow/linear-algebra is the linear-algebra layer of Luna Flow for
MoonBit. It provides dense matrices and vectors in two execution models
(immutable values and in-place buffers), numerical routines for floating-point
matrices, exact algorithms for integer matrices, and small capability layers so
that generic algorithms run on any matrix type that implements them. Every
operation that can fail at runtime has a checked form returning a structured
LinearAlgebraError.
///|
test "linear-algebra in a few lines" {
let a = @immut.Matrix::from_2d_array([[1, 1], [1, 0]])
inspect(a.pow(10).unwrap(), content="|89, 55|\n|55, 34|")
let m = @mutable.Matrix::from_2d_array([[4.0, 2.0], [2.0, 3.0]])
inspect(m.determinant().unwrap(), content="8")
inspect(m.inverse().unwrap(), content="|0.375, -0.25|\n|-0.25, 0.5|")
inspect(m.cholesky_decomposition().unwrap(), content="|2, 0|\n|1, 1.4142135623730951|")
}
Packages
Package
Purpose
immut
immutable Matrix, Vector and lazy MatrixFn; Bareiss determinants for integers, pivoted LU for floating point, and powers
mutable
in-place Matrix and Vector, row/column/transpose views; LU, inverse, rank, Cholesky, symmetric eigenvalues, power method, statistics
error
LinearAlgebraError and LinearAlgebraErrorKind for every checked API
arithmetic
scalar operation traits (Abs, ApproxEq, checked division, square root and comparison) and upstream re-exports
algebra
structure traits for whole vectors and matrices, from MatrixShape to MatMulMatrix (experimental)
backends/default
dense wrappers implementing the algebra traits over immut and mutable
container
storage-independent read/build/edit dictionaries and generic map, convert and transpose (experimental)
container/adapters
dictionaries for every vector and matrix type of this repository
internal, consistency
shared shape guards and cross-package agreement tests
perf, perf_runner, perf_support
benchmark subsystem (see bench/README.md)
The native OpenBLAS backend is not part of this release: its upstream binding
does not compile with MoonBit 0.10. The source and re-enable steps are kept in
contrib/openblas_backend.
Toolchain
MoonBit with moonc 0.10 or newer. The module builds without warnings with
moon check --target all and is tested on wasm-gc, js, wasm and
native. It depends on Luna-Flow/luna-generic0.4.0 and
Luna-Flow/arithmetic0.5.0.
Documentation
The manual (API, tutorials and design notes for every package, in English,
Chinese and Japanese) is published at https://lunaflow.cn/en/linear-algebra/.
Its English source is doc/manual; every example in
it is compiled and run as a test by src/doc_en_us. The design pages derive
the algorithms (LU, Cholesky, the symmetric eigensolver, Bareiss elimination)
and state their accuracy; the numerical routines of mutable use an absolute
tolerance of 1e-11, so scale data to order one, and read the
numerical caveats before relying
on @immut.Matrix::determinant for floating-point data. Release history is in CHANGELOG.md.
Development
moon check --target all
./run_test.sh # default gate on all targets
LINEAR_ALGEBRA_TEST_BENCH=1 ./run_test.sh # also the benchmark packages
just bench # full benchmark report
linear-algebra
Luna-Flow/linear-algebrais the linear-algebra layer of Luna Flow for MoonBit. It provides dense matrices and vectors in two execution models (immutable values and in-place buffers), numerical routines for floating-point matrices, exact algorithms for integer matrices, and small capability layers so that generic algorithms run on any matrix type that implements them. Every operation that can fail at runtime has a checked form returning a structuredLinearAlgebraError.Install
Example
Packages
immutMatrix,Vectorand lazyMatrixFn; Bareiss determinants for integers, pivoted LU for floating point, and powersmutableMatrixandVector, row/column/transpose views; LU, inverse, rank, Cholesky, symmetric eigenvalues, power method, statisticserrorLinearAlgebraErrorandLinearAlgebraErrorKindfor every checked APIarithmeticAbs,ApproxEq, checked division, square root and comparison) and upstream re-exportsalgebraMatrixShapetoMatMulMatrix(experimental)backends/defaultalgebratraits overimmutandmutablecontainercontainer/adaptersinternal,consistencyperf,perf_runner,perf_supportbench/README.md)The native OpenBLAS backend is not part of this release: its upstream binding does not compile with MoonBit 0.10. The source and re-enable steps are kept in
contrib/openblas_backend.Toolchain
MoonBit with
moonc0.10 or newer. The module builds without warnings withmoon check --target alland is tested onwasm-gc,js,wasmandnative. It depends onLuna-Flow/luna-generic0.4.0andLuna-Flow/arithmetic0.5.0.Documentation
The manual (API, tutorials and design notes for every package, in English, Chinese and Japanese) is published at https://lunaflow.cn/en/linear-algebra/. Its English source is
doc/manual; every example in it is compiled and run as a test bysrc/doc_en_us. The design pages derive the algorithms (LU, Cholesky, the symmetric eigensolver, Bareiss elimination) and state their accuracy; the numerical routines ofmutableuse an absolute tolerance of1e-11, so scale data to order one, and read the numerical caveats before relying on@immut.Matrix::determinantfor floating-point data. Release history is in CHANGELOG.md.Development
Contributing
See CONTRIBUTING.md. Commits follow Conventional Commits.
License
Apache-2.0. See LICENSE.