use crate::ode_state::ode_state_trait::{OdeState, StateIndex};
use linalg_traits::Matrix;
#[cfg(feature = "nalgebra")]
use nalgebra::SMatrix;
#[macro_export]
macro_rules! impl_ode_state_for_smatrix {
($($type:ident),*) => {
$(
impl<const R: usize, const C: usize> OdeState for $type<f64, R, C> {
fn add(&self, other: &Self) -> Self {
<Self as Matrix<f64>>::add(self, other)
}
fn add_assign(&mut self, other: &Self) {
<Self as Matrix<f64>>::add_assign(self, other);
}
fn sub(&self, other: &Self) -> Self {
<Self as Matrix<f64>>::sub(self, other)
}
fn sub_assign(&mut self, other: &Self) {
<Self as Matrix<f64>>::sub_assign(self, other);
}
fn mul(&self, scalar: f64) -> Self {
<Self as Matrix<f64>>::mul(self, scalar)
}
fn mul_assign(&mut self, scalar: f64) {
<Self as Matrix<f64>>::mul_assign(self, scalar);
}
fn get_state_variable(&self, index: StateIndex) -> f64 {
match index {
StateIndex::Scalar() => panic!("Cannot index a matrix ODE state with a StateIndex::Scalar."),
StateIndex::Vector(i) => self[i], StateIndex::Matrix(i, j) => self[(i, j)]
}
}
}
)*
};
}
#[cfg(feature = "nalgebra")]
impl_ode_state_for_smatrix!(SMatrix);