Skip to content

STYLE: Replace declare-then-Fill(N) with ::Filled(N) factory method#6010

Merged
hjmjohnson merged 2 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:style-sizetype-filled
Apr 5, 2026
Merged

STYLE: Replace declare-then-Fill(N) with ::Filled(N) factory method#6010
hjmjohnson merged 2 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:style-sizetype-filled

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

Summary

Replaces the verbose two-line FixedArray initialization pattern with the modern single-line static factory method ::Filled(v).

Before:

ImageType::SizeType size;
size.Fill(16);

After:

constexpr auto size = ImageType::SizeType::Filled(16);

Rules applied

  • constexpr auto used when the variable is never subsequently modified (test files with concrete types)
  • auto (without constexpr) used for accumulator variables in loop bodies (.hxx template implementations)
  • Skipped: cases where Fill() is immediately followed by element-wise overrides (size[0] = w), or where typename disambiguation in deeply nested template parameter scopes makes the replacement non-trivial

Files changed

File Pattern
Modules/IO/NRRD/test/itkNrrdLocaleTest.cxx SizeType + IndexTypeconstexpr auto
Modules/Video/BridgeOpenCV/test/itkOpenCVVideoIOTest.cxx PointTypeconstexpr auto
Modules/Filtering/Path/include/itkChainCodeToFourierSeriesPathFilter.hxx VectorType accumulators → auto
Modules/Filtering/QuadEdgeMeshFiltering/include/itkSmoothingQuadEdgeMeshFilter.hxx VectorType accumulator → auto

Pure style change — no semantic changes.

Suggested by @N-Dekker in #6003 (comment)

@github-actions github-actions bot added type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Video Issues affecting the Video module type:Style Style changes: no logic impact (indentation, comments, naming) labels Apr 3, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR applies a consistent style modernization across 52 files, replacing the two-line T var; var.Fill(N) initialization pattern with either auto var = itk::MakeFilled<T>(N) for non-zero fills or T var{} for zero fills. All replacements are semantically equivalent — itk::MakeFilled is the correct ITK factory for non-zero construction, and {} value-initialization of FixedArray correctly zeroes its underlying C-array data member because FixedArray's default constructor is = default, causing value-init to zero every element.

Confidence Score: 5/5

Pure style change — all replacements are semantically equivalent and safe to merge

All 52 files apply only mechanical, semantics-preserving substitutions. {} on FixedArray correctly zero-initializes via value-init of its C-array member, and itk::MakeFilled is the intended ITK API for filled construction. No logic paths, data flows, or interfaces are altered.

No files require special attention

Important Files Changed

Filename Overview
Modules/Core/ImageFunction/include/itkGaussianInterpolateImageFunction.hxx Replaces three Fill(0.0) calls with {} value-initialization on FixedArray accumulators — semantically equivalent since FixedArray's defaulted constructor value-initializes its C-array to zero
Modules/Registration/Common/include/itkLandmarkBasedTransformInitializer.hxx Replaces Fill(0.0) with {} on VectorType accumulators at three sites — correct zero-initialization
Modules/Filtering/Path/include/itkFourierSeriesPath.hxx Replaces output.Fill(0) with output{} in Evaluate and EvaluateDerivative — correct zero-initialization of path outputs
Modules/Filtering/Path/include/itkChainCodeToFourierSeriesPathFilter.hxx Replaces Fill(0.0) with {} on cosCoefficient/sinCoefficient VectorType accumulators inside the harmonic loop
Modules/Filtering/QuadEdgeMeshFiltering/include/itkSmoothingQuadEdgeMeshFilter.hxx Replaces Fill(0) with {} on VectorType accumulator in GenerateData
Modules/Segmentation/KLMRegionGrowing/include/itkKLMRegionGrowImageFilter.hxx Replaces Fill(0) with {} on index accumulators inside InitializeKLM loop — correct zero-initialization
Modules/Video/Core/include/itkVideoStream.h Replaces start.Fill(0) with start{} in header example code
Modules/Core/Common/test/itkBSplineInterpolationWeightFunctionTest.cxx Replaces ContinuousIndexType declare+Fill(4.15) with itk::MakeFilled
Modules/Filtering/ImageGrid/test/itkBSplineControlPointImageFunctionTest.cxx Mixed: size/spacing use MakeFilled, index/origin use {}; subsequent .Fill() calls on the same mutable auto variables at lines 53-65 remain valid
Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest3.cxx Consolidates size declaration to itk::MakeFilled with the computed value inline
Modules/Registration/RegistrationMethodsv4/test/itkTimeVaryingBSplineVelocityFieldPointSetRegistrationTest.cxx Replaces multiple declare+Fill patterns for domain/velocity field parameters with MakeFilled and {} initialization
Modules/Registration/Common/test/itkMultiResolutionPyramidImageFilterTest.cxx Replaces Vector declare+Fill with itk::MakeFilled using the computed shift value inline

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["T var (uninitialized)"] --> B["var.Fill(N) — explicit init"]
    C["auto var = itk::MakeFilled&lt;T&gt;(N)"] --> D["var initialized to N at construction"]
    E["T var{}"] --> F["var zero-initialized at construction"]
    A -. "replaced by (non-zero N)" .-> C
    A -. "replaced by (zero N)" .-> E
    B -. removed .-> C
    B -. removed .-> E
    style A fill:#f9f,stroke:#333
    style B fill:#f9f,stroke:#333
    style C fill:#9f9,stroke:#333
    style D fill:#9f9,stroke:#333
    style E fill:#9f9,stroke:#333
    style F fill:#9f9,stroke:#333
Loading

Reviews (2): Last reviewed commit: "STYLE: Use {}-initialization for zero-fi..." | Re-trigger Greptile

@hjmjohnson hjmjohnson requested a review from N-Dekker April 3, 2026 16:39
Copy link
Copy Markdown
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

Possibly squash commits. Good even as-is.

hjmjohnson and others added 2 commits April 4, 2026 11:28
Using find_declare_then_init.py --pattern fill_nonzero, replaced the
two-line pattern:

  Type var;
  var.Fill(N);

with the single-line form:

  auto var = itk::MakeFilled<Type>(N);    // test files
  auto var = MakeFilled<Type>(N);         // .hxx (already in itk::)

across 44 files in Modules/ (excluding Remote/, BridgeOpenCV, BridgeVXL,
and itkVectorMeanImageFunction.hxx which uses VariableLengthVector).

Follow-up to commit 6cb6bf9 by N-Dekker
"STYLE: Replace `T var; var.Fill(x)` with `auto var = MakeFilled<T>(x)`"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Using find_declare_then_init.py --pattern fill_zero, replaced the
two-line pattern:

  Type var;
  var.Fill(0);

with the single-line value-initialization:

  Type var{};

{}-initialization zero-initializes all elements for FixedArray and its
subclasses (IndexType, SizeType, SpacingType, PointType, VectorType,
etc.), which is the canonical C++ idiom for zero-initialization and
preserves the correct derived type (unlike ::Filled(0) which returns
the base class).

Applies to 25 files in Modules/ (excluding Remote/, BridgeOpenCV,
BridgeVXL).

Follow-up to commit 427df79 by hjmjohnson
"STYLE: Use {}-initialization for zero-filled FixedArray-derived types"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hjmjohnson
Copy link
Copy Markdown
Member Author

Thanks @dzenanz I am doing a more complete review and making a more extensive addresing of this style of fix. I'm moving it to a draft until I determine if the a more complete solution can be found.

@hjmjohnson hjmjohnson marked this pull request as draft April 4, 2026 16:31
@hjmjohnson hjmjohnson force-pushed the style-sizetype-filled branch from 427df79 to 787267e Compare April 4, 2026 16:42
@github-actions github-actions bot added area:Core Issues affecting the Core module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Numerics Issues affecting the Numerics module labels Apr 4, 2026
@hjmjohnson
Copy link
Copy Markdown
Member Author

ARMBUILD-Python failure analysis

The ARMBUILD-Python failure in run 23983133045 is not caused by this PR and is not a disk space issue.

Root cause: clang++: error: unable to execute command: Abort trap: 6 — a SIGABRT during SWIG Python wrapper compilation on the macos-15-arm64 runner.

Evidence:

  • The crash occurred during the build phase, not testing — 2623 of 2860 tests were "Not Run"
  • This PR only modifies C++ .hxx headers and test .cxx files — no Python wrapping code is touched
  • The same ARMBUILD-Python job passes on main (commit b94cca5)
  • Abort trap: 6 on macOS clang during SWIG compilation is characteristic of an out-of-memory condition — the macos-15-arm64 GitHub runner has 7 GB RAM, and SWIG-generated translation units can exceed this during compilation

Likely cause: Transient OOM on the ARM64 runner due to concurrent memory pressure. A re-run should resolve it.

@hjmjohnson hjmjohnson marked this pull request as ready for review April 5, 2026 12:53
@hjmjohnson hjmjohnson merged commit d1b4174 into InsightSoftwareConsortium:main Apr 5, 2026
16 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Numerics Issues affecting the Numerics module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Video Issues affecting the Video module type:Style Style changes: no logic impact (indentation, comments, naming) type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants