Struct fast_neural_network::matrix::Matrix
source · pub struct Matrix { /* private fields */ }
Expand description
A matrix implementation that supports basic matrix operations.
Implementations§
source§impl Matrix
impl Matrix
sourcepub fn from_vec(vec: Vec<f64>, rows: usize, cols: usize) -> Self
pub fn from_vec(vec: Vec<f64>, rows: usize, cols: usize) -> Self
Creates a new matrix with the given dimensions and fills it with the given value.
Example
use fast_neural_network::matrix::*;
let matrix = Matrix::from_vec(
vec![0.03, 0.62, 0.85, 0.60, 0.62, 0.64],
3,
2,);
assert_eq!(matrix.get(0, 1), 0.62);
assert_eq!(matrix.rows(), 3);
assert_eq!(matrix.cols(), 2);
sourcepub fn from_json(json: &str) -> Self
pub fn from_json(json: &str) -> Self
Creates a new matrix from the given JSON string.
Example
use fast_neural_network::matrix::*;
let matrix = Matrix::from_json(
r#"{
"data": [
0.03,
0.62,
0.85,
0.60,
0.62,
0.64
],
"rows": 3,
"cols": 2
}"#);
assert_eq!(matrix.get(0, 1), 0.62);
sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
transforms the matrix into a JSON string.
Example
use fast_neural_network::matrix::*;
let matrix = Matrix::from_vec(
vec![0.03, 0.62, 0.85, 0.60, 0.62, 0.64],
3,
2,);
assert_eq!(matrix.to_json(), r#"{"data":[0.03,0.62,0.85,0.6,0.62,0.64],"rows":3,"cols":2}"#);
sourcepub fn save(&self, path: &str)
pub fn save(&self, path: &str)
Saves the matrix to the given path.
Example
use fast_neural_network::matrix::*;
let matrix = Matrix::from_vec(
vec![0.03, 0.62, 0.85, 0.60, 0.62, 0.64],
3,
2,);
matrix.save("matrix.json");
sourcepub fn set(&mut self, row: usize, col: usize, value: f64)
pub fn set(&mut self, row: usize, col: usize, value: f64)
Sets the value at the given row and column.
sourcepub fn dot_vec(&self, other: &Vec<f64>) -> Vec<f64>
pub fn dot_vec(&self, other: &Vec<f64>) -> Vec<f64>
Multiplies the matrix with the given vector.
sourcepub fn scalar_mul(&self, scalar: f64) -> Matrix
pub fn scalar_mul(&self, scalar: f64) -> Matrix
Multiplies the matrix with the given vector.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Matrix
impl<'de> Deserialize<'de> for Matrix
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl RefUnwindSafe for Matrix
impl Send for Matrix
impl Sync for Matrix
impl Unpin for Matrix
impl UnwindSafe for Matrix
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more