| Crates.io | linear_algebra_42 |
| lib.rs | linear_algebra_42 |
| version | 0.1.1 |
| created_at | 2025-08-10 17:47:08.956524+00 |
| updated_at | 2025-08-26 11:53:40.742076+00 |
| description | A linear algebra library in Rust |
| homepage | https://github.com/paulodavi/42sp-linear-algebra |
| repository | https://github.com/paulodavi/42sp-linear-algebra |
| max_upload_size | |
| id | 1789150 |
| size | 199,588 |
A complete Rust library for linear algebra operations, based on the 42 School Matrix project. Now published on crates.io!
Includes vectors, matrices, complex numbers, and a comprehensive trait system with type safety and high performance.
Add to your Cargo.toml:
[dependencies]
linear_algebra_42 = "0.1.0"
Or always check the latest version at: https://crates.io/crates/linear_algebra_42
use linear_algebra_42::{Vector, Matrix, Complex, linear_combination, lerp};
// Vectors
let mut v1 = Vector::from([1, 2, 3]);
let v2 = Vector::from([4, 5, 6]);
v1.add_inline(&v2); // [5, 7, 9]
println!("Dot product: {}", v1.dot(&v2));
// Matrices
let m1 = Matrix::from([[1.0, 2.0], [3.0, 4.0]]);
let m2 = Matrix::from([[5.0, 6.0], [7.0, 8.0]]);
let result = m1.mul_mat(&m2);
println!("Determinant: {}", m1.determinant());
// Complex Numbers
let z1 = Complex::new(3.0, 4.0);
let z2 = Complex::new(1.0, -2.0);
let product = z1 * z2;
println!("Conjugate: {}", z1.conjugate());
// Advanced Operations
let vectors = [Vector::from([1.0, 0.0]), Vector::from([0.0, 1.0])];
let result = linear_combination(vectors, [2.0, 3.0])?;
let interpolated = lerp(v1, v2, 0.5)?;
Vector::from([1, 2, 3]), Vector::zeros(n)add_inline(), sub(), scl(), dot(), cross_product()norm_1(), norm(), norm_inf()add_new(), sub_new(), scl_new()Matrix::from([[1, 2], [3, 4]]), Matrix::zeros(rows, cols)add(), sub(), scl(), mul_vec(), mul_mat()transpose(), determinant(), inverse(), rank(), trace()Complex::new(real, imag), Complex::real(x), Complex::imag(x)+, -, *, /), conjugate(), magnitude()Conjugate, Magnitude, Zero, Onelinear_combination(vectors, coefficients) - Linear combinationslerp(start, end, t) - Linear interpolationangle_cos(u, v) - Cosine of angle between vectorscross_product(u, v) - 3D cross productConjugate: Complex conjugation for Complex, Vector<Complex>, Matrix<Complex>Magnitude: Unified magnitude calculation (abs() for numbers, norm() for vectors)Zero: Additive identity (zero() method)One: Multiplicative identity (one() method)Negative: Additive inverse (negative() method)Most operations require combinations of: Copy, Clone, Add, Sub, Mul, Div, Default, PartialEq, PartialOrd
cargo test # Run all tests
cargo doc --open # Generate and open documentation
cargo run --example basic # Run basic example
cargo run --example complex # Run example with complex numbers
matrix_displayThe matrix_display/ directory contains a bonus project: a CLI tool with options to generate files containing the matrix needed to use ./display. Useful for computer graphics, simulations, or image manipulation.
Run the CLI to quickly generate rotation matrices and other display-related utilities.
Implementation of the 42 School Matrix project, covering fundamental linear algebra concepts for computer graphics, machine learning, and engineering applications.
Features implemented: vector operations, matrix algebra, linear systems, complex numbers with conjugation, comprehensive trait system, and optimized algorithms.
MIT License - see LICENSE-MIT for details.