-
-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
STYLE: Replace std::pow(x, 2)
calls with Math::sqr(x)
#5249
STYLE: Replace std::pow(x, 2)
calls with Math::sqr(x)
#5249
Conversation
BTW, Edit: |
I had actually started writing a comment wondering why we saved 1 letter and didn't just call it Renaming it |
Thanks @issakomi and @seanm I don't like the name ITK/Modules/Core/Common/include/itkMath.h Line 822 in 018e0ea
If it would be implemented in ITK instead, I would prefer it to be named Anyway, my aim for this PR is to avoid calling I feel that a new square function for ITK is beyond the scope of this PR. (The new square function might be constexpr, it might be written as a function template, it would need extra unit tests, deprecating the current |
@@ -128,7 +128,7 @@ StatisticsLabelMapFilter<TImage, TFeatureImage>::ThreadedProcessLabelObject(Labe | |||
|
|||
// increase the sums | |||
sum += v; | |||
sum2 += std::pow(static_cast<double>(v), 2); | |||
sum2 += Math::sqr(static_cast<double>(v)); |
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.
This one is arguably better left as it was, to be more similar to the next 2 lines... but I don't feel strongly about it.
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.
I see your point, thanks, but on the other hand, the next line (sum3 += std::pow(static_cast<double>(v), 3)
) might as well use Math::cube
instead 😸
m_Radius >= std::sqrt(std::pow(pointVector.GetNorm(), 2.0) - std::pow(distanceFromCenter, 2.0))) | ||
m_Radius >= std::sqrt(Math::sqr(pointVector.GetNorm()) - Math::sqr(distanceFromCenter))) |
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.
As a follow-up, it might be nice to replace Math::sqr(pointVector.GetNorm()
with pointVector.GetSquaredNorm()
, but I guess doing so might introduce regression errors, because it would potentially reduce rounding errors!
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.
Note that distanceFromCenter
is in fact the dot product of two vectors:
ITK/Modules/Core/Common/include/itkFiniteCylinderSpatialFunction.hxx
Lines 96 to 97 in e9af5c5
const double distanceFromCenter = dot_product(medialAxisVector.GetVnlVector(), pointVector.GetVnlVector()); | |
So I'm just wondering if the square of distanceFromCenter
was originally intended. (But I will leave it "squared" like this, because I don't know the original intention.)
`Math::sqr(x)` appears slightly more readable than `std::pow(x, 2)`.
d349adf
to
30a11da
Compare
This is a step in the right direction. If someone has time, this might be improved further. |
Following ITK pull request InsightSoftwareConsortium/ITK#5249 commit InsightSoftwareConsortium/ITK@20e2f6d "STYLE: Replace `std::pow(x, 2)` calls with `Math::sqr(x)`"
Following ITK pull request InsightSoftwareConsortium/ITK#5249 commit InsightSoftwareConsortium/ITK@20e2f6d "STYLE: Replace `std::pow(x, 2)` calls with `Math::sqr(x)`"
Math::sqr(x)
appears slightly more readable thanstd::pow(x, 2)
.