我正在尝试为通用方形 MatrixMN 实现 exp 函数
pub fn exp<N, R>(m: &MatrixMN<N, R, R>, k: usize) -> MatrixMN<N, R, R>
where
N: Scalar + One + Zero,
R: DimName + DimNameAdd<R>,
<R as DimName>::Value: Mul<<R as DimName>::Value>,
<<R as DimName>::Value as Mul<<R as DimName>::Value>>::Output: generic_array::ArrayLength<N>,
{
let mut i = MatrixMN::<N, R, R>::identity();
i.add(&m)
}
但我不断收到这样的错误。
error[E0599]: no method named `add` found for struct `nalgebra::base::matrix::Matrix<N, R, R, nalgebra::base::array_storage::ArrayStorage<N, R, R>>` in the current scope
--> src/state_extrapolation.rs:24:7
|
24 | i.add(&m)
| ^^^ method not found in `nalgebra::base::matrix::Matrix<N, R, R, nalgebra::base::array_storage::ArrayStorage<N, R, R>>`
|
= note: the method `add` exists but the following trait bounds were not satisfied:
`&mut nalgebra::base::matrix::Matrix<N, R, R, nalgebra::base::array_storage::ArrayStorage<N, R, R>> : nalgebra::base::dimension::DimNameAdd<_>`
`&nalgebra::base::matrix::Matrix<N, R, R, nalgebra::base::array_storage::ArrayStorage<N, R, R>> : nalgebra::base::dimension::DimNameAdd<_>`
`nalgebra::base::matrix::Matrix<N, R, R, nalgebra::base::array_storage::ArrayStorage<N, R, R>> : nalgebra::base::dimension::DimNameAdd<_>`
有没有更好的方法将泛型矩阵传递给函数?
我也试过这样的东西
pub fn exp2<M>(m: &M, k: usize) -> M
where
M: nalgebra::base::Matrix<_, _, _, _>,
{
let mut i = M::identity();
i.add(&m)
}
但无法为 M 提出好的特征。