[mathicgb] 315/393: Moved NonCopyable to its own file. Made KoszulQueue movable but non-copyable and removed use of FreeModuleOrder from KoszulQueue and SigSPairs.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:28 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 652073930783508f858197c59dbc0e8ea7930c7b
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Sat May 11 13:24:14 2013 +0200
Moved NonCopyable to its own file. Made KoszulQueue movable but non-copyable and removed use of FreeModuleOrder from KoszulQueue and SigSPairs.
---
Makefile.am | 46 ++++++++++++++++++++++----------------------
src/mathicgb/Basis.cpp | 26 +++++++------------------
src/mathicgb/KoszulQueue.cpp | 5 -----
src/mathicgb/KoszulQueue.hpp | 28 ++++++++++++---------------
src/mathicgb/MonoMonoid.hpp | 15 +--------------
src/mathicgb/NonCopyable.hpp | 22 +++++++++++++++++++++
src/mathicgb/SigSPairs.cpp | 9 ---------
src/mathicgb/SigSPairs.hpp | 10 +---------
src/mathicgb/SignatureGB.cpp | 29 +++++++++++++---------------
src/mathicgb/SignatureGB.hpp | 2 +-
10 files changed, 80 insertions(+), 112 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 1375921..2e4e4e1 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,28 +24,28 @@ libmathicgb_la_SOURCES = src/mathicgb/BjarkeGeobucket2.cpp \
src/mathicgb/HashTourReducer.cpp src/mathicgb/HashTourReducer.hpp \
src/mathicgb/Basis.cpp src/mathicgb/Basis.hpp \
src/mathicgb/io-util.cpp src/mathicgb/io-util.hpp \
- src/mathicgb/KoszulQueue.cpp src/mathicgb/KoszulQueue.hpp \
- src/mathicgb/MonomialHashTable.hpp src/mathicgb/MonTableDivList.hpp \
- src/mathicgb/MonTableKDTree.hpp src/mathicgb/MonTableNaive.cpp \
- src/mathicgb/MonTableNaive.hpp src/mathicgb/MTArray.cpp \
- src/mathicgb/MTArray.hpp src/mathicgb/PairTriangle.cpp \
- src/mathicgb/PairTriangle.hpp src/mathicgb/Poly.cpp \
- src/mathicgb/Poly.hpp src/mathicgb/PolyBasis.cpp \
- src/mathicgb/PolyBasis.hpp src/mathicgb/PolyGeoBucket.cpp \
- src/mathicgb/PolyGeoBucket.hpp src/mathicgb/PolyHashReducer.cpp \
- src/mathicgb/PolyHashReducer.hpp src/mathicgb/PolyHashTable.cpp \
- src/mathicgb/PolyHashTable.hpp src/mathicgb/PolyHeap.cpp \
- src/mathicgb/PolyHeap.hpp src/mathicgb/PolyReducer.cpp \
- src/mathicgb/PolyReducer.hpp src/mathicgb/PolyRing.cpp \
- src/mathicgb/PolyRing.hpp src/mathicgb/Reducer.cpp \
- src/mathicgb/Reducer.hpp src/mathicgb/ReducerDedup.hpp \
- src/mathicgb/ReducerHash.hpp src/mathicgb/ReducerHashPack.hpp \
- src/mathicgb/ReducerHelper.hpp src/mathicgb/ReducerNoDedup.hpp \
- src/mathicgb/ReducerPack.hpp src/mathicgb/ReducerPackDedup.hpp \
- src/mathicgb/SignatureGB.cpp src/mathicgb/SignatureGB.hpp \
- src/mathicgb/SigSPairs.cpp src/mathicgb/SigSPairs.hpp \
- src/mathicgb/SPairs.cpp src/mathicgb/SPairs.hpp \
- src/mathicgb/stdinc.h src/mathicgb/TournamentReducer.cpp \
+ src/mathicgb/KoszulQueue.hpp src/mathicgb/MonomialHashTable.hpp \
+ src/mathicgb/MonTableDivList.hpp src/mathicgb/MonTableKDTree.hpp \
+ src/mathicgb/MonTableNaive.cpp src/mathicgb/MonTableNaive.hpp \
+ src/mathicgb/MTArray.cpp src/mathicgb/MTArray.hpp \
+ src/mathicgb/PairTriangle.cpp src/mathicgb/PairTriangle.hpp \
+ src/mathicgb/Poly.cpp src/mathicgb/Poly.hpp \
+ src/mathicgb/PolyBasis.cpp src/mathicgb/PolyBasis.hpp \
+ src/mathicgb/PolyGeoBucket.cpp src/mathicgb/PolyGeoBucket.hpp \
+ src/mathicgb/PolyHashReducer.cpp src/mathicgb/PolyHashReducer.hpp \
+ src/mathicgb/PolyHashTable.cpp src/mathicgb/PolyHashTable.hpp \
+ src/mathicgb/PolyHeap.cpp src/mathicgb/PolyHeap.hpp \
+ src/mathicgb/PolyReducer.cpp src/mathicgb/PolyReducer.hpp \
+ src/mathicgb/PolyRing.cpp src/mathicgb/PolyRing.hpp \
+ src/mathicgb/Reducer.cpp src/mathicgb/Reducer.hpp \
+ src/mathicgb/ReducerDedup.hpp src/mathicgb/ReducerHash.hpp \
+ src/mathicgb/ReducerHashPack.hpp src/mathicgb/ReducerHelper.hpp \
+ src/mathicgb/ReducerNoDedup.hpp src/mathicgb/ReducerPack.hpp \
+ src/mathicgb/ReducerPackDedup.hpp src/mathicgb/SignatureGB.cpp \
+ src/mathicgb/SignatureGB.hpp src/mathicgb/SigSPairs.cpp \
+ src/mathicgb/SigSPairs.hpp src/mathicgb/SPairs.cpp \
+ src/mathicgb/SPairs.hpp src/mathicgb/stdinc.h \
+ src/mathicgb/TournamentReducer.cpp \
src/mathicgb/TournamentReducer.hpp src/mathicgb/SigSPairQueue.hpp \
src/mathicgb/SigSPairQueue.cpp src/mathicgb/SparseMatrix.hpp \
src/mathicgb/SparseMatrix.cpp src/mathicgb/QuadMatrixBuilder.hpp \
@@ -68,7 +68,7 @@ libmathicgb_la_SOURCES = src/mathicgb/BjarkeGeobucket2.cpp \
src/mathicgb/MonoProcessor.hpp src/mathicgb/MonoOrder.hpp \
src/mathicgb/Scanner.hpp src/mathicgb/Scanner.cpp \
src/mathicgb/Unchar.hpp src/mathicgb/MathicIO.hpp \
- src/mathicgb/MathicIO.cpp
+ src/mathicgb/MathicIO.cpp src/mathicgb/NonCopyable.hpp
# The headers that libmathicgb installs.
diff --git a/src/mathicgb/Basis.cpp b/src/mathicgb/Basis.cpp
index c381f13..006b76d 100755
--- a/src/mathicgb/Basis.cpp
+++ b/src/mathicgb/Basis.cpp
@@ -3,7 +3,6 @@
#include "PolyRing.hpp"
#include "Poly.hpp"
-#include "FreeModuleOrder.hpp"
#include "MathicIO.hpp"
#include <ostream>
#include <istream>
@@ -16,25 +15,14 @@ void Basis::insert(std::unique_ptr<Poly>&& p) {
mGenerators.push_back(std::move(p));
}
-namespace {
- class BasisSort {
- public:
- BasisSort(const FreeModuleOrder& order): mOrder(order) {}
- bool operator()(
- const std::unique_ptr<Poly>& a,
- const std::unique_ptr<Poly>& b
- ) {
- return mOrder.signatureCompare
- (a->getLeadMonomial(), b->getLeadMonomial()) == LT;
- }
-
- private:
- const FreeModuleOrder& mOrder;
- };
-}
-
void Basis::sort(FreeModuleOrder& order) {
- BasisSort cmp(order);
+ const auto& monoid = ring().monoid();
+ const auto cmp = [&monoid](
+ const std::unique_ptr<Poly>& a,
+ const std::unique_ptr<Poly>& b
+ ) {
+ return monoid.lessThan(a->getLeadMonomial(), b->getLeadMonomial());
+ };
std::sort(mGenerators.begin(), mGenerators.end(), cmp);
}
diff --git a/src/mathicgb/KoszulQueue.cpp b/src/mathicgb/KoszulQueue.cpp
old mode 100644
new mode 100755
index 6807fe1..3a4daca
--- a/src/mathicgb/KoszulQueue.cpp
+++ b/src/mathicgb/KoszulQueue.cpp
@@ -1,10 +1,5 @@
#include "stdinc.h"
#include "KoszulQueue.hpp"
-#include "FreeModuleOrder.hpp"
-
-KoszulQueue::Configuration::CompareResult KoszulQueue::Configuration::compare(const Entry& a, const Entry& b) const {
- return mOrder->signatureCompare(a,b);
-}
// Local Variables:
// compile-command: "make -C .. "
diff --git a/src/mathicgb/KoszulQueue.hpp b/src/mathicgb/KoszulQueue.hpp
index 917ad5e..57106e7 100755
--- a/src/mathicgb/KoszulQueue.hpp
+++ b/src/mathicgb/KoszulQueue.hpp
@@ -1,18 +1,14 @@
#ifndef koszul_queue_guard
#define koszul_queue_guard
-#include <memtailor.h>
-#include <mathic.h>
#include "PolyRing.hpp"
+#include "NonCopyable.hpp"
+#include <mathic.h>
-class FreeModuleOrder;
-
-class KoszulQueue
-{
+class KoszulQueue : public NonCopyable<KoszulQueue> {
public:
- KoszulQueue(const FreeModuleOrder *order, const PolyRing& ring):
- mQueue(Configuration(order, ring))
- {}
+ KoszulQueue(const PolyRing& ring): mQueue(Configuration(ring)) {}
+ KoszulQueue(KoszulQueue&& kq): mQueue(std::move(kq.mQueue)) {}
const_monomial top() const {
MATHICGB_ASSERT(!empty());
@@ -37,22 +33,23 @@ public:
size_t getMemoryUse() const {return mQueue.getMemoryUse();}
private:
+ KoszulQueue(const KoszulQueue&); // unavailable
+
+
class Configuration
{
public:
typedef monomial Entry;
- Configuration(const FreeModuleOrder *order, const PolyRing& ring):
- mOrder(order), mRing(ring)
- {
- MATHICGB_ASSERT(mOrder != 0);
- }
+ Configuration(const PolyRing& ring): mRing(ring) {}
const PolyRing& ring() const {return mRing;}
typedef int CompareResult; /* LT, EQ, GT */
- CompareResult compare(const Entry& a, const Entry& b) const;
+ CompareResult compare(const Entry& a, const Entry& b) const {
+ return ring().monoid().compare(a, b);
+ }
bool cmpLessThan(CompareResult r) const {return r == GT;}
@@ -66,7 +63,6 @@ private:
return a;
}
private:
- const FreeModuleOrder *mOrder;
const PolyRing& mRing;
};
diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index 23d64b6..67b5792 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -2,6 +2,7 @@
#define MATHICGB_MONO_MONOID_GUARD
#include "MonoOrder.hpp"
+#include "NonCopyable.hpp"
#include <vector>
#include <algorithm>
#include <memtailor.h>
@@ -13,20 +14,6 @@
#include <cstring>
#include <mathic.h>
-/// Temporary class. Should be moved to its own place eventually.
-/// Derive from this class to disable the compiler-generated
-/// copy constructor and assignment. The purpose of the template
-/// parameter is to avoid any chance of getting a diamond-graph
-/// inheritance graph.
-template<class T>
-class NonCopyable {
-public:
- NonCopyable() {}
-private:
- NonCopyable(const NonCopyable&); // unavailable
- void operator=(const NonCopyable&); // unavailable
-};
-
/// Implements the monoid of (monic) monomials with integer
/// non-negative exponents. Exponent must be an unsigned integer type that is
/// used to store each exponent of a monomial.
diff --git a/src/mathicgb/NonCopyable.hpp b/src/mathicgb/NonCopyable.hpp
new file mode 100755
index 0000000..e64dfa0
--- /dev/null
+++ b/src/mathicgb/NonCopyable.hpp
@@ -0,0 +1,22 @@
+#ifndef MATHICGB_NON_COPYABLE_GUARD
+#define MATHICGB_NON_COPYABLE_GUARD
+
+/// Derive from this class to disable the compiler-generated copy
+/// constructor and assignment. T should be the class that is deriving
+/// from NonCopyable.
+///
+/// The purpose of the template parameter is to avoid any chance of
+/// getting a diamond-graph inheritance graph. Diamond graphs can lead
+/// to runtime overhead.
+template<class T>
+class NonCopyable {
+public:
+ NonCopyable() {}
+ NonCopyable(NonCopyable&&) {} // still movable.
+
+private:
+ NonCopyable(const NonCopyable&); // unavailable
+ void operator=(const NonCopyable&); // unavailable
+};
+
+#endif
diff --git a/src/mathicgb/SigSPairs.cpp b/src/mathicgb/SigSPairs.cpp
index ba437ba..dc95301 100755
--- a/src/mathicgb/SigSPairs.cpp
+++ b/src/mathicgb/SigSPairs.cpp
@@ -4,7 +4,6 @@
#include "GroebnerBasis.hpp"
#include "MTArray.hpp"
-#include "FreeModuleOrder.hpp"
#include "Reducer.hpp"
#include <limits>
#include <stdexcept>
@@ -12,7 +11,6 @@
SigSPairs::SigSPairs(
const PolyRing *R0,
- FreeModuleOrder *F0,
const GroebnerBasis *GB0,
MonomialTableArray *Hsyz0,
Reducer* reducer,
@@ -22,7 +20,6 @@ SigSPairs::SigSPairs(
size_t queueType
):
R(R0),
- F(F0),
mUseSingularCriterionEarly(useSingularCriterionEarly),
mUseBaseDivisors(useBaseDivisors),
mUseHighBaseDivisors(useBaseDivisors),
@@ -42,12 +39,6 @@ void SigSPairs::newSyzygy(const_monomial sig) {
MATHICGB_ASSERT(Hsyz->member(sig));
}
-SigSPairs::Stats SigSPairs::getStats() const
-{
- F->getStats(mStats.comparisons, mStats.precomparisons);
- return mStats;
-}
-
monomial SigSPairs::popSignature(PairContainer& pairs) {
monomial sig = mQueue->popSignature(pairs);
if (!sig.isNull()) {
diff --git a/src/mathicgb/SigSPairs.hpp b/src/mathicgb/SigSPairs.hpp
index 9f06855..9c3def1 100755
--- a/src/mathicgb/SigSPairs.hpp
+++ b/src/mathicgb/SigSPairs.hpp
@@ -12,7 +12,6 @@
class Poly;
class MonomialTableArray;
class GroebnerBasis;
-class FreeModuleOrder;
class Reducer;
// Handles S-pairs in signature Grobner basis algorithms. Responsible
@@ -22,7 +21,6 @@ class SigSPairs
public:
SigSPairs(
const PolyRing *R0,
- FreeModuleOrder *F0,
const GroebnerBasis *GB0,
MonomialTableArray *Hsyz0,
Reducer* reducer,
@@ -42,8 +40,6 @@ public:
void newSyzygy(const_monomial sig);
struct Stats {
- size_t comparisons; // comparisons not in construction (?)
- size_t precomparisons; // comparisons in spair construction (?)
unsigned long long spairsConstructed; // all spairs
unsigned long long spairsFinal; // spairs given to client
unsigned long long nonregularSPairs; // spairs eliminated by being non-regular
@@ -58,8 +54,6 @@ public:
unsigned long long duplicateSignatures; // number of spairs removed due to duplicate signature
Stats():
- comparisons(0),
- precomparisons(0),
spairsConstructed(0),
spairsFinal(0),
nonregularSPairs(0),
@@ -73,7 +67,7 @@ public:
queuedPairs(0),
duplicateSignatures(0) {}
};
- Stats getStats() const;
+ Stats getStats() const {return mStats;}
size_t pairCount() const;
@@ -104,8 +98,6 @@ private:
const PolyRing *R;
- FreeModuleOrder *F;
-
// if true, apply the early singular criterion
bool const mUseSingularCriterionEarly;
diff --git a/src/mathicgb/SignatureGB.cpp b/src/mathicgb/SignatureGB.cpp
index 999c60b..748dd2f 100755
--- a/src/mathicgb/SignatureGB.cpp
+++ b/src/mathicgb/SignatureGB.cpp
@@ -38,11 +38,11 @@ SignatureGB::SignatureGB(
stats_pairsReduced(0),
stats_nsecs(0.0),
GB(make_unique<GroebnerBasis>(R, F.get(), divlookup_type, montable_type, preferSparseReducers)),
- mKoszuls(make_unique<KoszulQueue>(F.get(), *R)),
+ mKoszuls(*R),
Hsyz(MonomialTableArray::make(R, montable_type, basis.size(), !mPostponeKoszul)),
Hsyz2(MonomialTableArray::make(R, montable_type, basis.size(), !mPostponeKoszul)),
reducer(Reducer::makeReducer(reductiontyp, *R)),
- SP(make_unique<SigSPairs>(R, F.get(), GB.get(), Hsyz.get(), reducer.get(), mPostponeKoszul, mUseBaseDivisors, useSingularCriterionEarly, queueType))
+ SP(make_unique<SigSPairs>(R, GB.get(), Hsyz.get(), reducer.get(), mPostponeKoszul, mUseBaseDivisors, useSingularCriterionEarly, queueType))
{
mProcessor = make_unique<MonoProcessor<Monoid>>(std::move(processor));
mProcessor->setComponentCount(basis.size());
@@ -222,13 +222,13 @@ bool SignatureGB::step()
// Not a known syzygy
- while (!mKoszuls->empty()
- && F->signatureCompare(mKoszuls->top(), sig) == LT)
+ while (!mKoszuls.empty()
+ && F->signatureCompare(mKoszuls.top(), sig) == LT)
{
- mKoszuls->pop();
+ mKoszuls.pop();
}
- if (!mKoszuls->empty() && R->monomialEQ(mKoszuls->top(), sig))
+ if (!mKoszuls.empty() && R->monomialEQ(mKoszuls.top(), sig))
{
++stats_koszulEliminated;
// This signature is of a syzygy that is not in Hsyz, so add it
@@ -282,23 +282,20 @@ bool SignatureGB::step()
if (Hsyz->member(koszul, dummy))
R->freeMonomial(koszul);
else
- mKoszuls->push(koszul);
+ mKoszuls.push(koszul);
}
return true;
}
size_t SignatureGB::getMemoryUse() const {
- size_t sum =
+ return
GB->getMemoryUse() +
Hsyz->getMemoryUse() +
R->getMemoryUse() +
reducer->getMemoryUse() +
- mSpairTmp.capacity() * sizeof(mSpairTmp.front());
- sum += SP->getMemoryUse();
-
- if (mKoszuls.get() != 0)
- mKoszuls->getMemoryUse();
- return sum;
+ mSpairTmp.capacity() * sizeof(mSpairTmp.front()) +
+ SP->getMemoryUse() +
+ mKoszuls.getMemoryUse();
}
void SignatureGB::displayStats(std::ostream &o) const
@@ -519,7 +516,7 @@ void SignatureGB::displaySomeStats(std::ostream& out) const {
extra << mic::ColumnPrinter::oneDecimal(syzBasisRatio)
<< " syzygies per basis element\n";
- const size_t queuedKoszuls = mKoszuls->size();
+ const size_t queuedKoszuls = mKoszuls.size();
const double quedRatio = static_cast<double>(queuedKoszuls) / minSyz;
name << "Queued Koszul syzygies:\n";
value << mic::ColumnPrinter::commafy(queuedKoszuls) << '\n';
@@ -699,7 +696,7 @@ void SignatureGB::displayMemoryUse(std::ostream& out) const
extra << mic::ColumnPrinter::percentInteger(syzMem, total) << '\n';
}
{ // Koszul queue
- const size_t syzQueueMem = mKoszuls->getMemoryUse();
+ const size_t syzQueueMem = mKoszuls.getMemoryUse();
name << "Koszul queue:\n";
value << mic::ColumnPrinter::bytesInUnit(syzQueueMem) << '\n';
extra << mic::ColumnPrinter::percentInteger(syzQueueMem, total) << '\n';
diff --git a/src/mathicgb/SignatureGB.hpp b/src/mathicgb/SignatureGB.hpp
index 4177ae5..278f5b2 100755
--- a/src/mathicgb/SignatureGB.hpp
+++ b/src/mathicgb/SignatureGB.hpp
@@ -101,7 +101,7 @@ private:
double stats_nsecs;
std::unique_ptr<GroebnerBasis> GB;
- std::unique_ptr<KoszulQueue> mKoszuls;
+ KoszulQueue mKoszuls;
std::unique_ptr<MonomialTableArray> Hsyz;
std::unique_ptr<MonomialTableArray> Hsyz2;
std::unique_ptr<Reducer> reducer;
--
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