generated from Tiphereth-A/TINplate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67dbfee
commit 0a0587a
Showing
53 changed files
with
380 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef TIFALIBS_CONV_CONV_NAIVE_MOD | ||
#define TIFALIBS_CONV_CONV_NAIVE_MOD | ||
|
||
#include "../math/mul_mod.hpp" | ||
|
||
namespace tifa_libs::math { | ||
|
||
CEXP inline u32 CONV_NAIVE_MOD_THRESHOLD = 16; | ||
CEXP vecuu conv_naive_mod(spnuu l, spnuu r, u64 mod, u32 ans_size = 0) NE { | ||
if (l.empty() || r.empty()) return {}; | ||
if (!ans_size) ans_size = u32(l.size() + r.size() - 1); | ||
vecuu ans(ans_size); | ||
u32 n = (u32)l.size(), m = (u32)r.size(); | ||
auto &&l_ = n < m ? r : l, &&r_ = n < m ? l : r; | ||
if (n < m) swap(n, m); | ||
flt_ (u32, i, 0, n) | ||
flt_ (u32, j, 0, min(m, ans_size - i)) ans[i + j] += mul_mod_u(l_[i], r_[j], mod); | ||
for (auto &i : ans) i %= mod; | ||
return ans; | ||
} | ||
|
||
} // namespace tifa_libs::math | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef TIFALIBS_CONV_CONV_u64 | ||
#define TIFALIBS_CONV_CONV_u64 | ||
|
||
#include "conv_naive.hpp" | ||
#include "fft_r3.hpp" | ||
|
||
namespace tifa_libs::math { | ||
|
||
template <class T> | ||
vecuu conv_u64(vec<T> CR a, vec<T> CR b, u32 ans_size = 0) NE { | ||
const u32 n = (u32)a.size(), m = (u32)b.size(); | ||
if (!ans_size) ans_size = n + m - 1; | ||
if (a.empty() && b.empty()) return {}; | ||
if (min(n, m) < CONV_NAIVE_THRESHOLD) return conv_naive<T, u64>(a, b, ans_size); | ||
static FFT_R3<T> fft; | ||
using EI = FFT_R3<T>::data_t; | ||
CEXP static EI inv_3{-T(1) / 3 * 2 + 1, 0}; | ||
fft.bzr(n + m - 1); | ||
u32 s = fft.size(); | ||
vec<EI> pa(s), pb(s); | ||
for (u32 i = 0; i < std::min(s, n); ++i) pa[i].real(a[i]); | ||
for (u32 i = s; i < std::min(2 * s, n); ++i) pa[i - s].imag(a[i]); | ||
for (u32 i = 0; i < std::min(s, m); ++i) pb[i].real(b[i]); | ||
for (u32 i = s; i < std::min(2 * s, m); ++i) pb[i - s].imag(b[i]); | ||
vec<EI> pc(4 * s); | ||
auto mul = [](auto&& mul, EI* p, EI* q, EI* to, u32 n) { | ||
if (n <= 27) { | ||
std::fill_n(to, n, 0); | ||
flt_ (u32, i, 0, n) { | ||
flt_ (u32, j, 0, n - i) to[i + j] += p[i] * q[j]; | ||
flt_ (u32, j, n - i, n) to[i + j - n] += p[i] * q[j] * EI::w; | ||
} | ||
return; | ||
} | ||
u32 m = 1; | ||
for (; m * m < n; m *= 3); | ||
u32 r = n / m; | ||
EI inv{1}; | ||
for (u32 i = 1; i < r; i *= 3) inv *= inv_3; | ||
flt_ (u32, i, 0, r) { | ||
fft.twiddle(p + m * i, m, m / r * i, to + m * i); | ||
fft.twiddle(q + m * i, m, m / r * i, to + n + m * i); | ||
} | ||
fft.dif(to, m, r), fft.dif(to + n, m, r); | ||
flt_ (u32, i, 0, r) mul(mul, to + m * i, to + n + m * i, to + 2 * n + m * i, m); | ||
fft.dit(to + 2 * n, m, r); | ||
flt_ (u32, i, 0, n) to[2 * n + i] *= inv; | ||
flt_ (u32, i, 0, r) fft.twiddle(to + 2 * n + m * i, m, 3 * m - m / r * i, to + n + m * i); | ||
flt_ (u32, i, 0, r) { | ||
flt_ (u32, j, 0, m) p[m * i + j] = conj(p[m * i + j]), q[m * i + j] = conj(q[m * i + j]); | ||
fft.twiddle(p + m * i, m, 2 * m / r * i, to + m * i); | ||
fft.twiddle(q + m * i, m, 2 * m / r * i, p + m * i); | ||
} | ||
fft.dif(to, m, r), fft.dif(p, m, r); | ||
flt_ (u32, i, 0, r) mul(mul, to + m * i, p + m * i, to + 2 * n + m * i, m); | ||
fft.dit(to + 2 * n, m, r); | ||
flt_ (u32, i, 0, n) to[2 * n + i] *= inv; | ||
flt_ (u32, i, 0, r) fft.twiddle(to + 2 * n + m * i, m, 3 * m - 2 * m / r * i, q + m * i); | ||
std::fill_n(to, n, 0); | ||
flt_ (u32, i, 0, n) { | ||
to[i] += (1 - EI::w) * to[n + i] + (1 - EI::w2) * conj(q[i]); | ||
if (i + m < n) to[i + m] += (EI::w2 - EI::w) * (to[n + i] - conj(q[i])); | ||
else to[i + m - n] += (1 - EI::w2) * (to[n + i] - conj(q[i])); | ||
} | ||
flt_ (u32, i, 0, n) to[i] *= inv_3; | ||
}; | ||
mul(mul, pa.data(), pb.data(), pc.data(), s); | ||
vec<T> ans(ans_size); | ||
flt_ (u32, i, 0, std::min(s, ans_size)) ans[i] = pc[i].real(); | ||
flt_ (u32, i, s, std::min(2 * s, ans_size)) ans[i] = pc[i - s].imag(); | ||
return ans; | ||
} | ||
|
||
} // namespace tifa_libs::math | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef TIFALIBS_CONV_CONVCYC_NAIVE | ||
#define TIFALIBS_CONV_CONVCYC_NAIVE | ||
|
||
#include "../util/util.hpp" | ||
|
||
namespace tifa_libs::math { | ||
|
||
template <class U, class T = U> | ||
requires(sizeof(U) <= sizeof(T)) | ||
CEXP vec<T> convcyc_naive(vec<U> CR l, vec<U> CR r) NE { | ||
if (l.empty() || r.empty()) return {}; | ||
assert(l.size() == r.size()); | ||
const u32 n = (u32)l.size(); | ||
vec<T> ans(n); | ||
flt_ (u32, i, 0, n) { | ||
flt_ (u32, j, 0, n - i) ans[i + j] += (T)l[i] * (T)r[j]; | ||
flt_ (u32, j, n - i, n) ans[i + j - n] += (T)l[i] * (T)r[j]; | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
} // namespace tifa_libs::math | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.