In the code here: Rust Playground
I am unable to do LU decomposition on an SxS square matrix. Adding constraints like the compiler error suggests eventually gets down to needing a restraint of a private struct.
Hi!
The simplest solution is to look at the same trait bounds needed by .lu()
methods and add them. You are missing S: DimMin<S>
and DefaultAllocator: Allocator<(usize, usize), DimMinimum<S, S>>
:
use nalgebra::{DefaultAllocator, allocator::Allocator, VectorN, DimName, ComplexField, MatrixN};
use nalgebra::dimension::{DimMinimum, DimMin};
pub fn test<N, S, F, G>(initial: &[N], mut f: F, mut jac: G)
where
N: ComplexField,
S: DimName + DimMin<S>,
F: FnMut(&[N]) -> VectorN<N, S>,
G: FnMut(&[N]) -> MatrixN<N, S>,
DefaultAllocator: Allocator<N, S> + Allocator<N, S, S> + Allocator<(usize, usize), DimMinimum<S, S>>,
{
let guess = VectorN::<N, S>::from_column_slice(initial);
let mut f_val = -f(initial);
let jac_val = jac(initial);
let lu = jac_val.lu();
}