Skip to content

Commit a025ba0

Browse files
authored
Merge pull request InsightSoftwareConsortium#5252 from N-Dekker/Replace-pow-with-left-shift
STYLE: Replace `std::pow(2, dim)` calls with `1 << dim`
2 parents fa343ed + 2bd9f0a commit a025ba0

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

Modules/Core/Common/include/itkFloodFilledSpatialFunctionConditionalConstIterator.hxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ FloodFilledSpatialFunctionConditionalConstIterator<TImage, TFunction>::IsPixelIn
111111
// To reiterate... DO NOT use this on images higher than 16D
112112

113113
constexpr unsigned int dim = TImage::ImageDimension;
114-
auto numReps = static_cast<unsigned int>(std::pow(2.0, static_cast<double>(dim)));
114+
constexpr unsigned int numReps{ 1ULL << dim };
115115

116116

117117
// First we loop over the binary counter
@@ -154,8 +154,9 @@ FloodFilledSpatialFunctionConditionalConstIterator<TImage, TFunction>::IsPixelIn
154154

155155
// To reiterate... DO NOT use this on images higher than 16D
156156

157-
const unsigned int dim = TImage::ImageDimension;
158-
auto numReps = static_cast<unsigned int>(std::pow(2.0, static_cast<double>(dim)));
157+
constexpr unsigned int dim = TImage::ImageDimension;
158+
constexpr unsigned int numReps{ 1ULL << dim };
159+
159160
// First we loop over the binary counter
160161
for (unsigned int counter = 0; counter < numReps; ++counter)
161162
{

Modules/Filtering/AnisotropicSmoothing/include/itkAnisotropicDiffusionImageFilter.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AnisotropicDiffusionImageFilter<TInputImage, TOutputImage>::AnisotropicDiffusion
2929
m_ConductanceParameter = 1.0;
3030
m_ConductanceScalingParameter = 1.0;
3131
m_ConductanceScalingUpdateInterval = 1;
32-
m_TimeStep = 0.5 / std::pow(2.0, static_cast<double>(ImageDimension));
32+
m_TimeStep = 0.5 / double{ 1ULL << ImageDimension };
3333
m_FixedAverageGradientMagnitude = 1.0;
3434
m_GradientMagnitudeIsFixed = false;
3535
}
@@ -66,14 +66,14 @@ AnisotropicDiffusionImageFilter<TInputImage, TOutputImage>::InitializeIteration(
6666
{
6767
minSpacing = 1.0;
6868
}
69-
if (m_TimeStep > (minSpacing / std::pow(2.0, static_cast<double>(ImageDimension) + 1)))
69+
if (m_TimeStep > (minSpacing / double{ 1ULL << (ImageDimension + 1) }))
7070
{
7171
// f->SetTimeStep(1.0 / std::pow(2.0,
7272
// static_cast<double>(ImageDimension)));
7373
itkWarningMacro("Anisotropic diffusion unstable time step: "
7474
<< m_TimeStep << std::endl
7575
<< "Stable time step for this image must be smaller than "
76-
<< minSpacing / std::pow(2.0, static_cast<double>(ImageDimension + 1)));
76+
<< minSpacing / double{ 1ULL << (ImageDimension + 1) });
7777
}
7878

7979
if (m_GradientMagnitudeIsFixed == false)

Modules/Filtering/GPUAnisotropicSmoothing/include/itkGPUAnisotropicDiffusionImageFilter.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ GPUAnisotropicDiffusionImageFilter<TInputImage, TOutputImage, TParentImageFilter
5656
{
5757
minSpacing = 1.0;
5858
}
59-
if (this->GetTimeStep() > (minSpacing / std::pow(2.0, static_cast<double>(ImageDimension) + 1)))
59+
if (this->GetTimeStep() > (minSpacing / double{ 1ULL << (ImageDimension + 1) }))
6060
{
6161
// f->SetTimeStep(1.0 / std::pow(2.0,
6262
// static_cast<double>(ImageDimension)));
6363
itkWarningMacro("Anisotropic diffusion unstable time step: "
6464
<< this->GetTimeStep() << std::endl
6565
<< "Stable time step for this image must be smaller than "
66-
<< minSpacing / std::pow(2.0, static_cast<double>(ImageDimension + 1)));
66+
<< minSpacing / double{ 1ULL << (ImageDimension + 1) }));
6767
}
6868

6969
if (this->m_GradientMagnitudeIsFixed == false)

0 commit comments

Comments
 (0)