-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[c++20] Rewrite Vector, Location2D, Matrix and LUDecomposition #782
base: develop
Are you sure you want to change the base?
Conversation
b0fc65c
to
a97cf02
Compare
Yes please. Constexpr constructors are particularly useful as they reduce to constinit .data section to be copied on startup instead of constructed by instructions. |
I think it may be desired to restrict these metrics to 0-255. |
That code was written for 8 bit AVR more than ten years ago. On those there is a penalty since arithmetic registers are 8 bit only but |
Great, so i'll take this to 2020! |
a97cf02
to
2f525e4
Compare
55ce405
to
cab8d18
Compare
Got some CI claims @windows only but no machine around.. |
There are the same errors on Linux. You could be lucky and not need Windows to debug this. |
5760b8b
to
11a5c8a
Compare
7582629
to
a6f7724
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a complete rewrite, maybe a little too radical but feels like natural: modm::Vector
is now an std::array
with support for arithmetic operations.
I've benchmarked against the original code and found the exact same - in some cases even faster - execution times.
src/modm/math/geometry/vector.hpp
Outdated
|
||
// no clue why, but RVO / Loop unrolling is not applied for this ... | ||
// std::transform(this->begin(), this->end(), other.begin(), res.begin(), Func{}); | ||
|
||
// ... but this optimizes perfectly. | ||
res.x() = BinFunc{}(this->x(), other.x()); | ||
if constexpr(N > 1) res.y() = BinFunc{}(this->y(), other.y()); | ||
if constexpr(N > 2) res.z() = BinFunc{}(this->z(), other.z()); | ||
if constexpr(N > 3) res.w() = BinFunc{}(this->w(), other.w()); | ||
if constexpr(N > 4) res.v() = BinFunc{}(this->v(), other.v()); | ||
if constexpr(N > 5) res.u() = BinFunc{}(this->u(), other.u()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For operator
s returning a new Vector
, the <algorithm>
-path did not optimize sufficiently (Line:174) - execution time has tripled. I've found a workaround (Line:177-182) but there's for sure a more elegant solution.
b57e8ed
to
9af3c48
Compare
@TomSaw I am quite busy with work right now, but will try to review tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the effort you put into this. I got about halfway through your changes and will have a more detailed look when I find more time to do so.
position == other.position and | ||
std::abs(orientation - other.orientation) < __FLT_EPSILON__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can position be float? Should we handle that case somehow?
Not sure if __FLT_EPSILON__
is the right thing to do. For numbers between 1.0 and 2.0 it's the distance between adjacent floats. For numbers greater than 2.0 the comparison will do the same thing as ==
.
Oops... due to my vector deep dive, i've forgot to mention 🤦♂️: If you find another minute, better take a second look on My pleasure. Also thanks for taking the time to review my code and support my practice! Win-win, i 💙 open-source. |
ba50e27
to
bf3e15e
Compare
480cf7a
to
291a456
Compare
291a456
to
9e2bb09
Compare
9e2bb09
to
30c76f3
Compare
This is an excerpt from #665.
modm::Vector<T, 2>
is passed as template-parameterResolution
tomodm::graphic::Buffer<..>
-> Thus the constructors require
constexpr
By the chance, i may give some maintenance to all of these vector files.
Just modernization, no changes in logicC++20 flavoured, more feature complete and 100% backwards compatible.Key changes
<algorithm>
everywhere (did i miss an oportunity? let me know!)std::round
whenever float->integral conversion occursGeometricTraits<T>::round()
could be removed[[depricated]]
allVector<>::convert()
in fave of fresh conversion constructors .operator<<
using declaratives
for local instances ofVector<T, N>
(Re)assorted methods
Migrated all method definitions into
vector{N}.hpp
TODO
Vector<T, 2>::convert()
andLocation2D<U>::convert()
for backwards-comp and depricate itgeometric_traits.hpp
avr specialisation