6 releases (breaking)

0.5.1 Jul 1, 2022
0.5.0 Jun 30, 2022
0.4.0 Jun 29, 2022
0.3.0 Jun 28, 2022
0.1.0 Jun 27, 2022

#872 in Math

Unlicense

35KB
641 lines

qmat

Version Docs codecov Build Status open issues License Code Size

qmat is a simple library for 2-dimensional matrices.

Usage

New matrix

There are three main ways to create a new matrix.

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<i32, 2, 3, 6> = Matrix::new([0, 1, 2, 3, 4, 5]).unwrap();

// Or,
let mat = Matrix::<_, 2, 3, 6>::new([0, 1, 2, 3, 4, 5]).unwrap();
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]);
use qmat::prelude::*;
let mat = matrix!([[0, 1, 2], [3, 4, 5]]);

Matrices can also be created using Matrix::empty and Matrix::diag.

Retrieving a value

Using a [usize; 2]

use qmat::prelude::*;
let mat = matrix!([[0, 1, 2], [3, 4, 5]]);
println!("{}", mat[[1, 1]]); // 4

Using the position struct

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

Dependencies

~0.4–1MB
~23K SLoC