Skip to content

Commit 3ea50d0

Browse files
committed
Improve exec_on_eval
1 parent 1694eb5 commit 3ea50d0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

cp-algo/math/cvector.hpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "../util/checkpoint.hpp"
66
#include "../util/big_alloc.hpp"
77
#include <ranges>
8+
#include <bit>
89

910
namespace stdx = std::experimental;
1011
namespace cp_algo::math::fft {
@@ -67,8 +68,19 @@ namespace cp_algo::math::fft {
6768
return polar(1., std::numbers::pi / (ftype)std::bit_floor(n) * (ftype)eval_arg(n));
6869
}
6970
}
71+
static constexpr std::array<point, 32> roots = []() {
72+
std::array<point, 32> res;
73+
for(size_t i = 2; i < 32; i++) {
74+
res[i] = polar(1., std::numbers::pi / (1ull << (i - 2)));
75+
}
76+
return res;
77+
}();
7078
static constexpr point root(size_t n) {
71-
return eval_point(n / 2);
79+
return roots[std::bit_width(n)];
80+
}
81+
template<int step>
82+
static void exec_on_eval(size_t n, size_t k, auto &&callback) {
83+
callback(k, root(4 * step * n) * eval_point(step * k));
7284
}
7385
template<int step>
7486
static void exec_on_evals(size_t n, auto &&callback) {
@@ -77,10 +89,6 @@ namespace cp_algo::math::fft {
7789
callback(i, factor * eval_point(step * i));
7890
}
7991
}
80-
template<int step>
81-
static void exec_on_eval(size_t n, size_t k, auto &&callback) {
82-
callback(root(4 * step * n) * eval_point(step * k));
83-
}
8492

8593
void dot(cvector const& t) {
8694
size_t n = this->size();

0 commit comments

Comments
 (0)