Skip to content

Conversation

@fredroy
Copy link
Contributor

@fredroy fredroy commented Jan 29, 2026

using std algos, clamp, etc and some keywords noexcept.

and fixed_array_algo, removing some useless templates

and some (generated but modified) unit tests for vec ,as there were almost none ? 🤔

Note that fixed_array_algo is only used in RGBAColor, at least in the standard code base.

[with-all-tests]


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).

@fredroy fredroy added pr: status to review To notify reviewers to review this pull-request pr: clean Cleaning the code pr: test PR adding test(s) in SOFA labels Jan 29, 2026
@fredroy
Copy link
Contributor Author

fredroy commented Jan 29, 2026

[ci-build][with-all-tests]

for (Size i=1; i<N; i++)
r += this->elems[i]*this->elems[i];
return r;
return std::inner_product(elems.begin(), elems.end(), elems.begin(), ValueType{});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ask the question of the performances...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ask the question of the performances...

Usually people (and IA...) advise to use stl functions because it may help the compiler more (vectorization and stuff). But of course it depends of the implementation of the libstl itself... I will try to do some bench tho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://quick-bench.com/q/WGEPcgHll4O2cAl8Ms-VoyRBn7I

At -O3, all config (clang/gcc & libstdc++/libc++) give same result. But will less optimization the loop is faster.
Should I roll back the implementation ?

Comment on lines +209 to +217
TEST(VecTest, setFromOtherVec)
{
sofa::type::Vec<3, double> v1(1.0, 2.0, 3.0);
sofa::type::Vec<5, double> v;
v.set(v1);
EXPECT_EQ(v[0], 1.0);
EXPECT_EQ(v[1], 2.0);
EXPECT_EQ(v[2], 3.0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set here is purposefully tested with a smaller vector?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I can add other set() cases as well

Co-authored-by: Themis Skamagkis <70031729+th-skam@users.noreply.github.com>
for (Size i=0; i<N; i++)
sum += this->elems[i];
return sum;
return std::accumulate(elems.begin(), elems.end(), ValueType{});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: clean Cleaning the code pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants