Skip to content

Commit f9bb12b

Browse files
committed
improve convolution normalization
1 parent 115e8fc commit f9bb12b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

hydra/Convolution.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <hydra/detail/Convolution.inl>
4242
#include <hydra/detail/ArgumentTraits.h>
4343
#include <hydra/detail/external/hydra_thrust/transform.h>
44+
#include <hydra/detail/external/hydra_thrust/reduce.h>
4445
#include <hydra/detail/external/hydra_thrust/iterator/transform_iterator.h>
4546
#include <hydra/detail/external/hydra_thrust/memory.h>
4647
#include <hydra/detail/external/hydra_thrust/system/cuda/detail/execution_policy.h>
@@ -93,6 +94,8 @@ convolute(detail::BackendPolicy<BACKEND> policy, detail::FFTPolicy<T, FFTBackend
9394
hydra_thrust::transform(policy, counting_samples.begin(), counting_samples.end(),
9495
kernel_samples.first , kernel_sampler);
9596

97+
auto norm_factor = hydra_thrust::reduce(policy, kernel_samples.first, kernel_samples.first + kernel_samples.second );
98+
9699
// sample function
97100
auto functor_sampler = hydra::detail::convolution::FunctorSampler<Functor>(functor, nsamples, min, delta);
98101

@@ -135,12 +138,12 @@ convolute(detail::BackendPolicy<BACKEND> policy, detail::FFTPolicy<T, FFTBackend
135138

136139
auto fft_product_output = fft_product.GetOutputData();
137140

138-
T n = ::pow(10.0, (long unsigned)::log10((double)nsamples*nsamples ));
141+
T n = 2*nsamples*norm_factor;
139142

140143
auto normalize_fft = detail::convolution::NormalizeFFT<T>(n);
141144

142145
auto first = hydra_thrust::make_transform_iterator( fft_product_output.first,normalize_fft);
143-
auto last = hydra_thrust::make_transform_iterator(fft_product_output.first + nsamples,normalize_fft);
146+
auto last = hydra_thrust::make_transform_iterator(fft_product_output.first + nsamples+1,normalize_fft);
144147

145148
auto fft_product_range = make_range(first, last);
146149

0 commit comments

Comments
 (0)