Skip to content

Commit 6e3cfbb

Browse files
committed
Fixes
1 parent 5b1d62b commit 6e3cfbb

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

cp-algo/math/fft.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ namespace cp_algo::math::fft {
247247
res[n + i] = B0 + B1 * split + B2 * splitsplit;
248248
});
249249
}
250-
void mul_inplace(auto &B, auto& res, size_t k) {
250+
void mul_inplace(auto &&B, auto& res, size_t k) {
251251
mul(B.A, B.B, res, k);
252252
}
253253
void mul(auto const& B, auto& res, size_t k) {

cp-algo/math/poly.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace cp_algo::math {
2626
poly_t(std::vector<T> const& t): a(t) {normalize();}
2727
poly_t(std::vector<T>&& t): a(std::move(t)) {normalize();}
2828

29-
poly_t operator -() const {return poly::impl::neg(*this);}
29+
poly_t operator -() const {return poly::impl::neg_inplace(poly_t(*this));}
3030
poly_t& operator += (poly_t const& t) {return poly::impl::add(*this, t);}
3131
poly_t& operator -= (poly_t const& t) {return poly::impl::sub(*this, t);}
3232
poly_t operator + (poly_t const& t) const {return poly_t(*this) += t;}
@@ -69,8 +69,10 @@ namespace cp_algo::math {
6969
poly_t operator * (T const& x) const {return poly_t(*this) *= x;}
7070
poly_t operator / (T const& x) const {return poly_t(*this) /= x;}
7171

72-
poly_t reverse(size_t n) const {return poly::impl::reverse(*this, n);}
73-
poly_t reverse() const {return reverse(size(a));}
72+
poly_t& reverse(size_t n) {return poly::impl::reverse(*this, n);}
73+
poly_t& reverse() {return reverse(size(a));}
74+
poly_t reversed(size_t n) {return poly_t(*this).reverse(n);}
75+
poly_t reversed() {return poly_t(*this).reverse();}
7476

7577
std::array<poly_t, 2> divmod(poly_t const& b) const {
7678
return poly::impl::divmod(*this, b);
@@ -433,7 +435,7 @@ namespace cp_algo::math {
433435
poly_t p_over_q = poly_t(y).chirpz(z, n);
434436
poly_t q = _1mzkx_prod(z, n);
435437

436-
return (p_over_q * q).mod_xk(n).reverse(n);
438+
return (p_over_q * q).mod_xk_inplace(n).reverse(n);
437439
}
438440

439441
static poly_t build(std::vector<poly_t> &res, int v, auto L, auto R) { // builds evaluation tree for (x-a1)(x-a2)...(x-an)
@@ -546,7 +548,7 @@ namespace cp_algo::math {
546548

547549
// [x^k] (a corr b) = sum_{i} a{(k-m)+i}*bi
548550
static poly_t corr(poly_t const& a, poly_t const& b) { // cross-correlation
549-
return a * b.reverse();
551+
return a * b.reversed();
550552
}
551553

552554
// [x^k] (a semicorr b) = sum_i a{i+k} * b{i}
@@ -609,11 +611,11 @@ namespace cp_algo::math {
609611
auto P0f = fft::dft<T>(P0.a, N);
610612
auto P1f = fft::dft<T>(P1.a, N);
611613

612-
Q = poly_t(Q0f * Q0f) - poly_t(Q1f * Q1f).mul_xk(1);
614+
Q = poly_t(Q0f * Q0f) -= poly_t(Q1f * Q1f).mul_xk_inplace(1);
613615
if(k % 2) {
614-
P = poly_t(Q0f *= P1f) - poly_t(Q1f *= P0f);
616+
P = poly_t(Q0f *= P1f) -= poly_t(Q1f *= P0f);
615617
} else {
616-
P = poly_t(Q0f *= P0f) - poly_t(Q1f *= P1f).mul_xk(1);
618+
P = poly_t(Q0f *= P0f) -= poly_t(Q1f *= P1f).mul_xk_inplace(1);
617619
}
618620
k /= 2;
619621
}

cp-algo/math/poly/impl/base.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace cp_algo::math::poly::impl {
1111
p.a.pop_back();
1212
}
1313
}
14-
auto neg(auto p) {
14+
auto& neg_inplace(auto &p) {
1515
std::ranges::transform(p.a, begin(p.a), std::negate{});
1616
return p;
1717
}
@@ -22,13 +22,13 @@ namespace cp_algo::math::poly::impl {
2222
p.normalize();
2323
return p;
2424
}
25-
auto& add(auto &p, auto q) {
25+
auto& add(auto &p, auto const& q) {
2626
p.a.resize(std::max(p.a.size(), q.a.size()));
2727
std::ranges::transform(p.a, q.a, begin(p.a), std::plus{});
2828
normalize(p);
2929
return p;
3030
}
31-
auto& sub(auto &p, auto q) {
31+
auto& sub(auto &p, auto const& q) {
3232
p.a.resize(std::max(p.a.size(), q.a.size()));
3333
std::ranges::transform(p.a, q.a, begin(p.a), std::minus{});
3434
normalize(p);
@@ -40,7 +40,7 @@ namespace cp_algo::math::poly::impl {
4040
begin(p.a) + std::min(l + k, p.a.size())
4141
);
4242
}
43-
auto reverse(auto p, size_t n) {
43+
auto& reverse(auto &p, size_t n) {
4444
p.a.resize(n);
4545
std::ranges::reverse(p.a);
4646
normalize(p);

0 commit comments

Comments
 (0)