Re: [eigen] Incorrect result of multiplication with scalar (mingw gcc 4.5 x64) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Incorrect result of multiplication with scalar (mingw gcc 4.5 x64)
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Thu, 26 Aug 2010 09:22:44 -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=O1dlA5evTjfP6w8o72in6MKum+jFeB//eaQLdLAr2TU=; b=jgHb4gqnURpfdHkDtW1lrP5BkpSGFG6ARdQRnjBKdvPAzQNqXTPT9EpIADal+mS9d1 3k+CCe5GK1uaAjJfm1LQ35tXfGJ8EGkuvL+JucNArLZEiNuuBHHINS2C3Psw05FwMlZF c0il5I/jCxI5P31HDebNlRcySz19Iuu31241M=
- 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=wOL4rmnVY3vAqorKUS2PUuQa9CKUY4DWP6FEbGaKhFnCnpxn4shC8lfShBm+mkoWAi DFSKGfqOZjADCMY2E+9YcQoEJ9hsE3bnR4KdPDN+i3B2T0vBQsQIvvL8SI2xTtiDU9Ec AUeN845WGSNDWCRP8c1rlxMD9n9Q22KrPEcyo=
Hi,
Since we're discussing a possible compiler bug here, can you please
make a compilable testcase and give us your complete g++ command line?
Benoit
2010/8/26 Eamon Nerbonne <eamon.nerbonne@xxxxxxxxx>:
> Hi all,
>
> I stumbled across a compiler-specific bug (Current Hg tip version 'fix bad
> "using typename"'):
>
> static MatrixXd Covariance(Eigen::MatrixBase<MatrixXd> const & points,
> VectorXd const & mean) {
> return (points.colwise() - mean) * (points.colwise() -
> mean).transpose() * (1.0/(points.cols()-1.0));
> }
>
> static MatrixXd CovarianceB(Eigen::MatrixBase<MatrixXd>const & points,
> VectorXd const & mean) {
> VectorXd diff = VectorXd::Zero(points.rows());
> MatrixXd cov = MatrixXd::Zero(points.rows(),points.rows());
> for(int i=0;i<points.cols();++i) {
> diff.noalias() = points.col(i) - mean;
> cov.noalias() += diff * diff.transpose();
> }
> return cov * (1.0/(points.cols()-1.0));
> }
>
> These two methods return approximately equal results in MSC but not in GCC;
> turns out the multiplication by the scalar "1.0/(points.cols()-1.0" is
> ignored by GCC in the first example.
>
> Rearranging the order of the multiplication (i.e. putting the scalar factor
> in front or in the middle) provides a workaround at no performance cost, as
> does placing the result into an intermediate variable with the assignment
> operator rather than returning it directly (with perf cost). On the other
> hand, this is also broken:
>
> static MatrixXd Covariance(Eigen::MatrixBase<MatrixXd> const & points,
> VectorXd const & mean) {
> return (1.0/(points.cols()-1.0)) * ((points.colwise() - mean) *
> (points.colwise() - mean).transpose());
> }
>
> I'm guessing somewhere some specialization of GeneralProduct is wrong, but
> as to why this is compiler specific or what exactly the problem is, I don't
> know.
>
> --eamon@xxxxxxxxxxxx - Tel#:+31-6-15142163
>