handled clippy

This commit is contained in:
Jon Janzen
2021-03-31 15:52:21 -06:00
parent 9c20d13833
commit 704503a9a1

View File

@@ -11,7 +11,7 @@ pub struct Matrix<const H: usize, const W: usize> {
}
impl<const H: usize, const W: usize> Matrix<H, W> {
pub fn new() -> Matrix<H, W> {
pub fn default() -> Self {
Matrix {
matrix: [[0f32; W]; H],
}
@@ -19,12 +19,14 @@ impl<const H: usize, const W: usize> Matrix<H, W> {
pub fn from_array(matrix: [[f32; W]; H]) -> Matrix<H, W> {
Matrix {
matrix: matrix,
matrix,
}
}
pub fn identity() -> Matrix<H, W> {
let mut m = Matrix::new();
// I can't figure out how to assign a 2d array to matrix inside the generic
// so I instead create the new and then assign 1.0 to the necessary values
let mut m = Self::default();
for i in 0..m.matrix.len() {
m.matrix[i][i] = 1.0;
}
@@ -69,7 +71,7 @@ impl<const H: usize, const W: usize> PartialEq for Matrix<H, W> {
}
}
}
return true;
true
}
}
@@ -95,9 +97,9 @@ impl<const H: usize, const W: usize> std::ops::Mul<Matrix<H, W>> for Matrix<H, W
fn mul(self, _rhs: Matrix<H, W>) -> Matrix<H, W> {
let mut result = [[0f32; W]; H];
for row in 0..H {
for col in 0..W {
result[row][col] = self.calc_val_for_mul(row, &_rhs, col);
for (row, val) in result.iter_mut().enumerate().take(H) {
for (col, v) in val.iter_mut().enumerate().take(W) {
*v = self.calc_val_for_mul(row, &_rhs, col);
}
}
Matrix::from_array(result)