Re: [eigen] Comma-initializer is quite expensive with compile-time known constants

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


On 2018-11-05 15:34, Ola Røer Thorsen wrote:
Hi, we're using fixed-size Eigen matrices (eigen 3.3.5), mostly
3-element-vectors, quaternions and 3x3 matrices but also larger ones. We've
been initializing them with the comma initializer, but looking at the
assembly produced the compiler (gcc 7) is not able to optimize everything
away even for small code like

Eigen::Vector3f v;
v << 1,2,3;
example: https://godbolt.org/z/y5YUnJ

GCC sometimes has trouble to fully optimize code inside the main function -- simply renaming your function will give fully optimized code (I'm not sure whether that is a known issue or a "feature" of GCC). Also, once you sufficiently tested your code, you should compile with `-DNDEBUG` to disable assertions.

Comparison:
https://godbolt.org/z/ujpwVU


[...]

Would it be possible to add some C++11 (or 14) feature to help in this
regard? Not sure if you want to keep Eigen completely free of
C++11-features. I've tried some variadic template "make_matrix" functions
that seem to do the trick, not having to do the error checks runtime.
Ideally, it would be nice to be able to write stuff like

const Eigen::Matrix3f m{ 1,2,3, 4,5,6, 7,8,9 };

Yes, this had been discussed a while ago:
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=954

We are not strictly "C++03 only" anymore.
The main issues are to agree on things like memory order (should this always be row-major, like the Comma-initializer?), or how to resolve ambiguous cases.
Also, how to compose more complex expressions from existing sub-matrices:

  // how to mark that A21 starts a new row?
  Eigen::MatrixXf A{ A11, A12, A21, A22};
  Eigen::MatrixXf A{ {A11, A12}, {A21, A22}};


Christoph


--
 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 fuer Kuenstliche Intelligenz GmbH
 Firmensitz: Trippstadter Straße 122, D-67663 Kaiserslautern
 Geschaeftsfuehrung: Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster
 (Vorsitzender) Dr. Walter Olthoff
 Vorsitzender des Aufsichtsrats: Prof. Dr. h.c. Hans A. Aukes
 Amtsgericht Kaiserslautern, HRB 2313
 Sitz der Gesellschaft: Kaiserslautern (HRB 2313)
 USt-Id.Nr.:    DE 148646973
 Steuernummer:  19/672/50006
 -----------------------------------------------------------------------



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