Re: [eigen] Signed or unsigned indexing |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
Some more thoughts on this topic:
* Jon Kalb (signed integer fraction) has pointed out that repeatedly obnoxious bugs with unsigned integer underflow and bounds wraparound when subtracting sizes went unnoticed very very long even in libraries like STL & boost.
* Andrej Alexandrescu pointed out that whether using indices or pointers in algorithmic loops is faster seems to change every five years or so. That means, that using indices instead of pointers is a valid strategy and may increase your performance.
* That the specified wraparound behaviour when using loop indices inhibits a class of optimizations and therefore especially for fixed but unknown loop lengths there is a inherent performance hit of using unsigned. See CppCon 2016 Michael Spencer - My Little Optimizer: undefined behaviour is magic. https://www.youtube.com/watch?v=g7entxbQOCc
* When pressed to answer why or how it came that std::size_t became unsigned Stoustrup replied: Someone had a case for needing to reserve more than half the address space in a vector and the number of elements to be strictly positive. (sadly I could not find the reference here) Which is funny, because you cannot actually use more than half, as Mark pointed out.
Am 20.01.2017 um 18:48 schrieb Mark Borgerding:
On the other side, I understand people who use std::size_t for indexing because it is consistent with the standard library.
* Eric Nieblers STL2 project has plans on using signed. See discussion here:https://github.com/ericniebler/stl2/issues/182 . So if Eigen now chooses unsigned for compatibility and the project STL2 ever flies, we might look like fools ;)
For me the argument that loop optimization suffers from using unsigned and this is inherent in the language (and cannot be fully solved by compiler vendors) is the strongest argument, as performance matters for Eigen's loop and indexes might likely end up being used in their exit conditions.
Regards, Martin
Am 20.01.2017 um 18:48 schrieb Mark Borgerding:
Well made points. These greatly expand on points I made on this list in May 2010.
- References:
- [eigen] Signed or unsigned indexing
- From: Henrik Mannerström
- Re: [eigen] Signed or unsigned indexing
- From: Benoit Jacob
- Re: [eigen] Signed or unsigned indexing
- From: Francois Fayard
- Re: [eigen] Signed or unsigned indexing
- From: Mark Borgerding
- Re: [eigen] Signed or unsigned indexing
- From: Martin Beeger
- Messages sorted by: [ date | thread ]
- Prev by Date: Re: [eigen] Signed or unsigned indexing
- Next by Date: Re: [eigen] Signed or unsigned indexing
- Previous by thread: Re: [eigen] Signed or unsigned indexing
- Next by thread: Re: [eigen] Signed or unsigned indexing
Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/