[mathicgb] 337/393: Starting on clean-up of monomial data structure code. Tidied DivLookupConfigureion.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:31 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 0c82d0991f76376c04f70bafcc438c9f5f73518b
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Tue Aug 27 13:38:25 2013 +0200
Starting on clean-up of monomial data structure code. Tidied DivLookupConfigureion.
---
src/mathicgb/DivLookup.hpp | 185 +++++++++--------------------------------
src/mathicgb/DivisorLookup.cpp | 23 +----
2 files changed, 41 insertions(+), 167 deletions(-)
diff --git a/src/mathicgb/DivLookup.hpp b/src/mathicgb/DivLookup.hpp
index 806ac79..785d94b 100755
--- a/src/mathicgb/DivLookup.hpp
+++ b/src/mathicgb/DivLookup.hpp
@@ -21,40 +21,26 @@ class DivLookupConfiguration;
template<bool AR, bool DM>
class DivLookupConfiguration {
-
public:
+ typedef PolyRing::Monoid Monoid;
+
DivLookupConfiguration(
- const PolyRing& ring,
- bool minimizeOnInsert,
- bool sortOnInsert,
- bool useDivisorCache,
- double rebuildRatio,
- size_t minRebuild,
+ const Monoid& monoid,
int type,
bool preferSparseReducers
):
mBasis(0),
mSigBasis(0),
- mRing(&ring),
- _varCount(ring.getNumVars()),
- _minimize_on_insert(minimizeOnInsert),
- _sortOnInsert(sortOnInsert),
- _useDivisorCache(useDivisorCache),
- _useAutomaticRebuild((rebuildRatio > 0.0 || minRebuild > 0) && UseDivMask),
- _rebuildRatio(rebuildRatio),
- _minRebuild(minRebuild),
- _expQueryCount(0),
- _type(type),
+ mMonoid(monoid),
+ mType(type),
_preferSparseReducers(preferSparseReducers)
- {
- MATHICGB_ASSERT(rebuildRatio >= 0);
- }
+ {}
void setBasis(const PolyBasis& basis) {
if (mBasis == &basis)
return;
MATHICGB_ASSERT(mBasis == 0);
- MATHICGB_ASSERT(mRing == &basis.ring());
+ MATHICGB_ASSERT(monoid() == basis.ring().monoid());
mBasis = &basis;
}
@@ -63,14 +49,18 @@ public:
return;
MATHICGB_ASSERT(mSigBasis == 0);
MATHICGB_ASSERT(mBasis == 0 || mBasis == &sigBasis.basis());
- MATHICGB_ASSERT(mRing == &sigBasis.basis().ring());
+ MATHICGB_ASSERT(monoid() == sigBasis.basis().ring().monoid());
mSigBasis = &sigBasis;
setBasis(sigBasis.basis());
}
- //////////////////////////
- // Functions and types required by KDTree, or by DivList, or by ...
- //////////////////////////
+ const SigPolyBasis* sigBasis() const {return mSigBasis;}
+ const PolyBasis* basis() const {return mBasis;}
+ const Monoid& monoid() const {return mMonoid;}
+ int type() const {return mType;}
+ bool preferSparseReducers() const {return _preferSparseReducers;}
+
+ // *** Interface expected by mathic follows below
typedef int Exponent;
typedef const_monomial Monomial;
@@ -83,94 +73,38 @@ public:
monom(monom0), index(index0) {}
};
- Exponent getExponent(const Monomial& m, size_t var) const
- {
- ++_expQueryCount;
- return mRing->monomialExponent(m, var);
- }
- Exponent getExponent(const Entry& e, size_t var) const
- {
- ++_expQueryCount;
- return mRing->monomialExponent(e.monom, var);
+ Exponent getExponent(const Monomial& m, size_t var) const {
+ return monoid().exponent(m, var);
}
- bool divides(const Monomial& a, const Monomial& b) const
- {
- for (size_t var = 0; var < getVarCount(); ++var)
- if (getExponent(b, var) < getExponent(a, var))
- return false;
- return true;
+ Exponent getExponent(const Entry& e, size_t var) const {
+ return monoid().exponent(e.monom, var);
}
- bool divides(const Entry& a, const Monomial& b) const
- {
- for (size_t var = 0; var < getVarCount(); ++var)
- if (getExponent(b, var) < getExponent(a, var))
- return false;
- return true;
+ bool divides(const Monomial& a, const Monomial& b) const {
+ return monoid().divides(a, b);
}
- bool divides(const Monomial& a, const Entry& b) const
- {
- for (size_t var = 0; var < getVarCount(); ++var)
- if (getExponent(b, var) < getExponent(a, var))
- return false;
- return true;
+ bool divides(const Entry& a, const Monomial& b) const {
+ return monoid().divides(a.monom, b);
}
- bool divides(const Entry& a, const Entry& b) const
- {
- for (size_t var = 0; var < getVarCount(); ++var)
- if (getExponent(b, var) < getExponent(a, var))
- return false;
- return true;
+ bool divides(const Monomial& a, const Entry& b) const {
+ return monoid().divides(a, b.monom);
}
- bool isLessThan(const Monomial& a, const Monomial& b) const
- {
- for (size_t var = 0; var < getVarCount(); ++var) {
- if (getExponent(a, var) < getExponent(b, var))
- return true;
- if (getExponent(b, var) < getExponent(a, var))
- return false;
- }
- return false;
+ bool divides(const Entry& a, const Entry& b) const {
+ return monoid().divides(a.monom, b.monom);
}
- bool isLessThan(const Entry& a, const Monomial& b) const
- {
- for (size_t var = 0; var < getVarCount(); ++var) {
- if (getExponent(a, var) < getExponent(b, var))
- return true;
- if (getExponent(b, var) < getExponent(a, var))
- return false;
- }
+ bool getSortOnInsert() const {return false;}
+ template<class A, class B>
+ bool isLessThan(const A& a, const B& b) const {
+ MATHICGB_ASSERT(false);
return false;
}
- bool isLessThan(const Monomial& a, const Entry& b) const
- {
- for (size_t var = 0; var < getVarCount(); ++var) {
- if (getExponent(a, var) < getExponent(b, var))
- return true;
- if (getExponent(b, var) < getExponent(a, var))
- return false;
- }
- return false;
- }
-
- bool isLessThan(const Entry& a, const Entry& b) const
- {
- for (size_t var = 0; var < getVarCount(); ++var) {
- if (getExponent(a, var) < getExponent(b, var))
- return true;
- if (getExponent(b, var) < getExponent(a, var))
- return false;
- }
- return false;
- }
-
- size_t getVarCount() const {return _varCount;}
+ size_t getVarCount() const {return monoid().varCount();}
static const bool UseTreeDivMask = DM;
static const bool UseLinkedList = false;
@@ -179,59 +113,18 @@ public:
static const bool PackedTree = true;
static const bool AllowRemovals = AR;
- bool getSortOnInsert() const {return _sortOnInsert;}
- bool getUseDivisorCache() const {return _useDivisorCache;}
- bool getMinimizeOnInsert() const {return _minimize_on_insert;}
-
- bool getDoAutomaticRebuilds() const {return _useAutomaticRebuild;}
- double getRebuildRatio() const {return _rebuildRatio;}
- size_t getRebuildMin() const {return _minRebuild;}
-
-///////////////////////////
-// Stats gathering ////////
-///////////////////////////
-public:
- struct Stats {
- size_t n_member;
- size_t n_inserts; // includes koszuls
- size_t n_insert_already_there;
- size_t n_compares;
- unsigned long long n_expQuery;
-
- Stats():
- n_member(0),
- n_inserts(0),
- n_insert_already_there(0),
- n_compares(0),
- n_expQuery(0)
- {}
-
- };
-
- void displayStats(std::ostream &o) const;
+ bool getUseDivisorCache() const {return true;}
+ bool getMinimizeOnInsert() const {return false;}
-///////////////////////////
- const SigPolyBasis* sigBasis() const {return mSigBasis;}
- const PolyBasis* basis() const {return mBasis;}
- const PolyRing* getPolyRing() const {return mRing;}
- unsigned long long getExpQueryCount() const {return _expQueryCount;}
- int type() const {return _type;}
- bool preferSparseReducers() const {return _preferSparseReducers;}
+ bool getDoAutomaticRebuilds() const {return UseDivMask;}
+ double getRebuildRatio() const {return 0.5;}
+ size_t getRebuildMin() const {return 50;}
private:
PolyBasis const* mBasis;
SigPolyBasis const* mSigBasis;
- const PolyRing* mRing;
- const size_t _varCount;
- const bool _minimize_on_insert;
- const bool _sortOnInsert;
- const bool _useDivisorCache;
- const bool _useAutomaticRebuild;
- const double _rebuildRatio;
- const size_t _minRebuild;
- mutable unsigned long long _expQueryCount;
- mutable Stats _stats;
- const int _type;
+ const Monoid& mMonoid;
+ const int mType;
bool const _preferSparseReducers;
};
diff --git a/src/mathicgb/DivisorLookup.cpp b/src/mathicgb/DivisorLookup.cpp
index 04102dd..370f7ef 100755
--- a/src/mathicgb/DivisorLookup.cpp
+++ b/src/mathicgb/DivisorLookup.cpp
@@ -10,15 +10,6 @@
MATHICGB_NAMESPACE_BEGIN
namespace {
- struct DefaultParams {
- static bool const minimizeOnInsert = false;
- static bool const sortOnInsert = false;
- static bool const useDivisorCache = true;
- static double const rebuildRatio;
- static size_t const minRebuildRatio = 50;
- };
- double const DefaultParams::rebuildRatio = 0.5;
-
class DivListFactory : public DivisorLookup::Factory {
public:
DivListFactory(const PolyRing& ring, bool useDivMask): mRing(ring), mUseDivMask(useDivMask) {}
@@ -38,12 +29,7 @@ namespace {
typedef DivLookupConfiguration<true, UseDivMask> Configuration;
bool useDM = UseDivMask;
Configuration configuration(
- mRing,
- DefaultParams::minimizeOnInsert,
- DefaultParams::sortOnInsert,
- DefaultParams::useDivisorCache,
- DefaultParams::rebuildRatio,
- DefaultParams::minRebuildRatio,
+ mRing.monoid(),
(useDM ? 1 : 3),
preferSparseReducers);
return std::unique_ptr<DivisorLookup>
@@ -82,12 +68,7 @@ namespace {
typedef DivLookupConfiguration<AllowRemovals, UseDivMask> Configuration;
bool useDM = UseDivMask;
Configuration configuration(
- mRing,
- DefaultParams::minimizeOnInsert,
- DefaultParams::sortOnInsert,
- DefaultParams::useDivisorCache,
- DefaultParams::rebuildRatio,
- DefaultParams::minRebuildRatio,
+ mRing.monoid(),
(useDM ? 2 : 4),
preferSparseReducers);
return std::unique_ptr<DivisorLookup>
--
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