Crates.io | simple-matrix |
lib.rs | simple-matrix |
version | 0.1.2 |
source | src |
created_at | 2018-08-28 16:04:21.282657 |
updated_at | 2018-08-30 07:19:23.522806 |
description | A simple generic matrix library |
homepage | https://github.com/NicolasMemeint/simple-matrix |
repository | https://github.com/NicolasMemeint/simple-matrix |
max_upload_size | |
id | 81839 |
size | 43,159 |
This crate should not be considered mature enough for professional use, check alternatives like cgmath or nalgebra if you are in that case.
If you are still interested, feel free to continue!
Link it in your project's Cargo.toml
file:
# Example Cargo.toml
[dependencies]
simple-matrix = "0.1"
Then, you can use it in your project:
// Specify the extern crate in your lib.rs or main.rs
extern crate simple_matrix;
// You can now use it
use simple_matrix::Matrix;
let mat: Matrix<i32> = Matrix::new();
// No need to specify an extern crate
// You can use it directly
use simple_matrix::Matrix;
let mat: Matrix<i32> = Matrix::new();
// Create a matrix of default cells
let zero: Matrix<u32> = Matrix::new(3, 3);
// Create a 2x4 matrix from an iterator (fill it row by row)
let mat1: Matrix<u32> = Matrix::from_iter(2, 4, 0..);
// Clone a matrix
let mat2 = mat1.clone();
// Add by reference (do not consume them)
let mut add = &mat1 + &mat2;
// Subtract by value (consume them)
let mut sub = mat1 - mat2;
// OpAssign are also available
sub += &zero;
sub -= zero;
// Get cells
let val: &u32 = add.get(0, 3).unwrap();
// Set cells
add.set(0, 3, 0);
// Iterate through the matrix (row by row)
for val in add {
print!("{} ", val);
}
let mat: Matrix<f64> = Matrix::from_iter(2, 4, 0..);
// Construct the transposed matrix
let mat_t = mat.transpose();
// Construct the dot product
let dot = mat * mat_t;
To include a feature, add it to your Cargo.toml
file:
# Example Cargo.toml with added feature (replace values with your own)
[dependencies]
simple-matrix = { version = "0.1", features = ["impl_from"] }
Current available features are listed below with a little description:
Implements the From Trait for basic numeric types.
let m1: Matrix<i8> = Matrix::new(3, 5);
let m2: Matrix<i64> = m1.into();
cargo test
in the root of the projectcargo bench
in the root of the projectThoses benchmarks are not designed for comparison to other matrix crates, but for tracking speed-ups/regressions. Comparison benchmarks are left as an exercice to the reader.
Create a new issue or a pull request and I will check them (as soon as I can).