Repository navigation
ENH: Add GetFullNumberOfParameters() as an additive alternative to #7216 - #7248
hjmjohnson wants to merge 2 commits into
Conversation
|
@gdevenyi Please review this alternative |
gdevenyi
left a comment
There was a problem hiding this comment.
Thanks for this. I prefer this design to my #7216. It fixes the dense-field case (#6949, ANTsX/ANTs#2033) without breaking the ~11 downstream projects that your forest build found. Once this merges I will close #7216, and ANTsX/ANTs#2080, which this makes unnecessary.
I checked it at 90db8c9 and found no correctness problems.
- Call sites: nothing in
Metricsv4orRegistrationMethodsv4still calls the 32-bitGetNumberOfParameters(). InOptimizersv4, only Amoeba, LBFGS, LBFGSB, OnePlusOne and Powell still use it, which is intended: they size vnl objects withunsigned int, so they should keep throwing. - Silent narrowing: none found. Every count that now holds the full value goes into
FullNumberOfParametersTypeorSizeValueType, including the threader base's cached count andglobalDerivativeSize. - ANTs: no ANTs code calls the metric-level count. Its only
GetNumberOfParameters()calls are on command-line option functions or transforms. So with this PR, ANTs SyN needs no ANTs change for counts above 2^32 - 1. - Linux/GCC: I built a minimal tree with GCC 15, Release (Optimizers, Optimizersv4, Metricsv4, RegistrationMethodsv4, RegistrationCommon, tests on). It has no new warnings, and
ctestpasses 474/474, including both new GTests. That adds Linux/GCC to your macOS/clang run.
On your questions:
- Name:
GetFullNumberOfParameters()is fine with me. Whatever the name, the doc comment could say that this is the count ITK uses internally, and thatGetNumberOfParameters()is the 32-bit view of it, which throws when the count does not fit. - The v3 range-check commit: it is independent and correct. Keeping it here is fine. If you would rather keep this PR about the new method, a separate PR would also be fine; I have no preference.
- Deprecating
GetNumberOfParameters(): I would not, at least not now. The v3 cost functions and the vnl optimizers really are 32-bit, and deprecation would bring back the downstream churn this design avoids.
One behavior worth a sentence in the migration record. ObjectToObjectMetric::GetFullNumberOfParameters() returns the moving transform's count, and ITK's v4 code now asks it for the count. A class derived from ObjectToObjectMetric that overrides only GetNumberOfParameters() to report something else is therefore no longer what the threaders and optimizers see. No class in ITK does this, and I know of none downstream. The default in ObjectToObjectMetricBase covers the BRAINSTools-style metrics that derive from the base directly, as your FullParameterCountDefaultsToLegacyOverride shows.
Review assisted by Claude Code (claude-opus-5-5); the call-site audit, ANTs search, build and tests above were run locally.
dzenanz
left a comment
There was a problem hiding this comment.
As this new GetFullNumberOfParameters is rarely required, I am in favor of retaining both getters indefinitely.
[Medium impact] The changes affect bounded ITK registration workflows. Fix the shortened reductions and the wrapped local-count path before merging. Findings
|
90db8c9 to
3227ff8
Compare
hjmjohnson
left a comment
There was a problem hiding this comment.
Force-push 90db8c9 → 3227ff8: review fixes only, no rebase.
@gdevenyi, thanks for the review and the GCC run. Both of your suggestions are in 88b9ed7: the GetFullNumberOfParameters() doc comment now calls it the count ITK uses internally and GetNumberOfParameters() its 32-bit view that throws, and the migration record notes that an ObjectToObjectMetric subclass overriding only GetNumberOfParameters() no longer changes the count the threaders and optimizers see.
3227ff8 to
88cac33
Compare
|
Converting to draft. The underlying problem, vnl reductions that take an |
GetNumberOfParameters() returns unsigned int, so a dense displacement field with more than 2^32 - 1 parameters cannot be registered (InsightSoftwareConsortium#6949). Add a virtual GetFullNumberOfParameters() returning IdentifierType and use it where the v4 metrics, threaders, multi-metric, and v4 optimizers size derivatives. GetNumberOfParameters() and GetNumberOfLocalParameters() keep their signatures and throw on oversized counts, so existing overrides compile unchanged. Reductions over the derivative use std::inner_product with std::multiplies, matching vnl bit for bit without vnl's unsigned length. Alternative to InsightSoftwareConsortium#7216, which changed the existing return type. Co-Authored-By: Gabriel A. Devenyi <gdevenyi@gmail.com>
The v3 metrics in Registration/Common returned the transform's 64-bit parameter count through an unsigned int, silently truncating counts above 2^32 - 1. Convert with Math::CastWithRangeCheck so such counts throw itk::RangeError, matching the v4 metrics' overflow exception.
88cac33 to
deafb9a
Compare
An additive alternative to #7216 that lets SyN register dense fields above 2^32 - 1 parameters (#6949, ANTsX/ANTs#2033) without changing
GetNumberOfParameters(). A new virtual,GetFullNumberOfParameters(), returnsIdentifierType; ITK's dense-field code uses it, and every existing override and caller compiles unchanged.Merge danger: two-way door. The public API change is additive; the ABI changes (one new vtable slot), as expected for 6.0. Blast radius: none found downstream (see Evidence).
Feedback wanted: the method name, whether the v3 range check (second commit) belongs here, and whether
GetNumberOfParameters()should later be deprecated underITK_FUTURE_LEGACY_REMOVE.Shape of the change
Callers moved to the new method (all inside ITK):
Metricsv4: ImageToImageMetricv4 derivative sizing, the GetValueAndDerivative threader base and threaders (cached count, loops), Correlation and Mattes threaders, ObjectToObjectMultiMetricv4, PointSetToPointSetMetricWithIndexv4 Optimizersv4: ConjugateGradientLineSearch, QuasiNewton, RegularStepGradientDescent unchanged: Amoeba, LBFGS, LBFGSB, OnePlusOne, Powell (vnl, 32-bit) -> keep calling GetNumberOfParameters() and throw on oversized countsThe gradient-descent optimizers and SyN already size everything from the metric's derivative, so they need no change.
The second commit makes the v3 metrics in
Registration/Commonconvert the transform's count withMath::CastWithRangeCheck<unsigned int>, so a count above 2^32 - 1 throwsitk::RangeErrorinstead of truncating. It is separable.Why not change the return type, or template it?
NumberOfParametersTypeon cost functions, so dual-version code needs adecltypeworkaround. All but one of those overrides are v3 cost functions, which the dense-field path never uses.GetNumberOfParameters<T = unsigned int>()cannot be virtual. A non-virtual template over a virtual hook breaks every existing override, and an override written withoutoverride(PlusLib, Nornir) compiles and silently stops being called.Evidence
itkObjectToObjectMetricGTest.cxx, all passing:ReportsFullParameterCountBeyond32Bits: a transform reporting 2^32 + 3 parameters;GetFullNumberOfParameters()returns it andGetNumberOfParameters()throws.FullParameterCountDefaultsToLegacyOverride: a metric written like BRAINSTools'ReflectiveCorrelationCenterToImageMetric, overriding onlyunsigned int GetNumberOfParameters(), reports the same count through the new method.ctest -Lfor ITKOptimizers, ITKOptimizersv4, ITKMetricsv4, ITKRegistrationMethodsv4, and ITKRegistrationCommon: 223 passed, 0 failed (22 not run for a missingitkTestDriver, then run separately: the 44 ITKv3 registration example tests pass).pre-commit run --all-filespasses.ninja -k 0:Python.hnot found in the wrapping build (a testbed configuration problem), and TubeTK API errors that predate this change.GetNumberOfParameters()override.AI assistance
Claude Code (claude-opus-5-5) designed the additive API, implemented it, wrote the tests, and ran the downstream forest builds, under review by the author.