[mathicgb] 238/393: The library interface now allows not specifying the number of polynomials or terms to follow.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:10 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 c5ee21cff6f9ed1384b64f6098a1cd3f68f2d60a
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Thu Apr 11 23:58:38 2013 -0400

    The library interface now allows not specifying the number of polynomials or terms to follow.
---
 src/mathicgb.cpp      | 69 ++++++++++++++++++++++++++++++++++++++++++++-------
 src/mathicgb.h        | 36 +++++++++++++++++++++++++++
 src/test/mathicgb.cpp | 12 +++++----
 3 files changed, 103 insertions(+), 14 deletions(-)

diff --git a/src/mathicgb.cpp b/src/mathicgb.cpp
index 6a00550..6f28e6c 100755
--- a/src/mathicgb.cpp
+++ b/src/mathicgb.cpp
@@ -50,10 +50,16 @@ namespace mgbi {
       modulus(modulus),
       varCount(varCount),
       state(Initial),
+
+      hasClaimedPolyCount(false),
       claimedPolyCount(0),
       seenPolyCount(0),
+
+      hasClaimedTermCount(false),
       claimedTermCount(0),
-      seenTermCount(0)
+      seenTermCount(0),
+
+      lastVar(0)
     {}
 
     bool debugAssertValid() const;
@@ -70,10 +76,15 @@ namespace mgbi {
     const VarIndex varCount;
 
     State state;
+
+    bool hasClaimedPolyCount;
     size_t claimedPolyCount;
     size_t seenPolyCount;
+
+    bool hasClaimedTermCount;
     size_t claimedTermCount;
     size_t seenTermCount;
+
     VarIndex lastVar;
   };
 
@@ -112,7 +123,7 @@ namespace mgbi {
     delete mPimpl;
   }
 
-  void StreamStateChecker::idealBegin(size_t polyCount) {
+  void StreamStateChecker::idealBegin() {
     MATHICGB_ASSERT(mPimpl->debugAssertValid());
 
     MATHICGB_STREAM_CHECK(
@@ -121,13 +132,23 @@ namespace mgbi {
       "without an intervening call to idealDone()."
     );
     mPimpl->state = Pimpl::MakingIdeal;
+    mPimpl->hasClaimedPolyCount = false;
+    mPimpl->claimedPolyCount = 0;
+    mPimpl->seenPolyCount = 0;
+
+    MATHICGB_ASSERT(mPimpl->debugAssertValid());
+  }
+
+  void StreamStateChecker::idealBegin(size_t polyCount) {
+    idealBegin();
+    mPimpl->hasClaimedPolyCount = true;
     mPimpl->claimedPolyCount = polyCount;
     mPimpl->seenPolyCount = 0;
 
     MATHICGB_ASSERT(mPimpl->debugAssertValid());
   }
 
-  void StreamStateChecker::appendPolynomialBegin(size_t termCount) {
+  void StreamStateChecker::appendPolynomialBegin() {
     MATHICGB_ASSERT(mPimpl->debugAssertValid());
 
     MATHICGB_STREAM_CHECK(
@@ -137,16 +158,27 @@ namespace mgbi {
     );
     MATHICGB_STREAM_CHECK(
       mPimpl->state == Pimpl::MakingIdeal,
-     "appendPolynomialBegin() must not be called twice without "
-     "an intervening call to appendPolynomialDone()."
+      "appendPolynomialBegin() must not be called twice without "
+      "an intervening call to appendPolynomialDone()."
     );
     MATHICGB_STREAM_CHECK(
-      mPimpl->seenPolyCount < mPimpl->claimedPolyCount,
+      !mPimpl->hasClaimedPolyCount ||
+        mPimpl->seenPolyCount < mPimpl->claimedPolyCount,
       "The number of polynomials in an ideal must not exceed the amount "
       "passed to idealBegin()."
     );
     mPimpl->state = Pimpl::MakingPoly;
     mPimpl->seenPolyCount += 1;
+    mPimpl->hasClaimedTermCount = false;
+    mPimpl->claimedTermCount = 0;
+    mPimpl->seenTermCount = 0;
+
+    MATHICGB_ASSERT(mPimpl->debugAssertValid());
+  }
+
+  void StreamStateChecker::appendPolynomialBegin(size_t termCount) {
+    appendPolynomialBegin();
+    mPimpl->hasClaimedTermCount = true;
     mPimpl->claimedTermCount = termCount;
     mPimpl->seenTermCount = 0;
 
@@ -169,7 +201,8 @@ namespace mgbi {
       "call to appendTermDone()."
     );
     MATHICGB_STREAM_CHECK(
-      mPimpl->seenTermCount < mPimpl->claimedTermCount,
+      !mPimpl->hasClaimedTermCount ||
+        mPimpl->seenTermCount < mPimpl->claimedTermCount,
       "The number of terms in a polynomial must not exceed the amount "
       "passed to appendPolynomialBegin()."
     );
@@ -236,7 +269,8 @@ namespace mgbi {
       "appendPolynomialDone() must only be called after appendPolynomialBegin()."
     );
     MATHICGB_STREAM_CHECK(
-      mPimpl->seenTermCount == mPimpl->claimedTermCount,
+      !mPimpl->hasClaimedTermCount ||
+        mPimpl->seenTermCount == mPimpl->claimedTermCount,
       "The number of terms in a polynomial must match the amount "
       "passed to appendPolynomialBegin()."
     );
@@ -253,7 +287,8 @@ namespace mgbi {
       "idealDone() must only be called after idealBegin()."
     );
     MATHICGB_STREAM_CHECK(
-      mPimpl->seenPolyCount == mPimpl->claimedPolyCount,
+      !mPimpl->hasClaimedPolyCount ||
+        mPimpl->seenPolyCount == mPimpl->claimedPolyCount,
       "The number of polynomials in an ideal must match the amount "
       "passed to idealBegin()."
     );
@@ -426,6 +461,15 @@ namespace mgb {
     return mPimpl->conf.varCount();
   }
 
+  void GroebnerInputIdealStream::idealBegin() {
+    MATHICGB_ASSERT(debugAssertValid());
+    MATHICGB_IF_DEBUG(mPimpl->checker.idealBegin());
+    MATHICGB_ASSERT(mPimpl->poly.isZero());
+    MATHICGB_ASSERT(mPimpl->ideal.empty());
+
+    MATHICGB_ASSERT(debugAssertValid());
+  }
+
   void GroebnerInputIdealStream::idealBegin(size_t polyCount) {
     MATHICGB_ASSERT(debugAssertValid());
     MATHICGB_IF_DEBUG(mPimpl->checker.idealBegin(polyCount));
@@ -437,6 +481,13 @@ namespace mgb {
     MATHICGB_ASSERT(debugAssertValid());
   }
 
+  void GroebnerInputIdealStream::appendPolynomialBegin() {
+    MATHICGB_ASSERT(debugAssertValid());
+    MATHICGB_IF_DEBUG(mPimpl->checker.appendPolynomialBegin());
+    MATHICGB_ASSERT(mPimpl->poly.isZero());
+    MATHICGB_ASSERT(debugAssertValid());
+  }
+
   void GroebnerInputIdealStream::appendPolynomialBegin(size_t termCount) {
     MATHICGB_ASSERT(debugAssertValid());
     MATHICGB_IF_DEBUG(mPimpl->checker.appendPolynomialBegin(termCount));
diff --git a/src/mathicgb.h b/src/mathicgb.h
index db9662f..bc94fa3 100755
--- a/src/mathicgb.h
+++ b/src/mathicgb.h
@@ -66,7 +66,9 @@ namespace mgb { // Part of the public interface of MathicGB
     Coefficient modulus() const;
     VarIndex varCount() const;
 
+    void idealBegin();
     void idealBegin(size_t polyCount);
+    void appendPolynomialBegin();
     void appendPolynomialBegin(size_t termCount);
     void appendTermBegin();
 
@@ -164,7 +166,9 @@ namespace mgb { // Part of the public interface of MathicGB
     Coefficient modulus() const;
     VarIndex varCount() const;
 
+    void idealBegin();
     void idealBegin(size_t polyCount);
+    void appendPolynomialBegin();
     void appendPolynomialBegin(size_t termCount);
     void appendTermBegin();
     void appendExponent(VarIndex index, Exponent exponent);
@@ -193,7 +197,9 @@ namespace mgb { // Part of the public interface of MathicGB
     Coefficient modulus() const {return mModulus;}
     VarIndex varCount() const {return mVarCount;}
 
+    void idealBegin() {}
     void idealBegin(size_t polyCount) {}
+    void appendPolynomialBegin() {}
     void appendPolynomialBegin(size_t termCount) {}
     void appendTermBegin() {}
     void appendExponent(VarIndex index, Exponent exponent) {}
@@ -226,7 +232,9 @@ namespace mgbi { // Not part of the public interface of MathicGB
     StreamStateChecker(const Coefficient modulus, const VarIndex varCount);
     ~StreamStateChecker();
 
+    void idealBegin();
     void idealBegin(size_t polyCount);
+    void appendPolynomialBegin();
     void appendPolynomialBegin(size_t termCount);
     void appendTermBegin();
     void appendExponent(VarIndex index, Exponent exponent);
@@ -261,7 +269,9 @@ namespace mgb { // Part of the public interface of MathicGB
     Coefficient modulus() const;
     VarIndex varCount() const;
 
+    void idealBegin();
     void idealBegin(size_t polyCount);
+    void appendPolynomialBegin();
     void appendPolynomialBegin(size_t termCount);
     void appendTermBegin();
     void appendExponent(VarIndex index, Exponent exponent);
@@ -349,6 +359,13 @@ namespace mgb {
     return mVarCount;
   }
 
+  template<class Stream>
+  void IdealStreamLog<Stream>::idealBegin() {
+    mLog << "s.idealBegin();\n";
+    if (mStream != 0)
+      mStream->idealBegin();
+  }
+
   template<class Stream> 
   void IdealStreamLog<Stream>::idealBegin(size_t polyCount) {
     mLog << "s.idealBegin(" << polyCount << "); // polyCount\n";
@@ -357,6 +374,13 @@ namespace mgb {
   }
 
   template<class Stream> 
+  void IdealStreamLog<Stream>::appendPolynomialBegin() {
+    mLog << "s.appendPolynomialBegin();\n";
+    if (mStream != 0)
+      mStream->appendPolynomialBegin();
+  }
+
+  template<class Stream> 
   void IdealStreamLog<Stream>::appendPolynomialBegin(size_t termCount) {
     mLog << "s.appendPolynomialBegin(" << termCount << ");\n";
     if (mStream != 0)
@@ -422,12 +446,24 @@ namespace mgb {
   }
 
   template<class Stream>
+  void IdealStreamChecker<Stream>::idealBegin() {
+    mChecker.idealBegin();
+    mStream.idealBegin();
+  }
+
+  template<class Stream>
   void IdealStreamChecker<Stream>::idealBegin(size_t polyCount) {
     mChecker.idealBegin(polyCount);
     mStream.idealBegin(polyCount);
   }
 
   template<class Stream>
+  void IdealStreamChecker<Stream>::appendPolynomialBegin() {
+    mChecker.appendPolynomialBegin();
+    mStream.appendPolynomialBegin();
+  }
+
+  template<class Stream>
   void IdealStreamChecker<Stream>::appendPolynomialBegin(size_t termCount) {
     mChecker.appendPolynomialBegin(termCount);
     mStream.appendPolynomialBegin(termCount);
diff --git a/src/test/mathicgb.cpp b/src/test/mathicgb.cpp
index 91850c2..c5076f0 100755
--- a/src/test/mathicgb.cpp
+++ b/src/test/mathicgb.cpp
@@ -6,8 +6,8 @@
 namespace {
   template<class Stream>
   void makeBasis(Stream& s) {
-    s.idealBegin(2);
-      s.appendPolynomialBegin(2); // x^2 - y
+    s.idealBegin();
+      s.appendPolynomialBegin(); // x^2 - y
         s.appendTermBegin();
           s.appendExponent(0,2);
         s.appendTermDone(1);
@@ -202,8 +202,8 @@ TEST(MathicGBLib, NullIdealStream) {
 TEST(MathicGBLib, IdealStreamLog) {
   {
     const char* const idealStr = 
-      "s.idealBegin(2); // polyCount\n"
-      "s.appendPolynomialBegin(2);\n"
+      "s.idealBegin();\n"
+      "s.appendPolynomialBegin();\n"
       "s.appendTermBegin();\n"
       "s.appendExponent(0, 2); // index, exponent\n"
       "s.appendTermDone(1); // coefficient\n"
@@ -245,7 +245,9 @@ TEST(MathicGBLib, IdealStreamLog) {
     const auto str1 = std::string(
       "IdealStreamLog s(stream, 7, 3);\n"
     ) + idealStr;
-    ASSERT_EQ(str1, out1.str()) << "Displayed expected:\n" << out1.str();
+    ASSERT_EQ(str1, out1.str())
+      << "Displayed expected:\n" << out1.str()
+      << "Displayed actual:\n" << str1 << std::endl;
 
     const auto str2 = std::string(
       "IdealStreamLog s(stream, log); // modulus=7, varCount=3\n"

-- 
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