|
@@ -1,7 +1,7 @@
|
|
|
use std::ops::{Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
|
use std::ptr::swap;
|
|
|
|
|
|
-use crate::{Float, Numeric, Primitive};
|
|
|
+use crate::{Float, Matrix, Numeric, Primitive};
|
|
|
#[cfg(feature = "angular")]
|
|
|
use crate::Angular;
|
|
|
|
|
@@ -12,6 +12,16 @@ pub struct GenericMatrix<T: Numeric, const ROWS: usize, const COLUMNS: usize> {
|
|
|
pub data: [[T; COLUMNS]; ROWS],
|
|
|
}
|
|
|
|
|
|
+impl<T: Numeric, const ROWS: usize, const COLUMNS: usize> Matrix<T, ROWS, COLUMNS> for GenericMatrix<T, ROWS, COLUMNS> {
|
|
|
+ fn get(&self, row: usize, col: usize) -> T {
|
|
|
+ self.data[row][col]
|
|
|
+ }
|
|
|
+
|
|
|
+ fn set(&mut self, row: usize, col: usize, value: T) {
|
|
|
+ self.data[row][col] = value;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// Special kind of `GenericMatrix` where both dimensions are equal.
|
|
|
pub type SquareMatrix<T, const DIMENSION: usize> = GenericMatrix<T, DIMENSION, DIMENSION>;
|
|
|
|
|
@@ -503,7 +513,7 @@ impl<T: Numeric + Float + Primitive> SquareMatrix<T, 4> {
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
- use crate::{ColumnVector, Complex, cplx, Float, GenericMatrix, Numeric, RowVector, SquareMatrix};
|
|
|
+ use crate::{ColumnVector, Complex, cplx, Float, GenericMatrix, Matrix, Numeric, RowVector, SquareMatrix};
|
|
|
|
|
|
fn matrices_are_equal<T: Numeric + Float + PartialOrd, const ROWS: usize, const COLUMNS: usize>(
|
|
|
a: &GenericMatrix<T, ROWS, COLUMNS>,
|
|
@@ -637,4 +647,18 @@ mod tests {
|
|
|
assert!(matrices_are_equal(&inverted, &expected, tolerance));
|
|
|
assert!(matrices_are_equal(&(inverted * mat), &SquareMatrix::identity(), tolerance));
|
|
|
}
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ #[should_panic = "index out of bounds"]
|
|
|
+ fn out_of_range_get() {
|
|
|
+ let mat = SquareMatrix::from([[1]]);
|
|
|
+ mat.get(1, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ #[should_panic = "index out of bounds"]
|
|
|
+ fn out_of_range_set() {
|
|
|
+ let mut mat = SquareMatrix::from([[1]]);
|
|
|
+ mat.set(1, 1, 2);
|
|
|
+ }
|
|
|
}
|