Re: [eigen] malloc in Scalar x Matrix Matrix

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Looks like this:
https://stackoverflow.com/questions/51043842/call-eigen-gemm-over-externally-allocated-data

It has been fixed a year ago on the devel-branch, but apparently not backported to 3.3:
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1562


If you know the sizes of your matrices at compile time, you should write

  const Map<const Matrix<double, 2, 10> > A( _A.data());
  const Map<const Matrix<double, 10, 2> > B( _B.data());
  Map<Matrix2d> C( _C.data());
  double v = 2.0;
  C.noalias() = v * A * B;

If you know can't upgrade to the devel branch, but know that your matrices are small (but with unknown size at compile time), you can write this as a workaround:

  C.noalias() = v * A.lazyProduct(B);


Generally, if you fail to produce a minimal example from scratch, you can start with (a copy of) your code and remove everything which does not let the error disappear, hopefully leaving just a few lines.

Cheers,
Christoph


On 09/07/2019 16.15, Henrik Larsson wrote:
Hi,

I have an expressions of type
C.noalias() = alpha * A * B;
where alpha is a double and A, B and C are Maps of double Dynamic
Matrices of proper sizes.
I want to avoid any memory allocation but when I try to debug the
expression using EIGEN_RUNTIME_NO_MALLOC, I get an exception since
malloc is still used.
Only if I use the expression _without_ the scalar, i.e.,
C.noalias() = A * B;
I don't get an exception. Unfortunately, I do not have a minimal working
example. A minimal working example actually *works* (without throwing an
exception) but for reasons I do not understand,
I get an exception in my actual code, which is more complicated, even if
I first "remap" everything to the following expression:

const Map<const MatrixXd> A( _A.data(), _A.rows(), _A.cols()); /* size 2
x 10; _A, _B are templated Maps of RowMajor Dynamic Matrices; _C is a
normal reference to RowMajor Dynamic Matrix.*/
const Map<const MatrixXd> B( _B.data(), _B.rows(), _B.cols());  /* size
10 x 2*/
Map<MatrixXd> C( _C.data(), _C.rows(), _C.cols()); /* size 2 x 2*/
double v = 2.0;
// C.noalias() = A * B; // no memory allocation
C.noalias() = v * A * B; // memory allocation

Could you please give me a hint why I get this memory allocation? Since
I do not have a minimal working example that throws the exception, I
attach a backtrace of the exception in my actual code.
It seems that the matrix size of the lhs ("C.noalias()") somehow gets
lost within the Eigen code. At # 15 of the attached backtrace, the
matrix size is still known but afterwards it is set to 0 (I cannot print
the matrix size in #14 due to code inlining).

I use eigen 3.3.7-2 from arch linux.

Best regards,

Henrik


--
 Dr.-Ing. Christoph Hertzberg

 Besuchsadresse der Nebengeschäftsstelle:
 DFKI GmbH
 Robotics Innovation Center
 Robert-Hooke-Straße 5
 28359 Bremen, Germany

 Postadresse der Hauptgeschäftsstelle Standort Bremen:
 DFKI GmbH
 Robotics Innovation Center
 Robert-Hooke-Straße 1
 28359 Bremen, Germany

 Tel.:     +49 421 178 45-4021
 Zentrale: +49 421 178 45-0
 E-Mail:   christoph.hertzberg@xxxxxxx

 Weitere Informationen: http://www.dfki.de/robotik
  -------------------------------------------------------------
  Deutsches Forschungszentrum für Künstliche Intelligenz GmbH
  Trippstadter Strasse 122, D-67663 Kaiserslautern, Germany

  Geschäftsführung:
  Prof. Dr. Jana Koehler (Vorsitzende)
  Dr. Walter Olthoff

  Vorsitzender des Aufsichtsrats:
  Prof. Dr. h.c. Hans A. Aukes
  Amtsgericht Kaiserslautern, HRB 2313
  -------------------------------------------------------------




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/