Re: [eigen] Sparse Vector |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: [eigen] Sparse Vector
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Sun, 17 Mar 2013 14:11:40 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type:content-transfer-encoding; bh=YmYJmje53hgxYcC5Ne+VY3mBmyWCgNQDGmXOtbgPGIk=; b=T496w4zwSaznopPuDH8ZJsbkZ5kVhErqMJDouTW8u4xXISHZao2pKWXSG18Xm06ali tq5oOU745XphFgHOTPdnLu3wMIHipipvvffqwD0LyAvF0LLKaq8qxEMHezk2Shk5cq0s vYtidiAaDP3XfbhaUOq40aYM3auAa7hxB6E8TPY65aUgb69KMFAIG/CGmdjYO5xO+q73 WbqGBSC9v1v0Wmg9T2cOOLEkBJeZ7wsshgIWw0MUNgtqKeL0uLzb5XSKyqQJMtFAuB01 rX94NAcJTUwAlZl4Tt61dLIfCdFASUtRzYw/EfQEWGil5oqhobLS10jvO5coo5lrb63m SpmQ==
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/
>
>
>
>
>