Skip to content

Commit

Permalink
feat(math): impl remove zeros for sparse univariate poly
Browse files Browse the repository at this point in the history
  • Loading branch information
batzor committed Jun 7, 2024
1 parent 78fd8bd commit 29ebb3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ class UnivariatePolynomialOp<UnivariateSparseCoefficients<F, MaxDegree>> {
}

c.coefficients_ = S(std::move(c_terms));
c.coefficients_.RemoveHighDegreeZeros();
c.coefficients_.RemoveZeros();
}

static void DoMul(const UnivariatePolynomial<S>& a,
Expand Down Expand Up @@ -861,7 +861,7 @@ class UnivariatePolynomialOp<UnivariateSparseCoefficients<F, MaxDegree>> {
}
pdqsort(c_terms.begin(), c_terms.end());
c.coefficients_ = S(std::move(c_terms));
c.coefficients_.RemoveHighDegreeZeros();
c.coefficients_.RemoveZeros();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ class UnivariateSparseCoefficients {
constexpr explicit UnivariateSparseCoefficients(
const std::vector<Term>& terms)
: terms_(terms) {
RemoveZeros();
CHECK_LE(Degree(), kMaxDegree);
RemoveHighDegreeZeros();
}
constexpr explicit UnivariateSparseCoefficients(std::vector<Term>&& terms)
: terms_(std::move(terms)) {
RemoveZeros();
CHECK_LE(Degree(), kMaxDegree);
RemoveHighDegreeZeros();
}

constexpr static UnivariateSparseCoefficients CreateChecked(
Expand Down Expand Up @@ -289,12 +289,12 @@ class UnivariateSparseCoefficients {
return &it->coefficient;
}

void RemoveHighDegreeZeros() { // Fix to RemoveZeros
while (!IsZero()) {
if (terms_.back().coefficient.IsZero()) {
terms_.pop_back();
void RemoveZeros() {
for (auto it = terms_.begin(); it != terms_.end(); ) {
if (it->coefficient.IsZero()) {
it = terms_.erase(it);
} else {
break;
++it;
}
}
}
Expand Down

0 comments on commit 29ebb3c

Please sign in to comment.