The Matrix type overloads all basic arithmetic operations: addition, subtraction,
multiplication, division - along with the possibility of getting negative and index
in/of given matrix. Matrix also provides fancy methods for e.g. getting and setting elements.
use lars::matrix;
use lars::matrix::Matrix;
fn matrix_creation() {
let m1 = Matrix::new(3, 5, 3.0);
let elements = [1.0, 3.0, 3.0, 7.0];
let m2 = matrix::from(3, 5, &elements);
let m3 = matrix::identity(5);
let m4 = matrix::random(3, 5);
let m5 = matrix::zeros(3, 5);
let m6 = matrix::zeros_like(m1.clone());
}
use lars::matrix;
use lars::matrix::Matrix;
fn matrix_operation() {
let mut foo = matrix::new(5, 5, 2.0);
let mut bar = matrix::new(5, 5, 1.5);
let product = foo.clone() * bar.clone();
let sum = foo.clone() + bar.clone();
let delta = foo.clone() - bar.clone();
let frac = foo.clone() / bar.clone();
let doubled = foo.clone() * 2;
let offset = foo.clone() + 42;
let subbed = foo.clone() - 100;
let halfed = foo.clone() / 2;
foo.transpose();
let trans_foo = foo.transposed();
let trace_bar = bar.trace();
foo.set(2, 2, 4.2);
let element = bar.get(2, 3);
let mut foobar = matrix::new(4, 4, 0.0);
foobar.reshape(8, 2);
}
use lars::matrix;
use lars::matrix::Matrix;
use lars::vector;
use lars::vector::Vector;
fn matrix_vector_dot() {
let foo = Matrix::new(3, 5, 3.0);
let bar = Vector::new(3, 6.0);
let foobar = foo * bar;
}