isce3 0.25.0
Loading...
Searching...
No Matches
FFTUtil.icc
1#ifndef ISCE_FFT_FFTUTIL_ICC
2#error "FFTUtil.icc is an implementation detail of FFTUtil.h"
3#endif
4
5#include <cmath>
6
7namespace isce3 { namespace fft {
8
9template<typename T, typename std::enable_if<std::is_integral<T>::value>::type *>
10inline
11T nextPowerOfTwo(T n)
12{
13 if (n < 0) {
14 throw isce3::except::DomainError(ISCE_SRCINFO(), "input must be non-negative");
15 }
16
17 if (n <= 1) {
18 return 1;
19 }
20
21 T res = 2;
22 --n;
23 while (n >>= 1) {
24 res <<= 1;
25 }
26
27 return res;
28}
29
30inline std::int32_t intpow(std::int32_t base, std::int32_t exponent)
31{
32 std::int32_t x = 1;
33 for (std::int32_t i = 0; i < exponent; ++i) {
34 x *= base;
35 }
36 return x;
37}
38
39// compute smallest m = 2^a * 3^b * 5^c >= n
40inline std::int32_t nextFastPower(std::int32_t n)
41{
42 if (n < 0) {
43 throw isce3::except::DomainError(ISCE_SRCINFO(), "input must be non-negative");
44 }
45 if (n <= 1) {
46 return 1;
47 }
48
49 // Upper bound on each exponent happens when the others are zero, e.g.,
50 // 3^max3 >= n and 5^max5 >= n
51 // which is easy to compute with logarithms.
52 double logn = std::log(n);
53 std::int32_t max5 = std::ceil(logn / std::log(5));
54 std::int32_t max3 = std::ceil(logn / std::log(3));
55 std::int32_t mmin = INT32_MAX;
56 for (std::int32_t x5 = 0; x5 <= max5; ++x5) {
57 std::int32_t n5 = intpow(5, x5);
58 for (std::int32_t x3 = 0; x3 <= max3; ++x3) {
59
60 // Promote type since worst case m is roughly 15 * n^2, so we need
61 // double the bits of n.
62 std::int64_t m = static_cast<std::int64_t>(n5) * intpow(3, x3);
63
64 // Go the rest of the way with factors of two.
65 while (m < n) {
66 m *= 2;
67 }
68 if (m < mmin) {
69 mmin = static_cast<std::int32_t>(m);
70 }
71 }
72 }
73 return mmin;
74}
75
76}}
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5

Generated for ISCE3.0 by doxygen 1.13.2.