Re: [eigen] Aliasing bug with Transpose, possibly a ReturnByValue problem |

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

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: Re: [eigen] Aliasing bug with Transpose, possibly a ReturnByValue problem*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Mon, 16 Feb 2015 16:17:29 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=WQQd8rer/5b/+kOacw0crArvTO+qf/lshAopjGtXRn8=; b=0NOMWe3YGVO+8K74+tkjVP9WTesM+WZfVvPdHWW/22M/Z6nPmEdyt27gcCxKRre1Wf 6ue3emz6ioasdc9ZMOG4Csl0nYkEoUIgDs0oEj3EuuMdBZRi2DmpanyKFrYY3SeJd3aY LlAPlcDY5idNWaQInu0jvXGSkTlnYKICg9NmLnHTBwtgDKbUDDLzW3aKJnYXyFz43rJh VwfSm5cT23E67NBsFanqJ5jC1e3R37tKbv6mrjj80QbeiP1/rgBVrpplABo+Yb1Sajwe 0xvXh95uslSrGxnG3h0NpyUwVS3SuYBkSH7S7oSnvmVtLZWzn/VP/nNZYHBTDNr+Gkd8 dUbg==

Hi,

sorry for the very late reply. Basically, dealing with aliasing issue is the responsibility of the user. There only a very few cases where Eigen explicitly consider aliasing:

- plain matrix-matrix products, which assumes aliasing by default (in my opinion this should be changed to noaliasing by default, but that's not the point here)

- A = A.transpose() (and some variants, which trigger a runtime assertion in debug mode

- A = A * permutation, which automatically fallbacks to an inplace implementation. Only works if the types of both 'A' are the same.

All other cases will silently fail. It would ben ice to implement a mechanism to automatically detect all possible cases of aliasing, but I don't see any lightweight solution for that.

gael

On Mon, Jan 19, 2015 at 7:57 AM, Adrien Escande <adrien.escande@xxxxxxxxx> wrote:

Adrien EscandeI know that tracking all aliasing problems is difficult and this might just be a silly example. However, with my limited understanding of Eigen's internal, it looks to me more like a problem with the ReturnByValue class. In particular, it looks like, by using evalTo, the implementation of MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other) in assign.h is ignoring the possibility of aliasing. That would mean that expressions with aliasing nested in ReturnByValue would always be an issue.In the first case, we getDear all,while browsing through Eigen's code, I found the following aliasing problem:

#include <Eigen/Eigen>

#include <iostream>

using namespace Eigen;

int main()

{

VectorXd v = VectorXd::LinSpaced(15, 1, 15);

MatrixXd M = Map<MatrixXd>(v.data(), 5, 3);

Transpositions<Dynamic> T(3);

T[0] = 2; T[1] = 0; T[2] = 0;

MatrixXd M2 = T*M.topLeftCorner(3, 3);

std::cout << M2 << std::endl << std::endl;

M.bottomRightCorner(3, 3) = T*M.topLeftCorner(3, 3);

std::cout << M.bottomRightCorner(3, 3) << std::endl << std::endl;

}

1 6 11

3 8 13

2 7 12which is correctIn the second case

1 6 11

1 6 11

2 7 12which is not.

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Merge Tensor module** - Next by Date:
**Re: [eigen] Code coverage and templates** - Previous by thread:
**Re: [eigen] (co-)mentoring for Google Summer of Code** - Next by thread:
**[eigen] Help needed to run a benchmark on many machines**

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