Re: [eigen] Sparse Vector

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi Thomas,

I acknowledge that SparseVector did not received the same attention as
SparseMatrix. That's because they are very rarely needed.

1) In short, SparseVector works like a sorted std::vector, so first
call reserve with an estimate of the number of nonzeros, and then fill
it with insert. I'm not sure a setFromTriplets() method would make
much sense, but why not.

2) Thanks for the finding, we just have to add the missing member in MatrixBase.

3) Yes, just make it fully template:

template<typename MatType> void foo(const MatType& x);

and restrict yourself with methods supported by both dense and sparse world..

gael



On Fri, Mar 15, 2013 at 12:03 PM, Thomas Capricelli
<orzel@xxxxxxxxxxxxxxx> wrote:
>
> Hello,
>
> I have some questions about SparseVector. I can't say
> http://eigen.tuxfamily.org/dox-devel/classEigen_1_1SparseVector.html
> was very useful :(
>
> and
> http://eigen.tuxfamily.org/dox-devel/group__TutorialSparse.html
> barely mentions those.
>
> My first question is about construction. SparseMatrix has
> setFromTriplets(), but i can't find anything similar for vectors. The
> method with 'insert' might work as well, but then how does the reserve()
> stuff works...?
>
> Second question : i need to compute densevector.dot(sparsevector), but
> this wont compile (funny error message at the end). I've "solved' this
> by using sparsevector.dot(densevector), which works.. is that
> expected/known ?
>
> Third question: in the never-ending quest "how to write functions
> accepting different kind of eigen objects", I'd like to have a function
> accepting either a dense or sparse vector... is that feasible ? easy ?
>
> Well... that's it for my first glimpse at eigen sparse :)
>
> regards,
> Thomas
>
>
>
> error message for densevector.dot(sparsevector)
> /home/orzel/hg/eigen/Eigen/src/Core/MatrixBase.h:198:5: note:
> template<class OtherDerived> typename
> Eigen::internal::scalar_product_traits<typename
> Eigen::internal::traits<T>::Scalar, typename
> Eigen::internal::traits<OtherDerived>::Scalar>::ReturnType
> Eigen::MatrixBase::dot(const Eigen::MatrixBase<OtherDerived>&) const
> [with OtherDerived = OtherDerived; Derived = Eigen::Matrix<double, 10, 1>]
> /home/orzel/hg/eigen/Eigen/src/Core/MatrixBase.h:198:5: note: template
> argument deduction/substitution failed:
> eigentest.cpp:16:42: note: ‘Eigen::SparseVector<double>’ is not derived
> from ‘const Eigen::MatrixBase<Derived>’
>
> --
> Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>
> http://www.freehackers.org/thomas/
>
>
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/