I want to have a recursive function
template <typename Derived>
void f(Eigen::MatrixBase<Derived>& m)
{
size_t blockRows = ...
size_t blockCols = ...
....
f(m.block(0, 0, blockRows, blockCols));
}
This unfortunately results in an infinite compile time recursion.
The first call would be to
f<Eigen::MatrixBase<Derived> >
The second would be to
f<Eigen::Block<Eigen::MatrixBase<Derived>, ... > >
The third call would be to
f<Eigen::Block<Eigen::Block<Eigen::MatrixBase<Derived>, ... >, ... > >
Every time a block of block is requested.
What is the best practice to implement recursive functions in Eigen, which still work on any Eigen matrix type?
I think, I should use some type, that still wraps the same piece of memory, but is not an expression template and it is evaluated.
You can cast your recursive block to an Eigen::Ref to avoid the infinite type instantiation:
Ref<MatrixXd> bl = m.block(0, 0, blockRows, blockCols);
f(bl);
To stay fully generic, you can replace MatrixXd by typename Derived::PlainObject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With