moonbitstack/moonmcl/linear does not have a README file

    Refused

    pub(all) suberror Refused {
    Dimension(got~ : Int, want~ : Int)
    Empty
    Singular(at~ : Int)
    NotPositiveDefinite(at~ : Int)
    Gain(got~ : Double)
    Range(got~ : Double, low~ : Double, high~ : Double)
    Exceeded(limit~ : Int, got~ : Int)
    Unreachable
    }

    A refusal: the input was not acceptable, or a computation could not reach a result.

    Dimension carries a size that does not fit the operation; Singular and NotPositiveDefinite name the pivot index that failed; Exceeded reports an iteration budget that ran out with the value it reached.

    Eigh

    pub(all) struct Eigh {
    values : Vec
    vectors : Mat
    } derive(
    Debug
    )

    The eigenvalues and eigenvectors of a symmetric matrix.

    values is ascending and vectors has the matching eigenvector in its matching column, so a * v[:, i] = values[i] * v[:, i].

    Eigh::to_repr

    pub(all) struct Lu {
    n : Int
    lower : Mat
    upper : Mat
    perm : Array[Int]
    sign : Double
    } derive(
    Debug
    )

    An LU factorisation with partial pivoting, perm * A = lower * upper, where lower is unit lower triangular and upper is upper triangular.

    sign is the parity of the row swaps, so det = sign * product(upper). The factorisation is kept so that several right-hand sides can reuse it, which is what the estimators do inside a filter loop.

    Lu::det

    fn Lu::det(self : Lu) -> Double

    The determinant of the factorised matrix.

    Lu::solve

    fn Lu::solve(self : Lu, b : Mat) -> Mat raise Refused

    Solve a * x = b from a factorisation. b has one column per right-hand side; the result has the same width.

    Lu::to_repr

    Mat

    pub(all) struct Mat {
    rows : Int
    cols : Int
    data : FixedArray[Double]
    } derive(
    Debug
    )

    A dense matrix of Double in row-major order.

    Element (i, j) lives at data[i * cols + j]. The arithmetic methods return new matrices; set is the only writer.

    Mat::add

    fn Mat::add(self : Mat, other : Mat) -> Mat

    The elementwise sum. Both matrices must have the same shape.

    Mat::add_to

    fn Mat::add_to(self : Mat, i : Int, j : Int, value : Double) -> Unit

    Add value to the entry at (i, j).

    Mat::apply

    fn Mat::apply(self : Mat, v : Vec) -> Vec

    The product self * v.

    Mat::apply_transposed

    fn Mat::apply_transposed(self : Mat, v : Vec) -> Vec

    The product v^T * self, a row vector times the matrix.

    Mat::approx

    fn Mat::approx(self : Mat, other : Mat, tolerance? : Double) -> Bool

    Whether self and other agree entry by entry within tolerance.

    Mat::at

    fn Mat::at(self : Mat, i : Int, j : Int) -> Double?

    The entry at (i, j), or None when the index is outside the matrix.

    Mat::augment

    fn Mat::augment(self : Mat, right : Mat) -> Mat

    self with right appended on the right, so the result is rows x (cols + right.cols).

    Mat::block

    fn Mat::block(self : Mat, row~ : Int, col~ : Int, height~ : Int, width~ : Int) -> Mat

    The height x width block whose top-left corner is (row, col).

    Mat::col

    fn Mat::col(self : Mat, j : Int) -> Vec

    The j-th column, copied out.

    Mat::diagonal

    fn Mat::diagonal(values : Vec) -> Mat

    A diagonal matrix with values on the diagonal.

    Mat::filled

    fn Mat::filled(rows : Int, cols : Int, value : Double) -> Mat

    A rows x cols matrix with every entry value.

    Mat::from_fixed

    fn Mat::from_fixed(rows : Int, cols : Int, data : FixedArray[Double]) -> Mat

    A matrix that takes over data without copying it. data holds the entries row by row.

    Mat::get

    fn Mat::get(self : Mat, i : Int, j : Int) -> Double

    The entry at (i, j). An index outside the matrix aborts.

    Mat::identity

    fn Mat::identity(n : Int) -> Mat

    The n x n identity.

    Mat::is_finite

    fn Mat::is_finite(self : Mat) -> Bool

    Whether every entry is finite.

    Mat::mul

    fn Mat::mul(self : Mat, other : Mat) -> Mat

    The product self * other.

    Mat::negate

    fn Mat::negate(self : Mat) -> Mat

    Every entry negated.

    Mat::of

    fn Mat::of(values : Array[Array[Double]]) -> Mat

    A matrix whose rows are values; every row must have the same length.

    Mat::row

    fn Mat::row(self : Mat, i : Int) -> Vec

    The i-th row, copied out.

    Mat::scale

    fn Mat::scale(self : Mat, factor : Double) -> Mat

    Every entry multiplied by factor.

    Mat::set

    fn Mat::set(self : Mat, i : Int, j : Int, value : Double) -> Unit

    Overwrite the entry at (i, j).

    Mat::set_col

    fn Mat::set_col(self : Mat, j : Int, values : Vec) -> Unit

    Overwrite the j-th column with values.

    Mat::set_row

    fn Mat::set_row(self : Mat, i : Int, values : Vec) -> Unit

    Overwrite the i-th row with values.

    Mat::stack

    fn Mat::stack(self : Mat, below : Mat) -> Mat

    self with below appended underneath, so the result is (rows + below.rows) x cols.

    Mat::sub

    fn Mat::sub(self : Mat, other : Mat) -> Mat

    The elementwise difference. Both matrices must have the same shape.

    Mat::to_array_rows

    fn Mat::to_array_rows(self : Mat) -> Array[Array[Double]]

    The rows copied into growable arrays, for output and test expectations.

    Mat::to_repr

    Mat::to_string

    fn Mat::to_string(self : Mat) -> String

    One line per row, each formatted like a Vec.

    Mat::trace

    fn Mat::trace(self : Mat) -> Double

    The sum of the diagonal entries.

    Mat::transpose

    fn Mat::transpose(self : Mat) -> Mat

    The transpose A^T.

    Mat::zeros

    fn Mat::zeros(rows : Int, cols : Int) -> Mat

    An all-zero rows x cols matrix.
    pub(all) struct Qr {
    q : Mat
    r : Mat
    } derive(
    Debug
    )

    An economy QR factorisation, a = q * r, with q of orthonormal columns and r upper triangular.

    q has the same shape as a and r is square, which is the form the least-squares step and the UKF's square root need.

    Qr::to_repr

    Vec

    pub(all) struct Vec {
    data : FixedArray[Double]
    } derive(
    Debug
    )

    A dense vector of Double.

    The storage is a fixed array, so a vector is cheap to pass around and a set writes through to it. Every arithmetic method returns a new vector; none of them mutate the receiver.

    Vec::add

    fn Vec::add(self : Vec, other : Vec) -> Vec

    The elementwise sum. The two vectors must have the same length.

    Vec::approx

    fn Vec::approx(self : Vec, other : Vec, tolerance? : Double) -> Bool

    Whether self and other agree entry by entry within tolerance.

    Vec::at

    fn Vec::at(self : Vec, i : Int) -> Double?

    The entry at i, or None when i is outside the vector.

    Vec::axpy

    fn Vec::axpy(self : Vec, factor : Double, other : Vec) -> Vec

    self + factor * other, the operation a matrix-vector product accumulates with.

    Vec::clone

    fn Vec::clone(self : Vec) -> Vec

    An independent copy.

    Vec::dot

    fn Vec::dot(self : Vec, other : Vec) -> Double

    The inner product. The two vectors must have the same length.

    Vec::filled

    fn Vec::filled(len : Int, value : Double) -> Vec

    A vector of len copies of value.

    Vec::from_fixed

    fn Vec::from_fixed(data : FixedArray[Double]) -> Vec

    A vector that takes over data without copying it.

    Vec::get

    fn Vec::get(self : Vec, i : Int) -> Double

    The entry at i. An index outside the vector aborts: it is a programming error, not input data.

    Vec::hadamard

    fn Vec::hadamard(self : Vec, other : Vec) -> Vec

    The elementwise product. The two vectors must have the same length.

    Vec::is_empty

    fn Vec::is_empty(self : Vec) -> Bool

    Whether the vector has no entries.

    Vec::is_finite

    fn Vec::is_finite(self : Vec) -> Bool

    Whether every entry is finite.

    Vec::len

    fn Vec::len(self : Vec) -> Int

    The number of entries.

    Vec::linspace

    fn Vec::linspace(start : Double, stop : Double, len : Int) -> Vec

    A vector of len samples evenly spaced from start to stop inclusive. A single sample is start.

    Vec::max_abs

    fn Vec::max_abs(self : Vec) -> Double

    The largest absolute entry, or zero for an empty vector.

    Vec::negate

    fn Vec::negate(self : Vec) -> Vec

    Every entry negated.

    Vec::norm

    fn Vec::norm(self : Vec) -> Double

    The Euclidean length.

    Vec::norm_squared

    fn Vec::norm_squared(self : Vec) -> Double

    The sum of the squared entries.

    Vec::normalized

    fn Vec::normalized(self : Vec) -> Vec

    The unit vector in the same direction; a zero vector is returned as it is.

    Vec::of

    fn Vec::of(values : ArrayView[Double]) -> Vec

    A vector holding values.

    Vec::scale

    fn Vec::scale(self : Vec, factor : Double) -> Vec

    Every entry multiplied by factor.

    Vec::set

    fn Vec::set(self : Vec, i : Int, value : Double) -> Unit

    Overwrite the entry at i.

    Vec::sub

    fn Vec::sub(self : Vec, other : Vec) -> Vec

    The elementwise difference. The two vectors must have the same length.

    Vec::sum

    fn Vec::sum(self : Vec) -> Double

    The sum of the entries.

    Vec::to_array

    fn Vec::to_array(self : Vec) -> Array[Double]

    The entries copied into a growable array.

    Vec::to_repr

    Vec::to_string

    fn Vec::to_string(self : Vec) -> String

    The entries in [ a, b, c ] form, for output and test expectations.

    Vec::zeros

    fn Vec::zeros(len : Int) -> Vec

    A vector of len zeros.

    cholesky

    fn cholesky(a : Mat) -> Mat raise Refused

    The lower Cholesky factor of a symmetric positive-definite matrix a, so that a = l * l^T.

    The factor is what the Kalman gain is solved with: a Cholesky solve costs half an LU solve and never needs pivoting for a covariance.

    cholesky_solve

    fn cholesky_solve(l : Mat, b : Mat) -> Mat raise Refused

    Solve a * x = b given the lower Cholesky factor l of a. b has one column per right-hand side.

    det

    fn det(a : Mat) -> Double raise Refused

    The determinant of a square matrix.

    eigh

    fn eigh(a : Mat, sweeps? : Int) -> Eigh raise Refused

    The symmetric eigendecomposition of a by cyclic Jacobi rotations.

    The rotations are stable for the covariance-shaped matrices this library hands it, and they need no shift strategy. Only the symmetric part of a is used, so a small skew from rounding does not matter. Raises Refused::Dimension when a is not square and Refused::Exceeded when the sweep limit is reached.

    expm

    fn expm(a : Mat, terms? : Int) -> Mat raise Refused

    The matrix exponential of a square matrix, by scaling and squaring followed by a truncated Taylor series.

    This is what turns a continuous state matrix into a discrete one; the scaling keeps the series inside the range where twenty terms reach machine precision.

    inv

    fn inv(a : Mat) -> Mat raise Refused

    The inverse of a square matrix.
    fn lu(a : Mat) -> Lu raise Refused

    Factorise a, a square matrix, into perm * a = lower * upper.

    Raises Refused::Singular at the first column whose pivot is zero; Refused::Dimension when a is not square.

    norm

    fn norm(a : Mat) -> Double

    The Frobenius norm of a matrix.
    fn qr(a : Mat) -> Qr raise Refused

    Factorise a as q * r with Householder reflections.

    Raises Refused::Dimension when a has fewer rows than columns: an economy factorisation cannot represent that shape.

    solve

    fn solve(a : Mat, b : Mat) -> Mat raise Refused

    Solve a * x = b for a square a.

    solve_vec

    fn solve_vec(a : Mat, b : Vec) -> Vec raise Refused

    Solve a * x = b for a square a and a single right-hand side.