Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/breadinator/qmat
A simple library for 2-dimensional matrices.
https://github.com/breadinator/qmat
data-structures math mathematics matrix matrix-calculations matrix-library matrix-multiplication rust rustlang
Last synced: 28 days ago
JSON representation
A simple library for 2-dimensional matrices.
- Host: GitHub
- URL: https://github.com/breadinator/qmat
- Owner: Breadinator
- License: unlicense
- Created: 2022-06-27T12:15:04.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-01T06:04:15.000Z (over 2 years ago)
- Last Synced: 2025-01-22T14:47:19.986Z (29 days ago)
- Topics: data-structures, math, mathematics, matrix, matrix-calculations, matrix-library, matrix-multiplication, rust, rustlang
- Language: Rust
- Homepage:
- Size: 38.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# qmat
[](https://crates.io/crates/qmat)
[](https://docs.rs/qmat/latest)
[](https://codecov.io/gh/Breadinator/qmat)
[](https://github.com/Breadinator/qmat/actions/workflows/rust.yml)
[](https://github.com/Breadinator/qmat/issues)
[](https://github.com/Breadinator/qmat/blob/main/LICENSE)
**qmat** is a simple library for 2-dimensional matrices.
## Usage
### New matrix
There are three main ways to create a new matrix.```rust
use qmat::prelude::*;// Creates the matrix 2x3
// [0, 1, 2]
// [3, 4, 5]
// The generics are the data type, the number of rows, the
// number of cols then the lenth of the data (rows * cols)
let mat: Matrix = Matrix::new([0, 1, 2, 3, 4, 5]).unwrap();// Or,
let mat = Matrix::<_, 2, 3, 6>::new([0, 1, 2, 3, 4, 5]).unwrap();
``````rust
use qmat::prelude::*;// Creates the same matrix using the analagous macro pattern.
// Automatically unwraps the errors.
let mat = matrix!(2, 3, [0, 1, 2, 3, 4, 5]);
``````rust
use qmat::prelude::*;
let mat = matrix!([[0, 1, 2], [3, 4, 5]]);
```Matrices can also be created using [Matrix::empty](https://docs.rs/qmat/latest/qmat/mat/struct.Matrix.html#method.empty) and [Matrix::diag](https://docs.rs/qmat/latest/qmat/mat/struct.Matrix.html#method.diag).
### Retrieving a value
#### Using a [usize; 2]
```rust
use qmat::prelude::*;
let mat = matrix!([[0, 1, 2], [3, 4, 5]]);
println!("{}", mat[[1, 1]]); // 4
```#### Using the position struct
```rust
use qmat::prelude::*;
let mat = matrix!([[0, 1, 2], [3, 4, 5]]);
let pos = Position(0, 2);
println!("{}", mat[pos]); // 2
```### Matrix operations
### Iterators## Todo
* Implement mutable row and col iterators
* Implement inverting for matrices that aren't of the shape (2, 2)
* Allow indexing for anything that can be converted into [usize; 2]
* Optimise
* Add examples for matrix operations and iterators to README.md