[eigen] Subtle way to produce bugs when using Block |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] Subtle way to produce bugs when using Block
- From: Márton Danóczy <marton78@xxxxxxxxx>
- Date: Fri, 13 Nov 2009 14:25:52 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=ayqbCSVWTv+NKZl7jYaRoeb1Ojxx6tUwLG3Aq5NlFyI=; b=cH22UNtzc4+At1ctZ0XkoAiaAJzEDFxd3hZp7O6nwDWOFLVskRyuW2osN1GZENRfqi 37B6JSGPuPYwb82b+/Wm1gPSxDMs+tGnY4ZEThc7nFEMYWNB6h7YbxOgORBR/Fmyf3AF teAHljsM+qEegOgGnIigZIaa4fY00QBkfvfMk=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=jVbKp+/7jdZ4r4oejsW7oi1Z+q8fAlT0aV48KbLKIBT0dWsChaGxbKERd4ooLNbmmK xhbqXLz75wOW8GWZLFaLtxHzcO1lMCbVdJbogR/tlSAY58Dr8CcXGSDtFtFXy4UWIW2q mB4xbUGb4AmrSkbGMv/SCSOtXKjLiXOHAq8ek=
Hi,
I've encountered some (possibly not so?) weird behaviour when keeping
references to blocks:
template <typename X>
void f(const MatrixBase<X>& x)
{
typedef typename Block<X, ei_traits<X>::RowsAtCompileTime, 1> col_t;
for (int i=0; i<x.cols(); ++i)
{
//using this line produces strange (undefined) results
col_t xi(x, i);
//this is the correct way to do it:
col_t xi(x.derived(), i);
do_something(xi);
}
}
It was quite hard to hunt down this bug. Apart from that I don't
understand what's happening here, is there a way to prevent the user
from making this mistake?
Thanks,
Marton