[mathicgb] 08/393: Making a BjarkeGeobucket2 class that will eventually replace BjarkeGeobucket. For now, this is being added in order to incrementally test mathic::HashTable
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:21 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 3af75ef36f52016779808b31c833b6e46e20550f
Author: Mike Stillman <mikestillman1 at gmail.com>
Date: Thu Aug 2 14:14:15 2012 -0400
Making a BjarkeGeobucket2 class that will eventually replace BjarkeGeobucket. For now, this is being added in order to incrementally test mathic::HashTable
---
Makefile.am | 4 +-
src/mathicgb/BjarkeGeobucket2.cpp | 136 ++++++++++++++++++++++++++++++++++++++
src/mathicgb/BjarkeGeobucket2.hpp | 119 +++++++++++++++++++++++++++++++++
src/mathicgb/Reducer.cpp | 6 +-
4 files changed, 261 insertions(+), 4 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index a7f4fa2..55ff40d 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,7 +17,9 @@ libmathicgb_la_LIBADD= $(DEPS_LIBS)
# the sources that are built to make libmathicgb. Listing the headers in
# sources ensure that those files are included in distributions.
-libmathicgb_la_SOURCES = src/mathicgb/BjarkeGeobucket.cpp \
+libmathicgb_la_SOURCES = src/mathicgb/BjarkeGeobucket2.cpp \
+ src/mathicgb/BjarkeGeobucket2.hpp \
+ src/mathicgb/BjarkeGeobucket.cpp \
src/mathicgb/BjarkeGeobucket.hpp src/mathicgb/BuchbergerAlg.cpp \
src/mathicgb/BuchbergerAlg.hpp src/mathicgb/ChainedHashTable.cpp \
src/mathicgb/ChainedHashTable.hpp src/mathicgb/DivisorLookup.cpp \
diff --git a/src/mathicgb/BjarkeGeobucket2.cpp b/src/mathicgb/BjarkeGeobucket2.cpp
new file mode 100644
index 0000000..cd2e291
--- /dev/null
+++ b/src/mathicgb/BjarkeGeobucket2.cpp
@@ -0,0 +1,136 @@
+// Copyright 2011 Michael E. Stillman
+
+#include <iostream>
+#include "stdinc.h"
+#include "BjarkeGeobucket2.hpp"
+
+extern int tracingLevel;
+
+BjarkeGeobucket2::BjarkeGeobucket2(const PolyRing *R0)
+ : Reducer(),
+ mRing(*R0),
+ mHashTableOLD(R0,10),
+ mNodeCount(0),
+ mHeap(Configuration(*R0,4,1))
+{
+}
+
+BjarkeGeobucket2::~BjarkeGeobucket2()
+{
+}
+
+///////////////////////////////////////
+// External interface routines ////////
+///////////////////////////////////////
+void BjarkeGeobucket2::insertTail(const_term multiplier, const Poly *g1)
+{
+ if (g1->nTerms() <= 1) return;
+
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+ HashPoly M;
+ mHashTableOLD.insert(multiplier, ++(g1->begin()), g1->end(), M);
+
+ if (!M.empty())
+ {
+ mHeap.push(M.begin(),M.end());
+ mNodeCount += M.size();
+ }
+
+ stats_n_inserts++;
+ stats_n_compares += mHeap.getConfiguration().getComparisons();
+ mHeap.getConfiguration().resetComparisons();
+
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+}
+
+void BjarkeGeobucket2::insert(monomial multiplier, const Poly *g1)
+{
+ HashPoly M;
+
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+
+ mHashTableOLD.insert(multiplier, g1->begin(), g1->end(), M);
+
+ if (!M.empty())
+ {
+ mHeap.push(M.begin(),M.end());
+ mNodeCount += M.size();
+ }
+
+ stats_n_inserts++;
+ stats_n_compares += mHeap.getConfiguration().getComparisons();
+ mHeap.getConfiguration().resetComparisons();
+
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+}
+
+bool BjarkeGeobucket2::findLeadTerm(const_term &result)
+{
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+ while (!mHeap.empty())
+ {
+ if (mHashTableOLD.popTerm(mHeap.top(), result.coeff, result.monom))
+ // returns true if mHeap.top() is not the zero element
+ return true;
+ mHeap.pop();
+ mNodeCount--;
+ }
+ return false;
+}
+
+void BjarkeGeobucket2::removeLeadTerm()
+// returns true if there is a term to extract
+{
+ mHeap.pop();
+ mNodeCount--;
+
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+}
+
+void BjarkeGeobucket2::value(Poly &result)
+// keep extracting lead term until done
+{
+ const_term t;
+ while (findLeadTerm(t))
+ {
+ result.appendTerm(t.coeff, t.monom);
+ mHeap.pop();
+ mNodeCount--;
+ }
+
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+ resetReducer();
+}
+
+void BjarkeGeobucket2::resetReducer()
+{
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+ const_term t;
+ while (findLeadTerm(t))
+ {
+ mHeap.pop();
+ mNodeCount--;
+ }
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+ mHashTableOLD.reset();
+ ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
+ // how to reset mHeap ?
+}
+
+size_t BjarkeGeobucket2::getMemoryUse() const
+{
+ size_t result = mHashTableOLD.getMemoryUse();
+ result += mHeap.getMemoryUse();
+ // std::cerr << "[reducer: " << mHashTableOLD.getMemoryUse() << " " << mHeap.getMemoryUse() << "]" << std::endl;
+ return result;
+}
+
+void BjarkeGeobucket2::dump() const
+{
+ mHashTableOLD.dump(0);
+}
+
+// Local Variables:
+// compile-command: "make -C $MATHIC/mathicgb "
+// indent-tabs-mode: nil
+// End:
diff --git a/src/mathicgb/BjarkeGeobucket2.hpp b/src/mathicgb/BjarkeGeobucket2.hpp
new file mode 100644
index 0000000..c0baba2
--- /dev/null
+++ b/src/mathicgb/BjarkeGeobucket2.hpp
@@ -0,0 +1,119 @@
+// Copyright 2011 Michael E. Stillman
+
+#ifndef _bjarkeGeoBucket_h_
+#define _bjarkeGeoBucket_h_
+
+#include <mathic.h>
+#include "Reducer.hpp"
+#include "PolyHashTable.hpp"
+
+template<
+ bool TrackFront,
+ bool MinBucketBinarySearch,
+ bool Deduplicate,
+ bool Premerge,
+ bool CollectMax,
+ int BucketStorage,
+ size_t InsertFactor = 1>
+class GeoConfiguration {
+public:
+ GeoConfiguration(
+ const PolyRing &ring,
+ size_t geoBase,
+ size_t minBucketSize):
+ mRing(ring), geoBase(geoBase), minBucketSize(minBucketSize), _comparisons(0) {}
+
+ const PolyRing &mRing;
+ size_t geoBase;
+ size_t minBucketSize;
+
+ typedef PolyHashTable::node * Entry;
+
+ typedef bool CompareResult;
+
+ CompareResult compare(const Entry& a, const Entry& b) const {
+ ++_comparisons;
+ return mRing.monomialLT(a->monom, b->monom);
+ }
+ bool cmpLessThan(CompareResult r) const {return r;}
+
+ static const bool supportDeduplication = Deduplicate;
+ bool cmpEqual(CompareResult r) const {return r;} // NOT USED IN OUR CASE HERRE!
+ Entry deduplicate(const Entry& a, const Entry& /* b */) const {ASSERT(false); return a;}
+
+ size_t getComparisons() const {return _comparisons;}
+ void resetComparisons() const {_comparisons = 0;}
+
+ static const bool minBucketBinarySearch = MinBucketBinarySearch;
+ static const bool trackFront = TrackFront;
+ static const bool premerge = Premerge;
+ static const bool collectMax = CollectMax;
+ static const mic::GeobucketBucketStorage bucketStorage =
+ (mic::GeobucketBucketStorage)BucketStorage;
+ static const size_t insertFactor = InsertFactor;
+
+private:
+ mutable size_t _comparisons;
+};
+
+class BjarkeGeobucket2Configuration
+{
+public:
+ typedef const_monomial Key;
+ typedef coefficient Value;
+
+ BjarkeGeobucket2Configuration(const PolyRing &ring) : mRing(ring) {}
+
+ size_t hash(Key k) {return mRing.monomialHashValue(k);}
+
+ bool keysEqual(Key k1, Key k2) {
+ return ((mRing.monomialHashValue(k1) == mRing.monomialHashValue(k2))
+ && mRing.monomialEQ(k1, k2));
+ }
+
+ void combine(Value &a, const Value &b) {mRing.coefficientAddTo(a,b);}
+private:
+ const PolyRing &mRing;
+};
+
+class BjarkeGeobucket2 : public Reducer {
+public:
+ BjarkeGeobucket2(const PolyRing *R);
+ ~BjarkeGeobucket2();
+
+ virtual std::string description() const { return "bjarke geo buckets"; }
+
+ void insertTail(const_term multiplier, const Poly *f);
+ void insert(monomial multiplier, const Poly *f);
+
+ bool findLeadTerm(const_term &result);
+ void removeLeadTerm();
+
+ void value(Poly &result); // keep extracting lead term until done
+
+ size_t getMemoryUse() const;
+
+ void dump() const; // Used for debugging
+
+protected:
+ void resetReducer();
+
+private:
+ void insert(const_term multiplier, Poly::iterator first, Poly::iterator last);
+
+ typedef PolyHashTable::MonomialArray HashPoly;
+ typedef GeoConfiguration<true,true,false,false,false,1,1> Configuration;
+
+ size_t mNodeCount; // number of (distinct) monomials in mHeap
+
+ const PolyRing &mRing;
+ PolyHashTable mHashTableOLD;
+ mic::Geobucket< Configuration > mHeap;
+};
+
+#endif
+
+// Local Variables:
+// indent-tabs-mode: nil
+// compile-command: "make -C $MATHIC/mathicgb "
+// End:
diff --git a/src/mathicgb/Reducer.cpp b/src/mathicgb/Reducer.cpp
index 062e843..fd1871f 100644
--- a/src/mathicgb/Reducer.cpp
+++ b/src/mathicgb/Reducer.cpp
@@ -7,7 +7,7 @@
#include "PolyGeoBucket.hpp"
#include "PolyReducer.hpp"
#include "PolyHashReducer.hpp"
-#include "BjarkeGeobucket.hpp"
+#include "BjarkeGeobucket2.hpp"
#include "GroebnerBasis.hpp"
#include "TournamentReducer.hpp"
#include "HashTourReducer.hpp"
@@ -48,7 +48,7 @@ std::auto_ptr<Reducer> Reducer::makeReducerNullOnUnknown(
case Reducer_PolyHash:
return std::auto_ptr<Reducer>(new PolyHashReducer(&ring));
case Reducer_BjarkeGeo:
- return std::auto_ptr<Reducer>(new BjarkeGeobucket(&ring));
+ return std::auto_ptr<Reducer>(new BjarkeGeobucket2(&ring));
case Reducer_TournamentTree:
return std::auto_ptr<Reducer>(new TournamentReducer(ring));
//return std::auto_ptr<Reducer>
@@ -147,7 +147,7 @@ void Reducer::displayReducerTypes(std::ostream &o)
o << " 1 PolyGeoBucket" << std::endl;
o << " 2 Poly" << std::endl;
o << " 3 PolyHash" << std::endl;
- o << " 4 BjarkeGeo" << std::endl;
+ o << " 4 BjarkeGeo2" << std::endl;
o << " 5 Tournament tree" << std::endl;
o << " 6 Hashed Tournament tree" << std::endl;
--
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