RE: [eigen] SparseMatrix with non POD-"Scalar" type (e.g. SparseBlockMatrix) yields unnecessary initialisations of Scalar-type?

[ Thread Index | Date Index | More Archives ]

Hello all,

I've tried to get one of the built-in sparse solvers (ConjugateGradient for the
moment) to accept my BlockMatrix "Scalar"-type. This BlockMatrix-Scalar behaves
a bit like a complex number in that its Real-type != to the type itself
(because many epsilons and comparisons etc. use this type).
I've defined some of the needed operators on my "Scalar" type, but some
things don't work.

There's one oddity I don't understand: I've had to define
Eigen::internal::scalar_product_traits for <BlockMatrix, BlockMatrix::Scalar>
(which I found a bit strange as Matrix<double, 5, 5> * double should already
be available).

A problem I'm currently stuck at is why Eigen doesn't seem to pick up my
definitions of real() and abs2():
The calls happen in ConjugateGradient.h:49
  RealScalar absNew = internal::real(;
=> residual and p are vectors of my Scalar-type, so vectors of 5x5 matrices for
The other culprit is in the next line, i.e. ConjugateGradient.h:50
  RealScalar rhsNorm2 = rhs.squaredNorm();
which is from Dot.h:115
  return internal::real((*this).cwiseAbs2().sum());
but it seems the cwiseAbs2() again only finds the internal implementation.

The actual compilation errors are as follows (from the internal::real & abs2):
eigen-3.2.0/Eigen/src/Core/MathFunctions.h:68:12: No viable conversion from 'const BlockMatrixWrapper<Eigen::Matrix<double, 5, 5, 0, 5, 5> >' to 'RealScalar' (aka 'double')

eigen-3.2.0/Eigen/src/Core/MathFunctions.h:263:12: No viable conversion from 'const typename ProductReturnType<Matrix<double, 5, 5, 0, 5, 5>, Matrix<double, 5, 5, 0, 5, 5> >::Type' (aka 'const CoeffBasedProduct<LhsNested, RhsNested, EvalBeforeAssigningBit | EvalBeforeNestingBit>') to 'RealScalar' (aka 'double')

in spite of me having defined
template<typename B>
inline typename Eigen::NumTraits<typename B::Scalar>::Real abs2(const BlockMatrixWrapper<B>& x)
template<typename B>
inline typename Eigen::NumTraits<typename B::Scalar>::Real real(const BlockMatrixWrapper<B>& x)

Attached is my current code (which doesn't compile due to the mentioned problems).

Best regards

Daniel Vollmer

Deutsches Zentrum für Luft- und Raumfahrt e.V. (DLR)
German Aerospace Center
Institute of Aerodynamics and Flow Technology | Lilienthalplatz 7 | 38108 Braunschweig | Germany

Attachment: BlockMatrixWrapper.h
Description: BlockMatrixWrapper.h

Attachment: main.cpp
Description: main.cpp

Mail converted by MHonArc 2.6.19+