Re: [eigen] Floating point as index type

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


Hi!

If we wanted to ensure not to break existing code here, we'd need to explicitly allow everything which can be converted to Eigen::Index (aka std::ptrdiff_t). But on the one hand, that would be complicated (due to the new Indexing feature), and on the other hand, I agree that this might rather hide existing bugs. (Like accessing Vector[(double(N)/n)*n] may or may not round down)

As a workaround you could write yourself a DenseBase plugin which adds `operator()(double, double)`, etc:
https://eigen.tuxfamily.org/dox-devel/TopicCustomizing_Plugins.html

But as also suggested by Rasmus, you should really just explicitly cast your floats/doubles to Eigen::Index (perhaps after rounding instead of truncating -- depending on your use-case). This will not add any overhead, as this was happening implicitly before -- only some syntactic noise which actually is good, since you are misusing types here.


Cheers,
Christoph




On 25/11/2019 23.16, Gael Guennebaud wrote:
Hi,

yes we are aware of that. We could explicitly accept float and double as
"valid_index_type", but I think this would just keep silent some latent
bugs. I've just added note there:
http://eigen.tuxfamily.org/index.php?title=3.4

Cheers,
gael

On Mon, Nov 25, 2019 at 7:57 PM Janos Meny <janos.meny@xxxxxxxxxxxxxx>
wrote:

Hey everyone,

I noticed that in the development branch the following code will no longer
compile: https://godbolt.org/z/pHPX2j

Aside from the fact that I think this is a bug, this would break a lot of
code I think.

Best regards

Janos




--
 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 Straße 122, D-67663 Kaiserslautern, Germany

  Geschäftsführung:
  Prof. Dr. Antonio Krüger (Vorsitzender)
  Dr. Walter Olthoff

  Vorsitzender des Aufsichtsrats:
  Dr. Gabriël Clemens
  Amtsgericht Kaiserslautern, HRB 2313
  -------------------------------------------------------------



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