[eigen] Recursion and block matrices |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
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,
which, adds the identity matrix to the main diagonal of the input
matrix (the point is
to illustrate the recursion/blocks issue :-) ).
//////////////////////////////// CODE
//////////////////////////////////////////////////////////////////////////////
#include <Eigen/Core>
using namespace Eigen;
#include <iostream>
using namespace std;
template< class Derived >
void incr( const DenseBase< Derived >& mat )
{
DenseBase< Derived >& matV =
const_cast< DenseBase< Derived >& >( mat );
++matV(0,0); // <--------- Line 13
if( ( 1 == mat.rows() ) ||
( 1 == mat.cols() ) )
{
return;
}
else
{
incr( mat.bottomRightCorner( mat.rows() - 1,
mat.cols() - 1 ) );
}
}// incr
int main( int argc, char* argv[] )
{
MatrixXd mat( 2, 3 );
mat << 1, 2, 3, 4, 5, 6;
cout << "Before: " << mat << endl;
incr( mat );
cout << "After: " << mat << endl;
return 0;
}// main
//////////////////////////////// END CODE
/////////////////////////////////////////////////////////////
The current error is,
Line 13:3: error: lvalue required as increment operand
which makes sense, since not all expressions are l-values.
I've tried replacing "DenseBase" with various combinations of Map and Block,
but no success.
Any suggestions?
On a related issue, Block< Block > is, conceptually, simply a Block (at
least at run-time).
Any comments on how this "meta complexity" is addressed, in general?
Thank you.