nalgebra icon indicating copy to clipboard operation
nalgebra copied to clipboard

Method `rank` exists, but its trait bounds were not satisfied

Open mmagician opened this issue 3 years ago • 4 comments

I'm trying to compute a rank of a square 256x256 matrix. It works for smaller sizes (up to 127), but for anything bigger I get:

the method `rank` exists for struct `Matrix<f32, nalgebra::Const<256_usize>, nalgebra::Const<256_usize>, ArrayStorage<f32, 256_usize, 256_usize>>`, but its trait bounds were not satisfied
the following trait bounds were not satisfied:
`nalgebra::Const<256_usize>: DimMin<nalgebra::Const<256_usize>>`
`nalgebra::Const<256_usize>: ToTypenum`rustc[E0599](https://doc.rust-lang.org/error-index.html#E0599)
dimension.rs(212, 1): doesn't satisfy `_: DimMin<nalgebra::Const<256_usize>>`
dimension.rs(212, 1): doesn't satisfy `nalgebra::Const<256_usize>: ToTypenum`

It sounds like a pretty basic operation to do, and the matrices aren't THAT big. Is there an easy solution to this? Many thanks!

mmagician avatar May 08 '22 14:05 mmagician

Can you use dynamically sized matrices for this? 256x256 is rather large for a value type.

Ralith avatar May 10 '22 03:05 Ralith

I'll try

mmagician avatar May 10 '22 06:05 mmagician

In embedded (no_std), a dynamically sized matrix isn't really an option, but there are still plenty of matrix operations that would be reasonable to perform on 128, 256, 512, 1024, etc. This rank invocation issue isn't really about rank, but rather the impl's of Const<T>.

Is there a limiting factor preventing add those to the library? I don't know the story behind Const only being implemented up to 127, i.e. why not at least stop on a power of 2. https://github.com/dimforge/nalgebra/pull/820 seems to imply that the Const generics improvement stopped at 127 because no one asked for more. I would be happy to have more on the power of two.

Here is a link to the macro impl for ToTypenum through 127: https://github.com/dimforge/nalgebra/blob/dev/src/base/dimension.rs#L309

trueb2 avatar May 25 '22 21:05 trueb2

@Ralith Thanks, that indeed works with dynamically sized matrices. It's a shame that static allocation only works for such small matrices though.

mmagician avatar Jun 28 '22 13:06 mmagician