Re: [eigen] Recursion and block matrices

[ Thread Index | Date Index | More 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:
There is an experimental solution here:


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 ^^.

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) {

This version only works for square matrices, I guess you get the idea, though.


Dipl.-Inf. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252

Mail converted by MHonArc 2.6.19+