I meant to give a shot at issue 731 on github to get my hands into nalgebra. I thought it could be completed with the computation of a permutation matrix that solves a vector. I have encountered the need before in an algorithm that prescribed to reorder a basis according to the images of a certain vector. Nothing complicated, it works well for a fixed dimension, but making it generic seems troublesome.
I merely reproduced the computation suggested in issue #731, that is Vector to Iterator to Vec to Iterator, and then meant to turn it back to a Vector.
fn argsort<N: Scalar, D: Dim, S: Storage<N, D>>(v: &Vector<N, D, S>) > Vector<N, D, S>
where
N: Ord,
{
let v_as_vec = Vec::from_iter(v.iter().enumerate());
v_as_vec.sort_by_key((_, &val) val);
let argsort = v_as_vec.into_iter().map((pos, _) pos);
Vector::from_iterator(argsort)
}
That’s how it happened:
error[E0034]: multiple applicable items in scope
> src/main.rs:30:13

30  Vector::from_iterator(argsort)
 ^^^^^^^^^^^^^ multiple `from_iterator` found

= note: candidate #1 is defined in an impl for the type `nalgebra::Matrix<N, R, C, <nalgebra::DefaultAllocator as nalgebra::allocator::Allocator<N, R, C>>::Buffer>`
= note: candidate #2 is defined in an impl for the type `nalgebra::Matrix<N, R, nalgebra::Dynamic, <nalgebra::DefaultAllocator as nalgebra::allocator::Allocator<N, R, nalgebra::Dynamic>>::Buffer>`
= note: candidate #3 is defined in an impl for the type `nalgebra::Matrix<N, nalgebra::Dynamic, C, <nalgebra::DefaultAllocator as nalgebra::allocator::Allocator<N, nalgebra::Dynamic, C>>::Buffer>`
= note: candidate #4 is defined in an impl for the type `nalgebra::Matrix<N, nalgebra::Dynamic, nalgebra::Dynamic, <nalgebra::DefaultAllocator as nalgebra::allocator::Allocator<N, nalgebra::Dynamic, nalgebra::Dynamic>>::Buffer>`
I sort of tracked this to from_iterator_generic
that is defined as Self::from_data(DefaultAllocator::allocate_from_iterator(nrows, ncols, iter))
.
Is there anything to do from there? I feel like the documentation didn’t prepare me for this kind of error there. (of course the argsort could just return a mere Vec, trying to figure things out there).