Skip to main content

Crate use_linear

Crate use_linear 

Source
Expand description

§use-linear

Small 2D vector and 2×2 matrix helpers for `RustUse`.
Explicit dot products, matrix products, and small linear-system solves without a larger linear-algebra framework.

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

§Install

[dependencies]
use-linear = "0.0.1"

§Foundation

use-linear provides a deliberately small numeric linear-algebra surface for 2D vectors and 2×2 matrices. The first slice includes a Vector2 type, a Matrix2 type, dot products, matrix-vector and matrix-matrix products, and explicit solving of small linear systems through LinearError. The crate stays close to ordinary f64 math instead of introducing a large generic tensor framework.

Vector primitives
Vector2 covers basic 2D numeric vectors with arithmetic, dot products, and norms.
Matrix primitives
Matrix2 covers determinants, trace, transpose, matrix products, and matrix-vector products.
Small system solves
solve_2x2 and Matrix2::solve keep singular handling explicit with LinearError.
Helper groupPrimary itemsBest fit
Vector operationsVector2, dotSmall numeric code that needs explicit 2D linear operations
Matrix operationsMatrix2Call sites that need compact 2×2 products, determinants, and trace values
Solves and error handlingsolve_2x2, LinearErrorSmall systems where singular behavior should stay explicit

§When to use directly

Choose use-linear directly when vector and matrix utilities are the only surface you need and you want to keep that concern narrower than the umbrella facade.

ScenarioUse use-linear directly?Why
You need 2D numeric vectors and 2×2 matricesYesThe current surface already covers the common small linear-algebra cases directly
You need explicit handling of singular 2×2 solvesYesThe API keeps failure visible through LinearError
You also need geometry, calculus, or other math domainsUsually nouse-math can compose the concrete surfaces behind features

§Scope

  • The current surface is intentionally small and concrete.
  • Helpers stay focused on f64-based 2D vectors and 2×2 matrices instead of a broader generic tensor framework.
  • Geometry-specific spatial types and broader algebraic traits belong in adjacent focused crates.

§Examples

§Vector and matrix products

use use_linear::{Matrix2, Vector2, dot};

let vector = Vector2::new(3.0, 4.0);
let other = Vector2::new(-2.0, 1.0);
let matrix = Matrix2::new(2.0, 1.0, 5.0, 3.0);

assert!((dot(vector, other) + 2.0).abs() < 1.0e-12);
assert!((vector.magnitude() - 5.0).abs() < 1.0e-12);
assert_eq!(matrix.mul_vector(Vector2::new(1.0, -1.0)), Vector2::new(1.0, 2.0));
assert_eq!(matrix * Matrix2::identity(), matrix);

§Solving a 2×2 system

use use_linear::{Matrix2, Vector2, solve_2x2};

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));

§Status

use-linear is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while adjacent geometry and algebra crates continue to grow around it. Linear-algebra utilities for RustUse.

Modules§

prelude
Common ergonomic imports for use-linear.

Structs§

Matrix2
A 2×2 matrix stored in row-major order.
Vector2
A 2D column vector.

Enums§

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

Functions§

dot
Returns the dot product of two vectors.
solve_2x2
Solves matrix * x = rhs for x.