wrote first bit of matrix
This commit is contained in:
@@ -1,7 +1,45 @@
|
|||||||
|
use std::ops::Index;
|
||||||
|
|
||||||
|
pub struct Matrix {
|
||||||
|
matrix: Vec<Vec<f32>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Matrix {
|
||||||
|
pub fn new(matrix: Vec<Vec<f32>>) -> Matrix {
|
||||||
|
Matrix {
|
||||||
|
matrix: matrix,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Index<usize> for Matrix {
|
||||||
|
type Output = Vec<f32>;
|
||||||
|
fn index(&self, index: usize) -> &Self::Output {
|
||||||
|
&self.matrix[index]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
assert_eq!(2 + 2, 4);
|
let m = vec![
|
||||||
|
vec![1.0, 2.0, 3.0, 4.0],
|
||||||
|
vec![5.5, 6.5, 7.5, 8.5],
|
||||||
|
vec![9.0, 10.0, 11.0, 12.0],
|
||||||
|
vec![13.5, 14.5, 15.5, 16.5],
|
||||||
|
];
|
||||||
|
|
||||||
|
let matrix = Matrix::new(m);
|
||||||
|
assert_eq!(1.0, matrix[0][0]);
|
||||||
|
assert_eq!(4.0, matrix[0][3]);
|
||||||
|
assert_eq!(5.5, matrix[1][0]);
|
||||||
|
assert_eq!(7.5, matrix[1][2]);
|
||||||
|
assert_eq!(11.0, matrix[2][2]);
|
||||||
|
assert_eq!(13.5, matrix[3][0]);
|
||||||
|
assert_eq!(15.5, matrix[3][2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user