Skip to main content

Crate use_linear

Crate use_linear 

Source
Expand description

§use-linear

Small linear-system helpers for RustUse.
Solver-style helpers that build on use-matrix and use-vector instead of redefining primitives.

Rust 1.95.0+ Edition 2024 Linear basics License MIT or Apache-2.0

§Install

[dependencies]
use-linear = "0.0.5"
use-matrix = "0.0.5"
use-vector = "0.0.5"

§Foundation

use-linear provides a deliberately small linear-algebra surface focused on algorithms that compose the primitive crates. The current slice includes solve_2x2 plus LinearError for explicit handling of singular or non-finite systems. Matrix primitives live in use-matrix, and vector primitives live in use-vector.

Algorithm layer
solve_2x2 solves small systems without redefining the underlying matrix or vector types.
Explicit errors
LinearError keeps singular and non-finite solve failures visible at the call site.
Focused composition
Pair use-linear with use-matrix and use-vector when the primitive ownership boundaries matter.
Helper groupPrimary itemsBest fit
Solves and error handlingsolve_2x2, LinearErrorSmall systems where singular behavior should stay explicit
Neighbor primitivesuse-matrix, use-vectorCall sites that want focused matrix and vector ownership boundaries

§When to use directly

Choose use-linear directly when solve-oriented helpers are the only linear surface you need and you want primitive ownership to stay in neighboring crates.

ScenarioUse use-linear directly?Why
You need explicit handling of singular 2×2 solvesYesThe API keeps solve failures visible through LinearError
You want matrix and vector types to stay in focused cratesYesuse-linear composes use-matrix and use-vector instead of redefining them
You also need geometry, calculus, or other math domainsUsually nouse-math can compose the concrete surfaces behind features

§Scope

  • use-matrix owns matrix primitives and direct matrix operations.
  • use-vector owns vector primitives and vector operations.
  • use-linear owns higher-level linear algorithms over those primitives.
  • The crate intentionally does not define its own matrix/vector types, geometry transforms, or decomposition frameworks.

§Examples

§Solving a 2x2 system

use use_linear::solve_2x2;
use use_matrix::Matrix2;
use use_vector::Vector2;

let matrix = Matrix2::new(2.0, 1.0, 5.0, 3.0);
let rhs = Vector2::new(1.0, 2.0);

assert_eq!(solve_2x2(matrix, rhs)?, Vector2::new(1.0, -1.0));

§Handling singular systems

use use_linear::{LinearError, solve_2x2};
use use_matrix::Matrix2;
use use_vector::Vector2;

let matrix = Matrix2::new(1.0, 2.0, 2.0, 4.0);
let rhs = Vector2::new(1.0, 2.0);

assert_eq!(
    solve_2x2(matrix, rhs),
    Err(LinearError::SingularMatrix { determinant: 0.0 })
);

§Status

use-linear is a concrete pre-1.0 crate in the RustUse math workspace. The API remains intentionally small while use-matrix and use-vector own the primitive surface and adjacent crates continue to grow around them. Linear-algebra utilities for RustUse.

Modules§

prelude
Common ergonomic imports for use-linear.

Enums§

LinearError
Errors returned by linear helpers when a system cannot be solved.

Functions§

solve_2x2
Solves matrix * x = rhs for x.