[mathicgb] 382/393: It is no longer possible to ask for the i'th term/coef/mono of a polynomial.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:37 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.
commit 6124dafb5526b10561b4572e4be2bda269e1a1cd
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Mon Sep 23 13:16:38 2013 +0200
It is no longer possible to ask for the i'th term/coef/mono of a polynomial.
---
src/mathicgb.cpp | 52 ++++++++++++++++++++++++++++++++++++++-------------
src/mathicgb.h | 11 ++++++++---
src/mathicgb/Poly.hpp | 17 -----------------
3 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/src/mathicgb.cpp b/src/mathicgb.cpp
index 1566885..c59a16e 100755
--- a/src/mathicgb.cpp
+++ b/src/mathicgb.cpp
@@ -774,13 +774,15 @@ namespace mgbi {
// ** Implementation of mgbi::IdealAdapter
namespace mgbi {
struct IdealAdapter::Pimpl {
+ Pimpl(): polyIndex(0), mTermIt() {}
+
std::unique_ptr<Basis> basis;
std::unique_ptr<Exponent[]> tmpTerm;
+ size_t polyIndex;
+ Poly::ConstTermIterator mTermIt;
};
- IdealAdapter::IdealAdapter():
- mPimpl(new Pimpl()) {
- }
+ IdealAdapter::IdealAdapter(): mPimpl(new Pimpl()) {}
IdealAdapter::~IdealAdapter() {
MATHICGB_ASSERT(mPimpl != 0);
@@ -803,23 +805,47 @@ namespace mgbi {
return mPimpl->basis->getPoly(poly)->termCount();
}
- auto IdealAdapter::term(
- PolyIndex poly,
- TermIndex term
- ) const -> std::pair<Coefficient, const Exponent*> {
+ void IdealAdapter::toFirstTerm() {
+ mPimpl->polyIndex = 0;
+ while (
+ mPimpl->polyIndex < mPimpl->basis->size() &&
+ mPimpl->basis->getPoly(mPimpl->polyIndex)->isZero()
+ )
+ ++(mPimpl->polyIndex);
+
+ if (mPimpl->polyIndex < mPimpl->basis->size())
+ mPimpl->mTermIt = mPimpl->basis->getPoly(mPimpl->polyIndex)->begin();
+ }
+
+ auto IdealAdapter::nextTerm() const
+ -> std::pair<Coefficient, const Exponent*>
+ {
MATHICGB_ASSERT(mPimpl->basis.get() != 0);
- MATHICGB_ASSERT(poly < mPimpl->basis->size());
+ MATHICGB_ASSERT(mPimpl->polyIndex < mPimpl->basis->size());
const auto& monoid = mPimpl->basis->ring().monoid();
- const auto& p = *mPimpl->basis->getPoly(poly);
- MATHICGB_ASSERT(term < p.termCount());
+ const auto& p = *mPimpl->basis->getPoly(mPimpl->polyIndex);
MATHICGB_ASSERT(p.ring().monoid() == monoid);
- const auto& from = p.mono(term);
+ const auto& from = *mPimpl->mTermIt;
auto to = mPimpl->tmpTerm.get();
for (VarIndex var = 0; var < monoid.varCount(); ++var)
- to[var] = monoid.externalExponent(from, var);
- return std::make_pair(p.coef(term), to);
+ to[var] = monoid.externalExponent(*from.mono, var);
+
+ ++(mPimpl->mTermIt);
+ if (mPimpl->mTermIt == p.end()) {
+ ++mPimpl->polyIndex;
+ while (
+ mPimpl->polyIndex < mPimpl->basis->size() &&
+ mPimpl->basis->getPoly(mPimpl->polyIndex)->isZero()
+ )
+ ++(mPimpl->polyIndex);
+
+ if (mPimpl->polyIndex < mPimpl->basis->size())
+ mPimpl->mTermIt = mPimpl->basis->getPoly(mPimpl->polyIndex)->begin();
+ }
+
+ return std::make_pair(from.coef, to);
}
}
diff --git a/src/mathicgb.h b/src/mathicgb.h
index 3f78ade..b889688 100755
--- a/src/mathicgb.h
+++ b/src/mathicgb.h
@@ -789,8 +789,12 @@ namespace mgb {
size_t polyCount() const;
size_t termCount(PolyIndex poly) const;
- // Return value only valid until the next call to term.
- ConstTerm term(PolyIndex poly, TermIndex term) const;
+ /// Sets the internal position to the first term of the first polynomial.
+ void toFirstTerm();
+
+ /// Returns the next term. First all terms of polynomial 0 are returned,
+ /// then all terms of the next polynomial and so on.
+ ConstTerm nextTerm() const;
private:
friend class mgbi::PimplOf;
@@ -816,6 +820,7 @@ namespace mgb {
if (!doOutput)
return;
+ ideal.toFirstTerm();
const size_t varCount = ideal.varCount();
const size_t polyCount = ideal.polyCount();
output.idealBegin(polyCount);
@@ -824,7 +829,7 @@ namespace mgb {
output.appendPolynomialBegin(termCount);
for (size_t termIndex = 0; termIndex < termCount; ++termIndex) {
output.appendTermBegin();
- const ConstTerm term = ideal.term(polyIndex, termIndex);
+ const ConstTerm term = ideal.nextTerm();
for (size_t var = 0; var < varCount; ++var)
output.appendExponent(var, term.second[var]);
output.appendTermDone(term.first);
diff --git a/src/mathicgb/Poly.hpp b/src/mathicgb/Poly.hpp
index 2b19cb5..3320788 100755
--- a/src/mathicgb/Poly.hpp
+++ b/src/mathicgb/Poly.hpp
@@ -115,12 +115,6 @@ public:
// *** Accessing the coefficients of the terms in the polynomial.
- /// Returns the coefficient of the given term.
- const Coef& coef(size_t index) const {
- MATHICGB_ASSERT(index < termCount());
- return mCoefs[index];
- }
-
/// Returns the coefficient of the leading term.
const Coef& leadCoef() const {
MATHICGB_ASSERT(!isZero());
@@ -149,12 +143,6 @@ public:
// *** Accessing the monomials of the terms in the polynomial
- /// Returns the monomial of the given term.
- ConstMonoRef mono(size_t index) const {
- MATHICGB_ASSERT(index < termCount());
- return Monoid::toRef(&mMonos[index * monoid().entryCount()]);
- }
-
/// Returns the monomial of the leading term.
ConstMonoRef leadMono() const {
MATHICGB_ASSERT(!isZero());
@@ -256,11 +244,6 @@ public:
Iterator mIt;
};
- NewConstTerm term(size_t index) const {
- NewConstTerm t = {coef(index), mono(index).ptr()};
- return t;
- }
-
typedef Range<ConstTermIterator> ConstTermIteratorRange;
ConstTermIterator begin() const {return makeZip(coefBegin(), monoBegin());}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git
More information about the debian-science-commits
mailing list