Skip to content

ENH: Print a warning for each unused parameter of the ParameterMap#1431

Merged
N-Dekker merged 1 commit into
mainfrom
Warn-for-unused-parameters
Apr 20, 2026
Merged

ENH: Print a warning for each unused parameter of the ParameterMap#1431
N-Dekker merged 1 commit into
mainfrom
Warn-for-unused-parameters

Conversation

@N-Dekker
Copy link
Copy Markdown
Member

Checks that all parameters in the ParameterMap are accessed.


Example output:

WARNING: 5 unused parameter(s) found!
  Unused parameter: AutomaticScalesEstimation
  Unused parameter: AutomaticTransformInitialization
  Unused parameter: AutomaticTransformInitializationMethod
  Unused parameter: Blablabla
  Unused parameter: ErodeMask

@mstaring @stefanklein This should ease finding mistakes in parameter maps that are edited by the user.

@stefanklein
Copy link
Copy Markdown
Member

stefanklein commented Apr 17, 2026 via email

Comment on lines +140 to +149
for (const auto & pair : m_ParameterMapInterface->GetParameterMap())
{
if (pair.first == parameterName)
{
// Conceptually, m_ParameterAccessFlags[i] is mutable.
m_ParameterAccessFlags[i] = true;
return;
}
++i;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Technically, this is O(n), rather than O(1), but I don't think it's worth optimizing the performance of AccessParameter(parameterName). It should not be called inside a performance critical loop anyway.

Comment thread Core/Configuration/elxConfiguration.h Outdated
const itk::ParameterMapInterface::Pointer m_ParameterMapInterface{ itk::ParameterMapInterface::New() };

// Tells for each parameter whether it is accessed.
std::unique_ptr<std::atomic_bool[]> m_ParameterAccessFlags;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Using std::atomic_bool instead of ordinary bool, because I guess these flags might be set concurrently by multiple threads.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Honestly I wonder if ParameterMap access really ever takes place concurrently (by multiple threads simultaneously). Otherwise the use of atomic_bool may be a bit overdone 🤷

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Update: Replaced atomic_bool with plain bool, as I think that's good enough.

@N-Dekker N-Dekker force-pushed the Warn-for-unused-parameters branch from c8512ea to 0df6c6c Compare April 17, 2026 13:14
Checks that all parameters in the ParameterMap are accessed.
@N-Dekker N-Dekker force-pushed the Warn-for-unused-parameters branch from 0df6c6c to 906c90c Compare April 20, 2026 11:49
@N-Dekker N-Dekker merged commit 0619985 into main Apr 20, 2026
8 checks passed
@N-Dekker N-Dekker deleted the Warn-for-unused-parameters branch April 20, 2026 15:32
@N-Dekker
Copy link
Copy Markdown
Member Author

For the record, this proposal was discussed in the most recent internal bi-weekly elastix and ITKElastix Zoom meetings.

N-Dekker added a commit to N-Dekker/ITKElastix that referenced this pull request May 15, 2026
Included elastix pull requests:

SuperElastix/elastix#1444
"Improve performance of Advanced, ParzenWindowHistogram,
ParzenWindowMutualInformation ImageToImageMetric"

SuperElastix/elastix#1440
"PERF: Use ImageBufferRange in AfterThreadedComputePDFs"

SuperElastix/elastix#1431
"ENH: Print a warning for each unused parameter of the ParameterMap"

All included new commits:

SuperElastix/elastix@5.3.1...77c726a
N-Dekker added a commit to N-Dekker/ITKElastix that referenced this pull request May 15, 2026
Included elastix pull requests:

SuperElastix/elastix#1444
"Improve performance of Advanced, ParzenWindowHistogram,
ParzenWindowMutualInformation ImageToImageMetric"

SuperElastix/elastix#1440
"PERF: Use ImageBufferRange in AfterThreadedComputePDFs"

SuperElastix/elastix#1431
"ENH: Print a warning for each unused parameter of the ParameterMap"

All included new commits:

SuperElastix/elastix@5.3.1...77c726a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants