1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*!
# Matrix-rs: A generic matrix library in Rust
Matrix-rs is a simple matrix library designed to be easy to use.
# Disclaimer
This crate should not be considered mature enough for *professional use*, check alternatives like [cgmath](https://github.com/brendanzab/cgmath) or [nalgebra](https://github.com/sebcrozet/nalgebra) if you are in that case.
If you are still interested, feel free to continue!
# Usage
Link it in your project's `Cargo.toml` file:
```text
# Example Cargo.toml
[dependencies]
simple-matrix = "0.1"
```
Then, you can use it in your project:
## Rust 2015
```
// 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();
```
## Rust 2018
```
// No need to specify an extern crate
// You can use it directly
use simple_matrix::Matrix;
let mat: Matrix<i32> = Matrix::new();
```
# Example: Basic matrix usage
```
// 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);
}
```
# Example: Dot product
```
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;
```
# Features
- *Features are extensions of the library left to opt-in by the user.*
- *They can increase compilation time and library size.*
To include a feature, add it to your `Cargo.toml` file:
```text
# 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:
## impl_from
Implements the *From* Trait for basic numeric types.
```
let m1: Matrix<i8> = Matrix::new(3, 5);
let m2: Matrix<i64> = m1.into();
```
*/
pub use crate*;