ITK icon indicating copy to clipboard operation
ITK copied to clipboard

ENH: Declare `front()` and `back()` of Index, Offset, and Size constexpr

Open N-Dekker opened this issue 1 year ago • 4 comments

Follow-up to pull request https://github.com/InsightSoftwareConsortium/ITK/pull/3236 commit 47bce264791a53853020a3911dd94d060cfbd655 "ENH: Declare begin(), end() of FixedArray, Index, Offset, Size constexpr"

N-Dekker avatar Apr 22 '24 13:04 N-Dekker

@thewtex Would this PR still be feasible for v5.4.0? It just adds constexpr keywords to front() and back() member functions.


FYI, Adding constexpr to itk::Index::back() would be a stepping stone towards evaluating the OffsetToIndexTable of BSplineInterpolationWeightFunction at compile-time, instead of at run-time: https://github.com/InsightSoftwareConsortium/ITK/blob/4d750726d06ba28c601b8a4bfac8780baa395ff1/Modules/Core/Common/include/itkBSplineInterpolationWeightFunction.h#L124

Which is likely to speed up BSplineInterpolationWeightFunction::Evaluate:

https://github.com/InsightSoftwareConsortium/ITK/blob/4d750726d06ba28c601b8a4bfac8780baa395ff1/Modules/Core/Common/include/itkBSplineInterpolationWeightFunction.hxx#L45-L48

N-Dekker avatar Apr 23 '24 07:04 N-Dekker

@thewtex Would this PR still be feasible for v5.4.0? It just adds constexpr keywords to front() and back() member functions.

Out of my curiosity, is this for a particular issue? Has it given any measurable performance benefit?

blowekamp avatar Apr 23 '24 12:04 blowekamp

Out of my curiosity, is this for a particular issue? Has it given any measurable performance benefit?

This PR would pave the way to adding constexpr to itk::Index iteration, by itk::IndexRange. Which would allow creating the OffsetToIndexTable of BSplineInterpolationWeightFunction at compile-time, instead of at run-time. I haven't yet been able to benchmark, but it may certainly benefit its performance.

Note that itk::Index<N> is similar to std::array<itk::IndexValueType, N>, whose front() and back() are also marked "constexpr": https://en.cppreference.com/w/cpp/container/array/back

N-Dekker avatar Apr 23 '24 15:04 N-Dekker

I think we should save it for ITK 6 to avoid any unforeseen issues.

@thewtex OK, thanks. Marked "draft" to avoid that this PR might accidentally be merged before the release of ITK 5.4!

N-Dekker avatar Apr 24 '24 18:04 N-Dekker

I think this pull request may also be merged now, as v5.4.0 has been tagged (https://github.com/InsightSoftwareConsortium/ITK/pull/4603#issuecomment-2120498131)

N-Dekker avatar May 21 '24 08:05 N-Dekker