Re: [eigen] Some trouble with triangularView |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Some trouble with triangularView
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Fri, 3 Sep 2010 11:23:08 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=TUmHMxGFUznB5ry85ifdZC1Jo0x7zux5jWOj5HXirSY=; b=gx2swwrhna8dTwKR0gv3PBM5l5p2hQpF3NYcm5dQziExJj6Z/hyfXuh5W5aSrz9OAq zMvREZ+lwaUNjNG50aX6YHA2tBXvFrUOAHdAN4qhljuQBZuEp+SAeAcF3LmHE4tthhDW U/QfxLn4mt+eInq09++giomF8RBYlDz9BQ6ZE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=vk0dB+fOX5nUhs8ZsKhh8yyN0rFlMd4jwvRBxs3dSgpaGik9IeyP4XomVQ0oMmYt/2 vrVd6+RNpiLOBTz2RVPGBCVXEwOCghzaaazxlGHX4gaQHdGphIgOLZtcCtAeEoN75At9 jwHeu7tqnGTFjHMFFB7Ak0pqzHAs9QDZfFiuE=
2010/9/3 Eamon Nerbonne <eamon.nerbonne@xxxxxxxxx>:
> To speed up covariance computations, I tried to use triangularView to avoid
> computing unnecessary coefficients. However, that didn't work as expected.
>
> To start with, there seems to be a g++ bug that prevents compiling the
> following template:
>
> #include <Eigen/Core>
> using namespace Eigen;
> template <typename TPoints>
> inline static Matrix<typename
> TPoints::Scalar,TPoints::RowsAtCompileTime,TPoints::RowsAtCompileTime>
> CovarianceX(Eigen::MatrixBase<TPoints>const & points) {
> typedef typename TPoints::Scalar Scalar;
> typedef Eigen::Matrix<Scalar,TPoints::RowsAtCompileTime,1> TPoint;
> typedef Matrix<typename
> TPoints::Scalar,TPoints::RowsAtCompileTime,TPoints::RowsAtCompileTime>
> TMatrix;
> TPoint mean = points.rowwise().sum() * (1.0/points.cols());
> TPoint diff = TPoint::Zero(points.rows());
> TMatrix cov = TMatrix::Zero(points.rows(),points.rows());
>
> for(int i=0;i<points.cols();++i) {
> diff.noalias() = points.col(i) - mean;
> cov.triangularView<Eigen::Upper>() += diff * diff.transpose();
> //line A
> }
>
> cov.triangularView<Eigen::StrictlyLower>() = cov.transpose(); //line
> B
> return cov * (1.0/(points.cols()-1.0));
> }
>
> int main(){return 0;}
>
> In particular, on lines A&B the compiler complains of "expected
> primary-expression before ')' token". If the function isn't templated it
> compiles (and works). In MSC, it works. It looks like specifying a
> template argument here breaks something - anyone know of a workaround? I
> tried using a templated class with a static function, but that fails
> equally.
This is just the usual c++ syntax issue, argh, we've answered this
question dozens of times, I wonder where we could document it once and
for all so users find it.
You have to add a template keyword:
cov.template triangularView<Eigen::Upper>() += ...
GCC is right to reject this code without template.
>
> Now, even when this works, it's a lot slower than without triangularView,
> which is odd. At first I thought that's because I can't mix .noalias and
> triangularView, but as far as I can tell, line A is using a lazy product
> despite possible aliasing (isn't that a bug?) so the perf degredation may
> simply be due to the greater code complexity.
no idea... sorry. (no time to investigate now).
Benoit
>
> --eamon@xxxxxxxxxxxx - Tel#:+31-6-15142163
>