Re: [eigen] Recursion and block matrices |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
On 27.08.2012 19:33, Norman Goldstein wrote:
I haven't been able to figure out how to write a routine that calls
itself recursively
with successively smaller sub-blocks of the original matrix. Here is a
simple example,
With the current stable branch this is not possible, because this would
possibly generate infinitely many template instanciations. See also:
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=408
There is an experimental solution here:
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=481.
[...]
template< class Derived >
void incr( const DenseBase< Derived >& mat )
{
DenseBase< Derived >& matV =
const_cast< DenseBase< Derived >& >( mat );
[...]
{
incr( mat.bottomRightCorner( mat.rows() - 1,
mat.cols() - 1 ) );
Your problem here, however, is that mat is const, so
mat.bottomRightCorner(...) is a Block<const ...> and that inner const is
not removed by a const_cast. If you do matV.bottomRightCorner(...)
instead, you should get to the problem above ^^.
Btw:
If you just do tail recursion, you don't need to do recursion at all,
just do sth like this:
template<class Derived>
void incr(const DenseBase<Derived>& mat){
for(int i=mat.rows(); i>0; --i) {
++mat.bottomRightCorner(i,i)(0,0);
}
}
This version only works for square matrices, I guess you get the idea,
though.
Christoph
--
----------------------------------------------
Dipl.-Inf. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: +49 (421) 218-64252
----------------------------------------------