[mathicgb] 266/393: Reduced the interface for PolyRing and added release/recapture support for pool-allocated monomials.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:17 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 a990e638af935c59c666ae029f5f36b88d03252f
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Tue Apr 16 18:52:01 2013 -0400
Reduced the interface for PolyRing and added release/recapture support for pool-allocated monomials.
---
src/mathicgb/BuchbergerAlg.cpp | 8 --------
src/mathicgb/MonoMonoid.hpp | 35 +++++++++++++++++++++++++++++------
src/mathicgb/PolyRing.cpp | 24 ------------------------
src/mathicgb/PolyRing.hpp | 17 -----------------
src/mathicgb/SignatureGB.cpp | 8 --------
src/test/QuadMatrixBuilder.cpp | 2 +-
6 files changed, 30 insertions(+), 64 deletions(-)
diff --git a/src/mathicgb/BuchbergerAlg.cpp b/src/mathicgb/BuchbergerAlg.cpp
index d628009..27ef054 100755
--- a/src/mathicgb/BuchbergerAlg.cpp
+++ b/src/mathicgb/BuchbergerAlg.cpp
@@ -203,7 +203,6 @@ void BuchbergerAlg::insertReducedPoly(
void BuchbergerAlg::computeGrobnerBasis() {
size_t counter = 0;
mTimer.reset();
- mRing.resetCoefficientStats();
if (mUseAutoTailReduction)
autoTailReduce();
@@ -330,13 +329,6 @@ void BuchbergerAlg::printStats(std::ostream& out) const {
out << " total compute time: " << mTimer.getMilliseconds()/1000.0 << " seconds " << '\n';
out << " S-pair group size: " << mSPairGroupSize << '\n';
- const PolyRing::coefficientStats& cstats = mRing.getCoefficientStats();
- out << "n-coeff-add: " << cstats.n_add << '\n';
- out << "n-coeff-addmult: " << cstats.n_addmult << '\n';
- out << "n-coeff-mult: " << cstats.n_mult << '\n';
- out << "n-coeff-recip: " << cstats.n_recip << '\n';
- out << "n-coeff-divide: " << cstats.n_divide << '\n';
-
mic::ColumnPrinter pr;
pr.addColumn(true, " ");
pr.addColumn(false, " ");
diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index a8a3a39..0a64cb5 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -971,6 +971,16 @@ public:
public:
Mono(): mMono(), mPool(0) {}
+ /// Passes ownership of the resources of mono to this object. Mono must
+ /// have been allocated from pool and it must have no other owner.
+ /// In particular, it must have been release()'ed from its original
+ /// owner.
+ Mono(MonoRef mono, MonoPool& pool):
+ mMono(mono.ptr()), mPool(&pool)
+ {
+ MATHICGB_ASSERT(pool.fromPool(mono));
+ }
+
Mono(Mono&& mono): mMono(mono.mMono), mPool(mono.mPool) {
mono.mMono.toNull();
mono.mPool = 0;
@@ -987,7 +997,18 @@ public:
mPool = mono.mPool;
mono.mPool = 0;
}
-
+
+ /// Sets this object to null but does NOT free the resources previously
+ /// held by this object. The returned MonoPtr points to the resources
+ /// that this object had prior to calling release(). If this object was
+ /// already null then the returned MonoPtr is also null.
+ MonoPtr release() {
+ const auto oldPtr = ptr();
+ mMono = 0;
+ mPool = 0;
+ return oldPtr;
+ }
+
bool isNull() const {return mMono.isNull();}
void toNull() {mPool->free(*this);}
@@ -1001,9 +1022,6 @@ public:
private:
friend class MonoMonoid;
- Mono(const MonoPtr mono, MonoPool& pool):
- mMono(mono), mPool(&pool) {}
-
Exponent* internalRawPtr() const {return rawPtr(mMono);}
MonoPtr mMono;
@@ -1055,7 +1073,7 @@ public:
Mono alloc() {
const auto ptr = static_cast<Exponent*>(mPool.alloc());
- Mono mono(ptr, *this);
+ Mono mono(*MonoPtr(ptr), *this);
monoid().setIdentity(mono);
return mono;
}
@@ -1064,13 +1082,18 @@ public:
void free(Mono&& mono) {
if (mono.isNull())
return;
- mPool.free(rawPtr(mono));
+ freeRaw(mono);
mono.mMono = 0;
mono.mPool = 0;
}
+ void freeRaw(MonoRef mono) {mPool.free(rawPtr(mono));}
const MonoMonoid& monoid() const {return mMonoid;}
+ bool fromPool(ConstMonoRef mono) const {
+ return mPool.fromPool(rawPtr(mono));
+ }
+
private:
MonoPool(const MonoPool&); // not available
void operator=(const MonoPool&); // not available
diff --git a/src/mathicgb/PolyRing.cpp b/src/mathicgb/PolyRing.cpp
index 4f22bf0..6d3ca2c 100755
--- a/src/mathicgb/PolyRing.cpp
+++ b/src/mathicgb/PolyRing.cpp
@@ -14,8 +14,6 @@
PolyRing::PolyRing(const Field& field, const Monoid& monoid):
mField(field),
mMonoid(monoid),
- mNumWeights(monoid.gradingCount()),
- mTopIndex(monoid.varCount() + mNumWeights),
mMonomialPool(maxMonomialByteSize())
{
}
@@ -27,32 +25,10 @@ PolyRing::PolyRing(
):
mField(p0),
mMonoid(nvars, weights),
- mNumWeights(nvars == 0 ? 0 : weights.size() / nvars),
- mTopIndex(nvars + mNumWeights),
mMonomialPool(maxMonomialByteSize())
{
}
-PolyRing::PolyRing(coefficient p0,
- int nvars,
- int nweights):
- mField(p0),
- mMonoid(nvars),
- mNumWeights(nweights),
- mTopIndex(nvars + nweights),
- mMonomialPool(maxMonomialByteSize())
-{
-}
-
-void PolyRing::resetCoefficientStats() const
-{
- mStats.n_addmult = 0;
- mStats.n_add = 0;
- mStats.n_mult = 0;
- mStats.n_recip = 0;
- mStats.n_divide = 0;
-}
-
///////////////////////////////////////
// (New) Monomial Routines ////////////
///////////////////////////////////////
diff --git a/src/mathicgb/PolyRing.hpp b/src/mathicgb/PolyRing.hpp
index 84fe7d5..ac25a14 100755
--- a/src/mathicgb/PolyRing.hpp
+++ b/src/mathicgb/PolyRing.hpp
@@ -201,9 +201,7 @@ public:
typedef PrimeField<unsigned long> Field;
PolyRing(coefficient charac, int nvars, const std::vector<exponent>& weights);
- PolyRing(coefficient charac, int nvars, int nweights);
PolyRing(const Field& field, const Monoid& monoid);
- ~PolyRing() {}
size_t getMemoryUse() const {
// todo: Make this more accurate.
@@ -469,16 +467,6 @@ public:
///////////////////////////////////////////
///////////////////////////////////////////
- struct coefficientStats {
- size_t n_addmult;
- size_t n_add;
- size_t n_mult;
- size_t n_recip;
- size_t n_divide;
- };
- const coefficientStats & getCoefficientStats() const { return mStats; }
- void resetCoefficientStats() const;
-
const Monoid& monoid() const {return mMonoid;}
const Field field() const {return mField;}
@@ -486,12 +474,7 @@ private:
Field mField;
Monoid mMonoid;
- size_t mNumWeights;
- size_t mTopIndex;
-
mutable memt::BufferPool mMonomialPool;
- mutable coefficientStats mStats;
-
};
inline exponent PolyRing::weight(ConstMonomial a) const {
diff --git a/src/mathicgb/SignatureGB.cpp b/src/mathicgb/SignatureGB.cpp
index 31bfdc9..8dd90b8 100755
--- a/src/mathicgb/SignatureGB.cpp
+++ b/src/mathicgb/SignatureGB.cpp
@@ -17,7 +17,6 @@ void SignatureGB::computeGrobnerBasis()
size_t counter = 0;
mTimer.reset();
- R->resetCoefficientStats();
std::ostream& out = std::cout;
while (step()) {
@@ -306,13 +305,6 @@ void SignatureGB::displayStats(std::ostream &o) const
o << " syz-n-actual-inserts: " << (hsyz_stats.n_actual_inserts) << '\n';
o << " syz sig denseness: " << hsyz_stats.denseness << '\n';
- const PolyRing::coefficientStats& cstats = R->getCoefficientStats();
- o << "n-coeff-add: " << cstats.n_add << '\n';
- o << "n-coeff-addmult: " << cstats.n_addmult << '\n';
- o << "n-coeff-mult: " << cstats.n_mult << '\n';
- o << "n-coeff-recip: " << cstats.n_recip << '\n';
- o << "n-coeff-divide: " << cstats.n_divide << '\n';
-
displayMemoryUse(o);
displaySomeStats(o);
o << std::flush;
diff --git a/src/test/QuadMatrixBuilder.cpp b/src/test/QuadMatrixBuilder.cpp
index 413fba1..aa6f21b 100755
--- a/src/test/QuadMatrixBuilder.cpp
+++ b/src/test/QuadMatrixBuilder.cpp
@@ -56,7 +56,7 @@ namespace {
TEST(QuadMatrixBuilder, Empty) {
// test a builder with no rows and no columns
- PolyRing ring(2, 0, 1);
+ PolyRing ring(2, 0);
QuadMatrixBuilder::Map map(ring);
QuadMatrixBuilder::MonomialsType monoLeft;
QuadMatrixBuilder::MonomialsType monoRight;
--
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