Skip to content
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

[Core] Refactor VMultiOpEntry #4333

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

alxbilger
Copy link
Contributor

My goal was to simplify the writing of vector operations in ODE solvers.

Before

VMultiOp ops;
ops.resize(2);
// vel += dx * dt
ops[0].first = vel2;                                   // <-- What is first???
ops[0].second.push_back(std::make_pair(vel.id(),1.0)); // <-- What does a pair represent? What does this list represent?
ops[0].second.push_back(std::make_pair(dx.id(),dt));
// pos += vel * dt
ops[1].first = pos2;
ops[1].second.push_back(std::make_pair(pos.id(),1.0));
ops[1].second.push_back(std::make_pair(vel2.id(),dt));

to

VMultiOp ops(2);

// vel += dx * dt
ops[0] = VMultiOpEntry{ vel2,
    ScaledConstMultiVecId{vel.id(), 1._sreal} + ScaledConstMultiVecId{dx.id(), dt}};
// ok, now we know that the scalar and the MultiVecId are multiplied together.
// there is also an operator +, suggesting that the whole operation is a linear combination

// pos += vel * dt
ops[1] = VMultiOpEntry{ pos2,
    ScaledConstMultiVecId{pos.id(), 1._sreal} + ScaledConstMultiVecId{vel2.id(), dt}};

Note that in C++20, we can write something like:

ops[1] = VMultiOpEntry{ .outputId = pos2,
    ScaledConstMultiVecId{pos.id(), 1._sreal} + ScaledConstMultiVecId{vel2.id(), dt}};

which is IMO clearer.

NOT IMPLEMENTED:
I wanted to go even further (but there are problems of type conversion, so it's not yet ready):

VMultiOp ops(2);

// vel += dx * dt
ops[0] = VMultiOpEntry{ vel2, vel.id() + dx.id() * dt};

// pos += vel * dt
ops[1] = VMultiOpEntry{ pos2, pos.id() + vel2.id() * dt};

By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

VMultiOpEntry is no longer a nested class. It has its own file.

It has been refactored for more expressivity.

An operator+ has been added to mimic a bit a mathematical notation
@alxbilger alxbilger added pr: breaking Change possibly inducing a compilation error pr: status to review To notify reviewers to review this pull-request refactoring Refactor code pr: dev meeting topic PR to be discussed in sofa-dev meeting labels Dec 4, 2023
@alxbilger alxbilger added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Dec 20, 2023
@hugtalbot hugtalbot removed the pr: dev meeting topic PR to be discussed in sofa-dev meeting label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: breaking Change possibly inducing a compilation error pr: status wip Development in the pull-request is still in progress refactoring Refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants