### 2 unstable releases

0.2.0 | May 28, 2023 |
---|---|

0.1.0 | May 25, 2023 |

#**551** in Algorithms

**MIT**license

24KB

474 lines

# Matx

A lightweight, rusty matrix library that allows for simple (as in, easy to put into place) matrix handling and operations.

Operations are not done in place, so most functions, especially mathematical operations, are pure functions that consume their arguments and output a new matrix.

- GitHub: https://github.com/Jerem-dY/Matx
- Crate.io: https://crates.io/crates/matx
- Doc: https://docs.rs/matx/0.1.0/matx/

## TODO

- Matrix initialization (
*filled*,*random*,*custom*) - Basic operations

with`Mat`

and`Mat`

with`Mat``Scalar` - Better error handling (

for operations that may fail because of uncompatible sizes?)`Results` - Matrix rotations
- Macros for simpler initialization
- Better recursive matrices (operations, display, etc.)
- Computations on GPU?

## Notes on usage

Do not hesitate to go see

for more examples.`tests .rs`

### Creating matrices

Declaring a matrix is rather straightforward: you only need to specify the **type of elements**, the number of **rows** and the number of **columns**.

`let` `mut` a `=` `Matrix``::``<``f64``>``::`new`(``2``,` `3``)``;`

By default, using

will initialize the matrix with zeros (it is thus only available with T: `Matrix ::`new

`(`

`)`

`num``::`Num

, so a number). If needed, you can specify the whole content of the matrix using `Matrix``::`from`<``Vec``<``Vec``<`T`>``>``>``(``)`

, so with a vector of vectors (with each representing a row).`//` 1 2 3
`//` 4 5 6
`let` a `=` `Matrix``::``<``f64``>``::`from`(``vec!``[`
`vec!``[``1.``0``f64``,` `2.``0``f64``,` `3.``0``f64``]``,`
`vec!``[``4.``0``f64``,` `5.``0``f64``,` `6.``0``f64``]`
`]``)``;`

### Operators

**Multiplication** and **addition** are implemented *between matrices*, and *between a matrix and an object of type T* (the type of the elements) if T is a number.

Matrix-matrix operations may require compatibility between the two (sizewise) ; operations on matrices, like the dot product, return a

since the size checks mostly happen at runtime for now.`Result``<``>`

As such, inline arithmetics is discouraged:

should rather be computed step by step as good pratice, or else all 'em unwraps will make things unreadable.`a + b * (d - e)`

No operation is done in-place: they all generate a new matrix. You'll need to explicitly

a matrix if it should be used in several operations.`.``clone``(``)`

Current implemented operations are as follows:

and`Mat``*`Mat`Mat``*`scal

and`Mat``/`Mat`Mat``/`scal

and`Mat``+`Mat`Mat``+`scal

and`Mat``-`Mat`Mat``-`scal

Summing up a matrix's content is also available for all types that implement

and can be summed through an iterator: `T +T`

`.``sum``(``)`

### Mapping

You can apply a closure on each matrix elements using the

method`.``map``(``)`

#### Dependencies

~1.4–2.2MB

~49K SLoC