Struct russell_lab::Matrix [−][src]
pub struct Matrix { /* fields omitted */ }
Implementations
Holds matrix components
Note
Data is stored in col-major format
Example of col-major data:
_ _
| 0 3 |
A = | 1 4 | ⇒ a = [0, 1, 2, 3, 4, 5]
|_ 2 5 _|(m x n)
a[i+j*m] = A[i][j]
Creates new (nrow x ncol) Matrix filled with zeros
use russell_lab::*;
let a = Matrix::new(3, 3);
let correct = "┌ ┐\n\
│ 0 0 0 │\n\
│ 0 0 0 │\n\
│ 0 0 0 │\n\
└ ┘";
assert_eq!(format!("{}", a), correct);
Creates new matrix from given data
Examples
use russell_lab::*;
let a = Matrix::from(&[
&[1.0, 2.0, 3.0],
&[4.0, 5.0, 6.0],
&[7.0, 8.0, 9.0],
]);
let correct = "┌ ┐\n\
│ 1 2 3 │\n\
│ 4 5 6 │\n\
│ 7 8 9 │\n\
└ ┘";
assert_eq!(format!("{}", a), correct);
Panics
This function panics if there are rows with different number of columns
Returns the number of rows
Examples
use russell_lab::*;
let a = Matrix::new(4, 3);
assert_eq!(a.nrow(), 4);
Returns the number of columns
Examples
use russell_lab::*;
let a = Matrix::new(4, 3);
assert_eq!(a.ncol(), 3);
Returns the dimensions (nrow, ncol) of this matrix
Examples
use russell_lab::*;
let a = Matrix::new(4, 3);
assert_eq!(a.dims(), (4, 3));