Re: [eigen] Floating point as index type |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Floating point as index type
- From: Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 26 Nov 2019 00:41:22 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=uni-bremen.de; s=2019; t=1574725283; i=@uni-bremen.de; bh=zymrvKi8YEGoG1DncboUE2GJUht1dr7gUWl0CFdXPdo=; h=To:References:From:Date:In-Reply-To; b=nEG8rz3iM/htuwakgLDlQzzjTXAWFG3e9cHrzh2BLGlBrum8nvLuW4nsjdbzTFgnp 9iXyReLoq9j1MG99916hrjo59bm5bjw2WTswkF/ZBrI9WjELVZb2aVLmzP5QIvFiER 5aCZzXIjJ8lzK5DrsbWFw5puIs60/DEYfZ4BIJAAA8zrdoQ5LkcxqGka+AXRKW0bpd yKrWaFQJMw44DbfOBwWFytlxI7ZAtB1g1NNFHm4TyM7tRKsQVb710rhTTy/w//2klB SjxVs6hHtMOig4t5MeI6qDcwNX9qwLBPjaar9soBuU3Umod/RvE0FfY2OezPujNCL7 1ukd55dlyNsVw==
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
-------------------------------------------------------------