Minimizing trait bound complexity when working with dimensional generics
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
I've ended up with a ridiculously gnarly function signature due to a ton of trait bounds being required to support some simple operations I want to make on generic-dimension static matrices. Specifically, I want to remove rows and columns while being able to add and reallocate (snippet below). Surely there's an easier way to do this that I've completely missed? Any help would be hugely appreciated!
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2718224f6cb54b60c95e378be8a0d2cd
```
use nalgebra::{
allocator::{Allocator, Reallocator},
ArrayStorage, Const, DefaultAllocator, DimDiff, DimSub, Matrix, SMatrix, SVector, Storage,
ToTypenum, U1,
};
#[inline(always)]
#[allow(clippy::too_many_arguments)]
fn qp_reduce(
Q: &SMatrix,
c: &SVector,
A: &SMatrix,
b: &SVector,
xk: &SVector,
limit_index_set: &SVector,
ls_weights: &SVector,
violating_index: usize,
delta_x: &mut SVector,
scale: &mut f64,
) where
Const: ToTypenum,
Const: ToTypenum,
as ToTypenum>::Typenum: DimSub>,
Const: DimSub,
Const: DimSub,
DefaultAllocator: Reallocator, Const, Const, DimDiff, U1>>,
ArrayStorage: Storage, Const>,
DefaultAllocator: Allocator as DimSub>>::Output, Const>,
DefaultAllocator:
Reallocator, Const, as DimSub>>::Output, Const>,
ArrayStorage: Storage, Const>,
DefaultAllocator: Allocator<
f64,
as DimSub>>::Output,
as DimSub>>::Output,
>,
DefaultAllocator: Reallocator<
f64,
as DimSub>>::Output,
Const,
as DimSub>>::Output,
as DimSub>>::Output,
>,
DefaultAllocator: Allocator as DimSub>>::Output>,
DefaultAllocator:
Reallocator, Const<1>, as DimSub>>::Output, Const<1>>,
Matrix, Const<1>, ArrayStorage>:
std::ops::Add, Const<1>, ArrayStorage>>,
ArrayStorage: Storage>,
DefaultAllocator: Allocator as DimSub>>::Output>,
DefaultAllocator:
Reallocator, Const<1>, as DimSub>>::Output, Const<1>>,
ArrayStorage: Storage>,
{
let xk_delta_x = *xk + *delta_x;
let A_reduced = A.remove_column(violating_index);
let Q_reduced = Q.remove_row(violating_index).remove_column(violating_index);
let c_reduced = c.remove_row(violating_index);
let xk_reduced = xk.remove_row(violating_index);
let limit_set_reduced = limit_index_set.remove_row(violating_index);
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.