Skip to content

STYLE: Use generate in tests, assigning values from vnl_sample_uniform - #5608

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
N-Dekker:Use-generate-for-vnl_sample_uniform
Nov 7, 2025
Merged

STYLE: Use generate in tests, assigning values from vnl_sample_uniform#5608
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
N-Dekker:Use-generate-for-vnl_sample_uniform

Conversation

@N-Dekker

@N-Dekker N-Dekker commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Did find code like:

v[0] = static_cast<T>(vnl_sample_uniform(a, b));
v[1] = static_cast<T>(vnl_sample_uniform(a, b));
v[2] = static_cast<T>(vnl_sample_uniform(a, b));

And replaced it with the equivalent std::generate call:

std::generate(v.begin(), v.end(), [] {
  return static_cast<T>(vnl_sample_uniform(a, b));
});

Aims to reduce code redundancy.


Motivation: in a follow-up I would like those vnl_sample_uniform calls to be replaced with modern C++ random number generation. This pull request should pave the way.

Did find code like:

    v[0] = static_cast<T>(vnl_sample_uniform(a, b));
    v[1] = static_cast<T>(vnl_sample_uniform(a, b));
    v[2] = static_cast<T>(vnl_sample_uniform(a, b));

And replaced it with the equivalent `std::generate` call:

    std::generate(v.begin(), v.end(), [] {
      return static_cast<T>(vnl_sample_uniform(a, b));
    });

Aims to reduce code redundancy.
@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:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:Segmentation Issues affecting the Segmentation module type:Style Style changes: no logic impact (indentation, comments, naming) labels Nov 7, 2025
@N-Dekker
N-Dekker marked this pull request as ready for review November 7, 2025 15:26
@hjmjohnson

Copy link
Copy Markdown
Member

@N-Dekker It would be good to start deprecating the exposure of vnl capabilities when better alternatives exist.

@hjmjohnson
hjmjohnson merged commit 126cc5a into InsightSoftwareConsortium:main Nov 7, 2025
17 checks passed
@N-Dekker

N-Dekker commented Nov 8, 2025

Copy link
Copy Markdown
Contributor Author

@N-Dekker It would be good to start deprecating the exposure of vnl capabilities when better alternatives exist.

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:Segmentation Issues affecting the Segmentation 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