[mathicgb] 329/393: Renamed to mgb::tbb to mgb::mtbb to avoid frequent issue of ambiguous resolution of tbb - it could be ::tbb or ::mgb::tbb in some cases, causing MSVC to complain.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:30 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 a5c8d7d091e5e64be38b255d4942ee0444cbc103
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Fri Aug 16 17:36:16 2013 +0200
Renamed to mgb::tbb to mgb::mtbb to avoid frequent issue of ambiguous resolution of tbb - it could be ::tbb or ::mgb::tbb in some cases, causing MSVC to complain.
---
src/checksource/CheckSource.cpp | 360 +++----
src/cli/CommonParams.cpp | 4 +-
src/cli/CommonParams.hpp | 2 +-
src/cli/MatrixAction.cpp | 18 +-
src/cli/SigGBAction.cpp | 24 +-
src/mathicgb.cpp | 1760 +++++++++++++++++------------------
src/mathicgb.h | 157 ++--
src/mathicgb/Atomic.hpp | 73 +-
src/mathicgb/Basis.hpp | 10 +-
src/mathicgb/CFile.hpp | 4 +-
src/mathicgb/DivisorLookup.hpp | 10 +-
src/mathicgb/F4MatrixBuilder.cpp | 47 +-
src/mathicgb/F4MatrixBuilder.hpp | 12 +-
src/mathicgb/F4MatrixBuilder2.cpp | 66 +-
src/mathicgb/F4MatrixBuilder2.hpp | 16 +-
src/mathicgb/F4MatrixProjection.cpp | 62 +-
src/mathicgb/F4MatrixProjection.hpp | 8 +-
src/mathicgb/F4MatrixReducer.cpp | 98 +-
src/mathicgb/F4ProtoMatrix.cpp | 12 +-
src/mathicgb/F4ProtoMatrix.hpp | 8 +-
src/mathicgb/F4Reducer.cpp | 64 +-
src/mathicgb/FixedSizeMonomialMap.h | 66 +-
src/mathicgb/LogDomain.cpp | 6 +-
src/mathicgb/LogDomain.hpp | 16 +-
src/mathicgb/LogDomainSet.cpp | 6 +-
src/mathicgb/LogDomainSet.hpp | 2 +-
src/mathicgb/MonoMonoid.hpp | 134 +--
src/mathicgb/MonoOrder.hpp | 12 +-
src/mathicgb/MonomialMap.hpp | 44 +-
src/mathicgb/Poly.hpp | 36 +-
src/mathicgb/PolyBasis.hpp | 18 +-
src/mathicgb/PolyRing.cpp | 2 +-
src/mathicgb/PolyRing.hpp | 28 +-
src/mathicgb/PrimeField.hpp | 24 +-
src/mathicgb/QuadMatrix.cpp | 56 +-
src/mathicgb/QuadMatrix.hpp | 26 +-
src/mathicgb/QuadMatrixBuilder.cpp | 27 +-
src/mathicgb/QuadMatrixBuilder.hpp | 10 +-
src/mathicgb/RawVector.hpp | 4 +-
src/mathicgb/Scanner.hpp | 4 +-
src/mathicgb/ScopeExit.hpp | 8 +-
src/mathicgb/SigSPairQueue.cpp | 408 ++++----
src/mathicgb/SignatureGB.cpp | 4 +-
src/mathicgb/SparseMatrix.cpp | 62 +-
src/mathicgb/SparseMatrix.hpp | 58 +-
src/mathicgb/io-util.cpp | 60 +-
src/mathicgb/io-util.hpp | 40 +-
src/mathicgb/mtbb.hpp | 31 +-
src/mathicgb/stdinc.h | 110 +--
src/test/F4MatrixBuilder.cpp | 24 +-
src/test/F4MatrixReducer.cpp | 2 +-
src/test/MonoMonoid.cpp | 13 +-
src/test/QuadMatrixBuilder.cpp | 18 +-
src/test/SparseMatrix.cpp | 6 +-
src/test/gb-test.cpp | 2 +-
src/test/mathicgb.cpp | 1196 ++++++++++++------------
56 files changed, 2687 insertions(+), 2691 deletions(-)
diff --git a/src/checksource/CheckSource.cpp b/src/checksource/CheckSource.cpp
index 3440b78..dd0b123 100755
--- a/src/checksource/CheckSource.cpp
+++ b/src/checksource/CheckSource.cpp
@@ -1,180 +1,180 @@
-// Program for checking format of code, with respect to proper
-// copyright header, no tabs, order of includes and so on.
-//
-// This code is not pretty, especially not the duplication of Scanner,
-// but this makes this whole thing easy to compile and this is VERY
-// quick-and-dirty code anyway. Anyone who wants to clean up thing up
-// with proper integration into the build system is more than welcome
-// to do so.
-#include "Scanner.cpp"
-
-#include <iostream>
-#include <sstream>
-#include <stdexcept>
-#include <fstream>
-#include <string>
-
-void error(std::string str) {
- throw std::runtime_error(str);
-}
-
-bool endsWith(const std::string& a, const std::string& b) {
- return a.size() >= b.size() && a.substr(a.size() - b.size()) == b;
-}
-
-bool matchInclude(Scanner& in, bool& system) {
- if (!in.match("#include "))
- return false;
-
- char delim = '\"';
- system = false;
- if (!in.match('\"')) {
- if (in.match('<')) {
- system = true;
- delim = '>';
- } else
- in.reportError("Expected < or \" after #include.");
- }
-
- in.readUntil(delim);
- in.expect(delim);
- return true;
-}
-
-std::string stripEnding(const std::string& str) {
- const auto index = str.find_last_of('.');
- if (index == std::string::npos)
- return str;
- else
- return str.substr(0, index);
-}
-
-
-
-void checkCopyrightHeader(Scanner& in) {
- const char* const l1 =
- "// MathicGB copyright 2012 all rights reserved. "
- "MathicGB comes with ABSOLUTELY\n";
- const char* const l2 =
- "// NO WARRANTY and is licensed as GPL v2.0 or later - see LICENSE.txt.\n";
- in.expect(l1);
- in.expect(l2);
-}
-
-void checkStdInc(Scanner& in) {
- in.eatWhite();
- if (!in.match("#include \"mathicgb/stdinc.h\"\n"))
- in.expect("#include \"stdinc.h\"\n");
-}
-
-void checkIncludes(Scanner& in) {
- bool sawSystem = false;
- bool system;
- while (matchInclude(in, system)) {
- if (sawSystem && !system)
- in.reportError("#include < > must come after all #include \" \".");
- sawSystem = system;
- }
-}
-
-void checkInclusionGuard(Scanner& in, const std::string& filename) {
- auto normalize = [](const std::string& str) {
- std::string norm;
- for (size_t i = 0; i < str.size(); ++i)
- if (str[i] != '_')
- norm += std::toupper(str[i]);
- return norm;
- };
-
- in.expect("#ifndef ");
- const auto macroName = in.readString();
- const auto fileNorm = normalize
- ("MATHICGB_" + stripEnding(filename) + "_GUARD");
-
- if (fileNorm != normalize(macroName)) {
- std::ostringstream err;
- err << "Inclusion guard name does not match file name.\n";
- err << "Normalization removes _ and converts to upper case.\n";
- err << " Filename normalizes to: " << fileNorm << '\n';
- err << "macro name normalizes to: " << normalize(macroName) << '\n';
- in.reportError(err.str());
- }
-
- in.expect("#define ");
- std::string macro2;
- macro2 = in.readString();
- if (macroName != macro2) {
- std::ostringstream out;
- out << "Inclusion guard #ifndef and #define macro name mismatch.\n";
- out << "#ifndef macro name: " << macroName << '\n';
- out << "#define macro name: " << macro2 << '\n';
- in.reportError(out.str());
- }
-}
-
-void checkOther(const std::string& filename) {
- std::ifstream file(filename.c_str(), std::ios_base::binary);
- file.peek();
- if (!file)
- error("could not open file");
- Scanner in(file);
- bool mgbNamespace = false;
- while (!in.matchEOF()) {
- if (in.peek() == '\r')
- in.reportError("File contains dos/windows line ending character \\r.");
- if (in.peek() == '\t')
- in.reportError("File contains a tab.");
- if (
- in.match("Local Variables:") ||
- in.match("compile-command:") ||
- in.match("indent-tabs-mode:")
- )
- in.reportError("File contains emacs-specific command comments.");
- if (in.match("namespace mgb") || in.match("MATHICGB_NAMESPACE_BEGIN"))
- mgbNamespace = true;
- else
- in.get();
- }
- if (!mgbNamespace)
- in.reportError("MATHICGB_NAMESPACE_BEGIN does not appear in file");
-}
-
-void checkFile(std::string filename) {
- try {
- std::cout << "Checking file " << filename << std::endl;
- const bool hpp = endsWith(filename, ".hpp");
- const bool cpp = endsWith(filename, ".cpp");
- if (!hpp && !cpp)
- return;
- checkOther(filename);
-
- std::ifstream file(filename.c_str());
- if (!file)
- error("could not open file");
- Scanner in(file);
-
- if (in.peekWhite())
- in.reportError
- ("File should start with copyright header, not whitespace.");
-
- checkCopyrightHeader(in);
- if (in.peekWhite())
- in.reportError
- ("There should not be whitespace after the copyright header.");
-
- if (cpp)
- checkStdInc(in);
- else
- checkInclusionGuard(in, filename);
- checkIncludes(in);
- } catch (std::exception& e) {
- std::cout << "*** ERROR in file " << filename << " ***\n"
- << e.what() << std::endl;
- }
-}
-
-int main(int argc, char* argv[]) {
- for (int i = 1; i < argc; ++i)
- checkFile(argv[i]);
- return 0;
-}
+// Program for checking format of code, with respect to proper
+// copyright header, no tabs, order of includes and so on.
+//
+// This code is not pretty, especially not the duplication of Scanner,
+// but this makes this whole thing easy to compile and this is VERY
+// quick-and-dirty code anyway. Anyone who wants to clean up thing up
+// with proper integration into the build system is more than welcome
+// to do so.
+#include "Scanner.cpp"
+
+#include <iostream>
+#include <sstream>
+#include <stdexcept>
+#include <fstream>
+#include <string>
+
+void error(std::string str) {
+ throw std::runtime_error(str);
+}
+
+bool endsWith(const std::string& a, const std::string& b) {
+ return a.size() >= b.size() && a.substr(a.size() - b.size()) == b;
+}
+
+bool matchInclude(Scanner& in, bool& system) {
+ if (!in.match("#include "))
+ return false;
+
+ char delim = '\"';
+ system = false;
+ if (!in.match('\"')) {
+ if (in.match('<')) {
+ system = true;
+ delim = '>';
+ } else
+ in.reportError("Expected < or \" after #include.");
+ }
+
+ in.readUntil(delim);
+ in.expect(delim);
+ return true;
+}
+
+std::string stripEnding(const std::string& str) {
+ const auto index = str.find_last_of('.');
+ if (index == std::string::npos)
+ return str;
+ else
+ return str.substr(0, index);
+}
+
+
+
+void checkCopyrightHeader(Scanner& in) {
+ const char* const l1 =
+ "// MathicGB copyright 2012 all rights reserved. "
+ "MathicGB comes with ABSOLUTELY\n";
+ const char* const l2 =
+ "// NO WARRANTY and is licensed as GPL v2.0 or later - see LICENSE.txt.\n";
+ in.expect(l1);
+ in.expect(l2);
+}
+
+void checkStdInc(Scanner& in) {
+ in.eatWhite();
+ if (!in.match("#include \"mathicgb/stdinc.h\"\n"))
+ in.expect("#include \"stdinc.h\"\n");
+}
+
+void checkIncludes(Scanner& in) {
+ bool sawSystem = false;
+ bool system;
+ while (matchInclude(in, system)) {
+ if (sawSystem && !system)
+ in.reportError("#include < > must come after all #include \" \".");
+ sawSystem = system;
+ }
+}
+
+void checkInclusionGuard(Scanner& in, const std::string& filename) {
+ auto normalize = [](const std::string& str) {
+ std::string norm;
+ for (size_t i = 0; i < str.size(); ++i)
+ if (str[i] != '_')
+ norm += std::toupper(str[i]);
+ return norm;
+ };
+
+ in.expect("#ifndef ");
+ const auto macroName = in.readString();
+ const auto fileNorm = normalize
+ ("MATHICGB_" + stripEnding(filename) + "_GUARD");
+
+ if (fileNorm != normalize(macroName)) {
+ std::ostringstream err;
+ err << "Inclusion guard name does not match file name.\n";
+ err << "Normalization removes _ and converts to upper case.\n";
+ err << " Filename normalizes to: " << fileNorm << '\n';
+ err << "macro name normalizes to: " << normalize(macroName) << '\n';
+ in.reportError(err.str());
+ }
+
+ in.expect("#define ");
+ std::string macro2;
+ macro2 = in.readString();
+ if (macroName != macro2) {
+ std::ostringstream out;
+ out << "Inclusion guard #ifndef and #define macro name mismatch.\n";
+ out << "#ifndef macro name: " << macroName << '\n';
+ out << "#define macro name: " << macro2 << '\n';
+ in.reportError(out.str());
+ }
+}
+
+void checkOther(const std::string& filename) {
+ std::ifstream file(filename.c_str(), std::ios_base::binary);
+ file.peek();
+ if (!file)
+ error("could not open file");
+ Scanner in(file);
+ bool mgbNamespace = false;
+ while (!in.matchEOF()) {
+ if (in.peek() == '\r')
+ in.reportError("File contains dos/windows line ending character \\r.");
+ if (in.peek() == '\t')
+ in.reportError("File contains a tab.");
+ if (
+ in.match("Local Variables:") ||
+ in.match("compile-command:") ||
+ in.match("indent-tabs-mode:")
+ )
+ in.reportError("File contains emacs-specific command comments.");
+ if (in.match("namespace mgb") || in.match("MATHICGB_NAMESPACE_BEGIN"))
+ mgbNamespace = true;
+ else
+ in.get();
+ }
+ if (!mgbNamespace)
+ in.reportError("MATHICGB_NAMESPACE_BEGIN does not appear in file");
+}
+
+void checkFile(std::string filename) {
+ try {
+ std::cout << "Checking file " << filename << std::endl;
+ const bool hpp = endsWith(filename, ".hpp");
+ const bool cpp = endsWith(filename, ".cpp");
+ if (!hpp && !cpp)
+ return;
+ checkOther(filename);
+
+ std::ifstream file(filename.c_str());
+ if (!file)
+ error("could not open file");
+ Scanner in(file);
+
+ if (in.peekWhite())
+ in.reportError
+ ("File should start with copyright header, not whitespace.");
+
+ checkCopyrightHeader(in);
+ if (in.peekWhite())
+ in.reportError
+ ("There should not be whitespace after the copyright header.");
+
+ if (cpp)
+ checkStdInc(in);
+ else
+ checkInclusionGuard(in, filename);
+ checkIncludes(in);
+ } catch (std::exception& e) {
+ std::cout << "*** ERROR in file " << filename << " ***\n"
+ << e.what() << std::endl;
+ }
+}
+
+int main(int argc, char* argv[]) {
+ for (int i = 1; i < argc; ++i)
+ checkFile(argv[i]);
+ return 0;
+}
diff --git a/src/cli/CommonParams.cpp b/src/cli/CommonParams.cpp
index 29e7786..dcd6fb1 100755
--- a/src/cli/CommonParams.cpp
+++ b/src/cli/CommonParams.cpp
@@ -60,9 +60,9 @@ void CommonParams::perform() {
// delete the old init object first to make the new one take control.
mTbbInit.reset();
- mTbbInit = make_unique<mgb::tbb::task_scheduler_init>(
+ mTbbInit = make_unique<mgb::mtbb::task_scheduler_init>(
mThreadCount.value() == 0 ?
- mgb::tbb::task_scheduler_init::automatic :
+ mgb::mtbb::task_scheduler_init::automatic :
mThreadCount.value()
);
}
diff --git a/src/cli/CommonParams.hpp b/src/cli/CommonParams.hpp
index 9357eff..d0b0f07 100755
--- a/src/cli/CommonParams.hpp
+++ b/src/cli/CommonParams.hpp
@@ -48,7 +48,7 @@ private:
std::vector<std::string> mExtensions; /// to recognize file type
/// to set thread count
- std::unique_ptr<mgb::tbb::task_scheduler_init> mTbbInit;
+ std::unique_ptr<mgb::mtbb::task_scheduler_init> mTbbInit;
std::size_t mMinDirectParams;
std::size_t mMaxDirectParams;
std::vector<std::string> mDirectParameters;
diff --git a/src/cli/MatrixAction.cpp b/src/cli/MatrixAction.cpp
index d81b441..382716f 100755
--- a/src/cli/MatrixAction.cpp
+++ b/src/cli/MatrixAction.cpp
@@ -28,13 +28,13 @@ namespace {
/// portable. There could be a solution with freopen, but unfortunately
/// freopen is allowed to fail on any change to the mode so it is not
/// a portable solution.
- bool fileExists(const ::std::string fileName) {
+ bool fileExists(const std::string fileName) {
return CFile(fileName, "r", CFile::NoThrowTag()).hasFile();
}
}
MatrixAction::MatrixAction():
- mParams(1, ::std::numeric_limits<size_t>::max()) {
+ mParams(1, std::numeric_limits<size_t>::max()) {
mParams.registerFileNameExtension(QuadMatrixExtension);
mParams.registerFileNameExtension(LowerRightMatrixExtension);
mParams.registerFileNameExtension(ReducedLowerRightMatrixExtension);
@@ -42,7 +42,7 @@ MatrixAction::MatrixAction():
}
void MatrixAction::directOptions(
- ::std::vector< ::std::string> tokens,
+ std::vector< std::string> tokens,
mic::CliParser& parser
) {
mParams.directOptions(tokens, parser);
@@ -57,7 +57,7 @@ void MatrixAction::performAction() {
const auto lowerRightFileName = fileNameStem + LowerRightMatrixExtension;
const auto reducedLowerRightFileName =
fileNameStem + ReducedLowerRightMatrixExtension;
- ::std::string inputFileName;
+ std::string inputFileName;
SparseMatrix lowerRightMatrix;
SparseMatrix::Scalar modulus;
@@ -103,10 +103,10 @@ void MatrixAction::performAction() {
referenceMatrix.read(file.handle());
if (lowerRightMatrix != referenceMatrix) {
- const ::std::string wrongFile =
+ const std::string wrongFile =
fileNameStem + ".out" + ReducedLowerRightMatrixExtension;
- const ::std::string wrongFilePbm = fileNameStem + ".out.pbm";
- ::std::cerr << "Reducing " << inputFileName
+ const std::string wrongFilePbm = fileNameStem + ".out.pbm";
+ std::cerr << "Reducing " << inputFileName
<< " does not yield the matrix "
<< reducedLowerRightFileName << ".\n"
<< "Writing computed matrix to " << wrongFile << ".\n";
@@ -115,7 +115,7 @@ void MatrixAction::performAction() {
CFile filePbm(wrongFilePbm, "wb");
lowerRightMatrix.writePBM(filePbm.handle());
} else if (tracingLevel > 0) {
- ::std::cerr << "Match for " << inputFileName
+ std::cerr << "Match for " << inputFileName
<< " -> " << ReducedLowerRightMatrixExtension << ".\n";
}
}
@@ -140,7 +140,7 @@ const char* MatrixAction::shortDescription() const {
}
void MatrixAction::pushBackParameters(
- ::std::vector<mic::CliParameter*>& parameters
+ std::vector<mic::CliParameter*>& parameters
) {
mParams.pushBackParameters(parameters);
}
diff --git a/src/cli/SigGBAction.cpp b/src/cli/SigGBAction.cpp
index a18a587..a3646ee 100755
--- a/src/cli/SigGBAction.cpp
+++ b/src/cli/SigGBAction.cpp
@@ -34,7 +34,7 @@ SigGBAction::SigGBAction():
{}
void SigGBAction::directOptions(
- ::std::vector< ::std::string> tokens,
+ std::vector< std::string> tokens,
mic::CliParser& parser
) {
mParams.directOptions(tokens, parser);
@@ -45,8 +45,8 @@ void SigGBAction::performAction() {
mGBParams.perform();
// read input file
- const ::std::string inputBasisFile = mParams.inputFileNameStem(0) + ".ideal";
- ::std::ifstream inputFile(inputBasisFile.c_str());
+ const std::string inputBasisFile = mParams.inputFileNameStem(0) + ".ideal";
+ std::ifstream inputFile(inputBasisFile.c_str());
if (inputFile.fail())
mic::reportError("Could not read input file \"" + inputBasisFile + '\n');
@@ -60,8 +60,8 @@ void SigGBAction::performAction() {
processor.setSchreyerMultipliers(basis);
SignatureGB alg(
- ::std::move(basis),
- ::std::move(processor),
+ std::move(basis),
+ std::move(processor),
Reducer::reducerType(mGBParams.mReducer.value()),
mGBParams.mDivisorLookup.value(),
mGBParams.mMonomialTable.value(),
@@ -75,10 +75,10 @@ void SigGBAction::performAction() {
alg.computeGrobnerBasis();
// print statistics
- alg.displayStats(::std::cout);
- alg.displayPaperStats(::std::cout);
+ alg.displayStats(std::cout);
+ alg.displayPaperStats(std::cout);
{
- ::std::ofstream statsOut((mParams.inputFileNameStem(0) + ".stats").c_str());
+ std::ofstream statsOut((mParams.inputFileNameStem(0) + ".stats").c_str());
alg.displayStats(statsOut);
alg.displayPaperStats(statsOut);
}
@@ -87,17 +87,17 @@ void SigGBAction::performAction() {
{
// print basis
{
- ::std::ofstream ogb((mParams.inputFileNameStem(0) + ".gb").c_str());
+ std::ofstream ogb((mParams.inputFileNameStem(0) + ".gb").c_str());
ogb << "-- gb: ----\n";
alg.getGB()->display(ogb);
}
// print syzygy basis
{
- ::std::ofstream syzygyOut((mParams.inputFileNameStem(0) + ".syz").c_str());
+ std::ofstream syzygyOut((mParams.inputFileNameStem(0) + ".syz").c_str());
syzygyOut << "-- syz: ----\n";
alg.getSyzTable()->display(syzygyOut, 1);
- syzygyOut << ::std::endl;
+ syzygyOut << std::endl;
}
}
}
@@ -120,7 +120,7 @@ const char* SigGBAction::shortDescription() const {
}
void SigGBAction::pushBackParameters(
- ::std::vector<mic::CliParameter*>& parameters
+ std::vector<mic::CliParameter*>& parameters
) {
mParams.pushBackParameters(parameters);
mGBParams.pushBackParameters(parameters);
diff --git a/src/mathicgb.cpp b/src/mathicgb.cpp
index ef51684..53001e0 100755
--- a/src/mathicgb.cpp
+++ b/src/mathicgb.cpp
@@ -1,881 +1,879 @@
-#include "mathicgb/stdinc.h"
-#include "mathicgb.h"
-
-#include "mathicgb/Basis.hpp"
-#include "mathicgb/PolyRing.hpp"
-#include "mathicgb/Poly.hpp"
-#include "mathicgb/Reducer.hpp"
-#include "mathicgb/ClassicGBAlg.hpp"
-#include "mathicgb/mtbb.hpp"
-#include "mathicgb/LogDomainSet.hpp"
-#include <mathic.h>
-
-extern "C" {
- void libmathicgbIsPresent(void) {}
-}
-
-using namespace mgb;
-
-namespace {
- bool isPrime(unsigned int n) {
- if (n == 0 || n == 1)
- return false;
- if (n == 2 || n == 3)
- return true;
- return true; // todo: make better test
- }
-};
-
-#ifndef MATHICGB_ASSERT
-#ifdef MATHICGB_DEBUG
-#include <cassert>
-#define MATHICGB_ASSERT(X) assert(X)
-#else
-#define MATHICGB_ASSERT(X)
-#endif
-#endif
-
-namespace mgb {
- bool logTime(const char* logName, double& time) {
- auto log = LogDomainSet::singleton().logDomain(logName);
- if (log == 0 || !log->enabled())
- return false;
- time = log->loggedSecondsReal();
- return true;
- }
-
- bool logNumber(const char* logName, double& number) {
- auto log = LogDomainSet::singleton().logDomain(logName);
- if (log == 0 || !log->enabled())
- return false;
- number = static_cast<double>(log->count());
- return true;
- }
-}
-
-#define MATHICGB_STREAM_CHECK(X, MSG) \
- do { \
- const bool value = (X); \
- if (!value) { \
- const bool ignoreMe = false; \
- MATHICGB_ASSERT(( \
- "MathicGB stream protocol error: "#MSG \
- "\nAssert expression: "#X"\n", \
- false \
- )); \
- throw std::invalid_argument( \
- "MathicGB stream protocol error: "#MSG \
- "\nAssert expression: "#X"\n" \
- ); \
- } \
- } while (false)
-
-namespace mgbi {
- struct StreamStateChecker::Pimpl {
- Pimpl(Coefficient modulus, VarIndex varCount):
- modulus(modulus),
- varCount(varCount),
- state(Initial),
-
- hasClaimedPolyCount(false),
- claimedPolyCount(0),
- seenPolyCount(0),
-
- hasClaimedTermCount(false),
- claimedTermCount(0),
- seenTermCount(0),
-
- lastVar(0)
- {}
-
- bool debugAssertValid() const;
-
- enum State {
- Initial,
- MakingIdeal,
- MakingPoly,
- MakingTerm,
- HasIdeal
- };
-
- const Coefficient modulus;
- const VarIndex varCount;
-
- State state;
-
- bool hasClaimedPolyCount;
- size_t claimedPolyCount;
- size_t seenPolyCount;
-
- bool hasClaimedTermCount;
- size_t claimedTermCount;
- size_t seenTermCount;
-
- VarIndex lastVar;
- };
-
- bool StreamStateChecker::Pimpl::debugAssertValid() const {
-#ifdef MATHICGB_DEBUG
- MATHICGB_ASSERT(this != 0);
- switch (state) {
- case Initial:
- case MakingIdeal:
- case MakingPoly:
- case MakingTerm:
- case HasIdeal:
- break;
-
- default:
- MATHICGB_ASSERT(false);
- return false;
- }
-#endif
- return true;
- };
-
- StreamStateChecker::StreamStateChecker(const Coefficient modulus, const VarIndex varCount):
- mPimpl(new Pimpl(modulus, varCount))
- {
- try {
- MATHICGB_STREAM_CHECK(isPrime(modulus), "The modulus must be prime");
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- } catch (...) {
- delete mPimpl;
- }
- }
-
- StreamStateChecker::~StreamStateChecker() {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- delete mPimpl;
- }
-
- void StreamStateChecker::idealBegin() {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
-
- MATHICGB_STREAM_CHECK(
- mPimpl->state == Pimpl::Initial || mPimpl->state == Pimpl::HasIdeal,
- "idealBegin() must not be called twice "
- "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() {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
-
- MATHICGB_STREAM_CHECK(
- mPimpl->state != Pimpl::Initial && mPimpl->state != Pimpl::HasIdeal,
- "appendPolynomialBegin() must only be called after idealBegin() and "
- "before idealEnd()."
- );
- MATHICGB_STREAM_CHECK(
- mPimpl->state == Pimpl::MakingIdeal,
- "appendPolynomialBegin() must not be called twice without "
- "an intervening call to appendPolynomialDone()."
- );
- MATHICGB_STREAM_CHECK(
- !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;
-
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- }
-
- void StreamStateChecker::appendTermBegin() {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
-
- MATHICGB_STREAM_CHECK(
- mPimpl->state != Pimpl::Initial &&
- mPimpl->state != Pimpl::HasIdeal &&
- mPimpl->state != Pimpl::MakingIdeal,
- "appendTermBegin() must only be called after appendPolynomialBegin() "
- "and before appendPolynomialDone()."
- );
- MATHICGB_STREAM_CHECK(
- mPimpl->state == Pimpl::MakingPoly,
- "appendTermBegin() must not be called twice without an intervening "
- "call to appendTermDone()."
- );
- MATHICGB_STREAM_CHECK(
- !mPimpl->hasClaimedTermCount ||
- mPimpl->seenTermCount < mPimpl->claimedTermCount,
- "The number of terms in a polynomial must not exceed the amount "
- "passed to appendPolynomialBegin()."
- );
-
- mPimpl->state = Pimpl::MakingTerm;
- mPimpl->seenTermCount += 1;
- mPimpl->lastVar = std::numeric_limits<decltype(mPimpl->lastVar)>::max();
-
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- }
-
- void StreamStateChecker::appendExponent(VarIndex index, Exponent exponent) {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
-
- MATHICGB_STREAM_CHECK(
- mPimpl->state == Pimpl::MakingTerm,
- "appendExponent must only be called after appendTermBegin() and before "
- "appendTermDone()."
- );
- MATHICGB_STREAM_CHECK(
- index < mPimpl->varCount,
- "The index passed to appendExponent must be strictly less than "
- "the number of variables."
- );
- MATHICGB_STREAM_CHECK(
- mPimpl->lastVar ==
- std::numeric_limits<decltype(mPimpl->lastVar)>::max() ||
- mPimpl->lastVar < index,
- "The variable indices passed to appendExponent must be in strictly "
- "increasing order within each monomial."
- );
-
- mPimpl->lastVar = index;
-
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- }
-
- void StreamStateChecker::appendTermDone(Coefficient coefficient) {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
-
- MATHICGB_STREAM_CHECK(
- coefficient > 0,
- "The coefficient passed to appendTermDone() must be strictly positive."
- );
- MATHICGB_STREAM_CHECK(
- coefficient < mPimpl->modulus,
- "The coefficient passed to appendTermDone() must be strictly less "
- "then the modulus."
- );
- MATHICGB_STREAM_CHECK(
- mPimpl->state == Pimpl::MakingTerm,
- "appendTermDone() must only be called after appendTermBegin()."
- );
- mPimpl->state = Pimpl::MakingPoly;
-
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- }
-
- void StreamStateChecker::appendPolynomialDone() {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
-
- MATHICGB_STREAM_CHECK(
- mPimpl->state == Pimpl::MakingPoly,
- "appendPolynomialDone() must only be called after appendPolynomialBegin()."
- );
- MATHICGB_STREAM_CHECK(
- !mPimpl->hasClaimedTermCount ||
- mPimpl->seenTermCount == mPimpl->claimedTermCount,
- "The number of terms in a polynomial must match the amount "
- "passed to appendPolynomialBegin()."
- );
- mPimpl->state = Pimpl::MakingIdeal;
-
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- }
-
- void StreamStateChecker::idealDone() {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
-
- MATHICGB_STREAM_CHECK(
- mPimpl->state == Pimpl::MakingIdeal,
- "idealDone() must only be called after idealBegin()."
- );
- MATHICGB_STREAM_CHECK(
- !mPimpl->hasClaimedPolyCount ||
- mPimpl->seenPolyCount == mPimpl->claimedPolyCount,
- "The number of polynomials in an ideal must match the amount "
- "passed to idealBegin()."
- );
-
- mPimpl->state = Pimpl::HasIdeal;
-
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- }
-
- bool StreamStateChecker::hasIdeal() const {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- return mPimpl->state == Pimpl::HasIdeal;
- }
-}
-
-namespace mgb {
- // ** Implementation of the class GroebnerConfiguration
-
- struct GroebnerConfiguration::Pimpl {
- Pimpl(Coefficient modulus, VarIndex varCount):
- mModulus(modulus),
- mVarCount(varCount),
- mBaseOrder(ReverseLexicographicBaseOrder),
- mGradings(varCount, 1),
- mComponentBefore(ComponentAfterBaseOrder),
- mComponentsAscending(true),
- mSchreyering(true),
- mReducer(DefaultReducer),
- mMaxSPairGroupSize(0),
- mMaxThreadCount(0),
- mLogging(),
- mCallbackData(0),
- mCallback(0)
-#ifdef MATHICGB_DEBUG
- , mHasBeenDestroyed(false)
-#endif
- {
- }
-
- ~Pimpl() {
- MATHICGB_ASSERT(debugAssertValid());
- MATHICGB_IF_DEBUG(mHasBeenDestroyed = true;)
- }
-
- static bool baseOrderValid(const BaseOrder order) {
- return
- order == LexicographicBaseOrder ||
- order == ReverseLexicographicBaseOrder;
- }
-
- static bool reducerValid(const Reducer reducer) {
- return
- reducer == DefaultReducer ||
- reducer == ClassicReducer ||
- reducer == MatrixReducer;
- }
-
- bool debugAssertValid() const {
-#ifdef MATHICGB_DEBUG
- MATHICGB_ASSERT(this != 0);
- MATHICGB_ASSERT(baseOrderValid(mBaseOrder));
- MATHICGB_ASSERT(reducerValid(mReducer));
- MATHICGB_ASSERT(mModulus != 0);
- MATHICGB_ASSERT(mCallback != 0 || mCallbackData == 0);
- MATHICGB_ASSERT_NO_ASSUME(!mHasBeenDestroyed);
-#endif
- return true;
- }
-
- const Coefficient mModulus;
- const VarIndex mVarCount;
- BaseOrder mBaseOrder;
- std::vector<Exponent> mGradings;
- size_t mComponentBefore;
- bool mComponentsAscending;
- bool mSchreyering;
- Reducer mReducer;
- unsigned int mMaxSPairGroupSize;
- unsigned int mMaxThreadCount;
- std::string mLogging;
- void* mCallbackData;
- Callback::Action (*mCallback) (void*);
- MATHICGB_IF_DEBUG(bool mHasBeenDestroyed);
- };
-
- GroebnerConfiguration::GroebnerConfiguration(
- Coefficient modulus,
- VarIndex varCount
- ):
- mPimpl(new Pimpl(modulus, varCount))
- {
- if (modulus > std::numeric_limits<unsigned short>::max()) {
- MATHICGB_ASSERT_NO_ASSUME(false);
- std::ostringstream str;
- str << "Modulus " << modulus
- << " is too large. MathicGB only supports 16 bit moduli.";
- mathic::reportError(str.str());
- }
- if (!isPrime(modulus)) {
- MATHICGB_ASSERT_NO_ASSUME(false);
- std::ostringstream str;
- str << "Modulus " << modulus
- << " is not prime. MathicGB only supports prime fields.";
- mathic::reportError(str.str());
- }
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- }
-
- GroebnerConfiguration::GroebnerConfiguration(
- const GroebnerConfiguration& conf
- ):
- mPimpl(new Pimpl(*conf.mPimpl))
- {
- MATHICGB_ASSERT(conf.mPimpl->debugAssertValid());
- }
-
- GroebnerConfiguration::~GroebnerConfiguration() {
- MATHICGB_ASSERT(mPimpl->debugAssertValid());
- delete mPimpl;
- }
-
- auto GroebnerConfiguration::modulus() const -> Coefficient {
- return mPimpl->mModulus;
- }
-
- auto GroebnerConfiguration::varCount() const -> VarIndex {
- return mPimpl->mVarCount;
- }
-
- bool GroebnerConfiguration::setMonomialOrderInternal(
- MonomialOrderData order
- ) {
- MATHICGB_ASSERT(Pimpl::baseOrderValid(order.baseOrder));
- MATHICGB_ASSERT(varCount() != 0 || order.gradingsSize == 0);
- MATHICGB_ASSERT(varCount() == 0 || order.gradingsSize % varCount() == 0);
-
- // Check if order is global.
- if (varCount() != 0) {
- const size_t rowCount = order.gradingsSize / varCount();
- for (VarIndex var = 0; var < varCount(); ++var) {
- // check if 1 < x_var.
- for (size_t row = 0; row < rowCount; ++row) {
- const Exponent e = order.gradings[row * varCount() + var];
- if (e < 0)
- return false; // order not global
- if (e > 0)
- goto orderGlobalForVar;
- }
- if (order.baseOrder == ReverseLexicographicBaseOrder)
- return false; // order not global
- orderGlobalForVar:;
- }
- }
-
- mPimpl->mBaseOrder = order.baseOrder;
- mPimpl->mGradings.assign
- (order.gradings, order.gradings + order.gradingsSize);
- return true;
- }
-
- auto GroebnerConfiguration::monomialOrderInternal() const ->
- MonomialOrderData
- {
- const MonomialOrderData data = {
- mPimpl->mBaseOrder,
- mPimpl->mGradings.data(),
- mPimpl->mGradings.size()
- };
- return data;
- }
-
- void GroebnerConfiguration::setCallbackInternal(
- void* data,
- Callback::Action (*func) (void*)
- ) {
- MATHICGB_ASSERT(func != 0 || data == 0);
- mPimpl->mCallbackData = data;
- mPimpl->mCallback = func;
- }
-
- void* GroebnerConfiguration::callbackDataInternal() const {
- return mPimpl->mCallbackData;
- }
-
- void GroebnerConfiguration::setComponentBefore(size_t value) {
- mPimpl->mComponentBefore = value;
- }
-
- size_t GroebnerConfiguration::componentBefore() const {
- return mPimpl->mComponentBefore;
- }
-
- void GroebnerConfiguration::setComponentsAscending(bool value) {
- mPimpl->mComponentsAscending = value;
- }
-
- bool GroebnerConfiguration::componentsAscending() const {
- return mPimpl->mComponentsAscending;
- }
-
- void GroebnerConfiguration::setSchreyering(bool value) {
- mPimpl->mSchreyering = value;
- }
-
- bool GroebnerConfiguration::schreyering() const {
- return mPimpl->mSchreyering;
- }
-
- void GroebnerConfiguration::setReducer(Reducer reducer) {
- MATHICGB_ASSERT(Pimpl::reducerValid(reducer));
- mPimpl->mReducer = reducer;
- }
-
- auto GroebnerConfiguration::reducer() const -> Reducer {
- return mPimpl->mReducer;
- }
-
- void GroebnerConfiguration::setMaxSPairGroupSize(unsigned int size) {
- mPimpl->mMaxSPairGroupSize = size;
- }
-
- uint32 GroebnerConfiguration::maxSPairGroupSize() const {
- return mPimpl->mMaxSPairGroupSize;
- }
-
- void GroebnerConfiguration::setMaxThreadCount(unsigned int maxThreadCount) {
- mPimpl->mMaxThreadCount = maxThreadCount;
- }
-
- unsigned int GroebnerConfiguration::maxThreadCount() const {
- return mPimpl->mMaxThreadCount;
- }
-
- void GroebnerConfiguration::setLogging(const char* logging) {
- if (logging == 0)
- mPimpl->mLogging.clear();
- else
- mPimpl->mLogging = logging;
- }
-
- const char* GroebnerConfiguration::logging() const {
- return mPimpl->mLogging.c_str();
- }
-}
-
-// ** Implementation of class GroebnerInputIdealStream
-namespace mgb {
- struct GroebnerInputIdealStream::Pimpl {
- Pimpl(const GroebnerConfiguration& conf):
- ring(
- PolyRing::Field(conf.modulus()),
- PolyRing::Monoid::Order(
- conf.varCount(),
- std::move(conf.monomialOrder().second),
- conf.monomialOrder().first ==
- GroebnerConfiguration::LexicographicBaseOrder ?
- PolyRing::Monoid::Order::LexBaseOrder :
- PolyRing::Monoid::Order::RevLexBaseOrder,
- conf.componentBefore(),
- conf.componentsAscending(),
- conf.schreyering()
- )
- ),
- basis(ring),
- poly(ring),
- monomial(ring.allocMonomial()),
- conf(conf)
-#ifdef MATHICGB_DEBUG
- , hasBeenDestroyed(false),
- checker(conf.modulus(), conf.varCount())
-#endif
- {}
-
- ~Pimpl() {
- ring.freeMonomial(monomial);
- }
-
- const PolyRing ring;
- Basis basis;
- Poly poly;
- Monomial monomial;
- const GroebnerConfiguration conf;
- MATHICGB_IF_DEBUG(bool hasBeenDestroyed);
- MATHICGB_IF_DEBUG(::mgbi::StreamStateChecker checker);
- };
-
- GroebnerInputIdealStream::GroebnerInputIdealStream(
- const GroebnerConfiguration& conf
- ):
- mExponents(new Exponent[conf.varCount()]),
- mPimpl(new Pimpl(conf))
- {
- MATHICGB_ASSERT(debugAssertValid());
- }
-
- GroebnerInputIdealStream::~GroebnerInputIdealStream() {
- MATHICGB_ASSERT(debugAssertValid());
- MATHICGB_ASSERT(mExponents != 0);
- MATHICGB_ASSERT(mPimpl != 0);
- MATHICGB_ASSERT_NO_ASSUME(!mPimpl->hasBeenDestroyed);
- MATHICGB_IF_DEBUG(mPimpl->hasBeenDestroyed = true);
- delete mPimpl;
- delete[] mExponents;
- }
-
- const GroebnerConfiguration& GroebnerInputIdealStream::configuration() {
- return mPimpl->conf;
- }
-
- auto GroebnerInputIdealStream::modulus() const -> Coefficient {
- return mPimpl->conf.modulus();
- }
-
- auto GroebnerInputIdealStream::varCount() const -> VarIndex {
- return mPimpl->conf.varCount();
- }
-
- void GroebnerInputIdealStream::idealBegin() {
- MATHICGB_ASSERT(debugAssertValid());
- MATHICGB_IF_DEBUG(mPimpl->checker.idealBegin());
- MATHICGB_ASSERT(mPimpl->poly.isZero());
- MATHICGB_ASSERT(mPimpl->basis.empty());
-
- MATHICGB_ASSERT(debugAssertValid());
- }
-
- void GroebnerInputIdealStream::idealBegin(size_t polyCount) {
- MATHICGB_ASSERT(debugAssertValid());
- MATHICGB_IF_DEBUG(mPimpl->checker.idealBegin(polyCount));
- MATHICGB_ASSERT(mPimpl->poly.isZero());
- MATHICGB_ASSERT(mPimpl->basis.empty());
-
- mPimpl->basis.reserve(polyCount);
-
- 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));
- MATHICGB_ASSERT(mPimpl->poly.isZero());
-
- mPimpl->poly.reserve(termCount);
-
- MATHICGB_ASSERT(debugAssertValid());
- }
-
- void GroebnerInputIdealStream::appendTermBegin() {
- MATHICGB_ASSERT(debugAssertValid());
- MATHICGB_IF_DEBUG(mPimpl->checker.appendTermBegin());
-
- std::fill_n(mExponents, varCount(), 0);
-
- MATHICGB_ASSERT(debugAssertValid());
- }
-
- void GroebnerInputIdealStream::appendTermDone(Coefficient coefficient) {
- MATHICGB_ASSERT(debugAssertValid());
- MATHICGB_IF_DEBUG(mPimpl->checker.appendTermDone(coefficient));
-
- // @todo: do this directly into the polynomial instead of copying a second
- // time.
- mPimpl->ring.monomialSetExponents(mPimpl->monomial, mExponents);
- mPimpl->poly.appendTerm(coefficient, mPimpl->monomial);
-
- MATHICGB_ASSERT(debugAssertValid());
- }
-
- void GroebnerInputIdealStream::appendPolynomialDone() {
- MATHICGB_ASSERT(debugAssertValid());
- MATHICGB_IF_DEBUG(mPimpl->checker.appendPolynomialDone());
-
- // todo: avoid copy here by the following changes
- // todo: give Ideal a Poly&& insert
- // todo: give Poly a Poly&& constructor
- auto poly = make_unique<Poly>(std::move(mPimpl->poly));
- if (!poly->termsAreInDescendingOrder())
- poly->sortTermsDescending();
- mPimpl->basis.insert(std::move(poly));
- mPimpl->poly.setToZero();
-
- MATHICGB_ASSERT(debugAssertValid());
- }
-
- void GroebnerInputIdealStream::idealDone() {
- MATHICGB_ASSERT(debugAssertValid());
- MATHICGB_IF_DEBUG(mPimpl->checker.idealDone());
- }
-
- bool GroebnerInputIdealStream::debugAssertValid() const {
- MATHICGB_ASSERT(this != 0);
- MATHICGB_ASSERT(mExponents != 0);
- MATHICGB_ASSERT(mPimpl != 0);
- MATHICGB_ASSERT_NO_ASSUME(!mPimpl->hasBeenDestroyed);
- MATHICGB_ASSERT(!mPimpl->monomial.isNull());
- MATHICGB_ASSERT(&mPimpl->basis.ring() == &mPimpl->ring);
- MATHICGB_ASSERT(&mPimpl->poly.ring() == &mPimpl->ring);
- MATHICGB_ASSERT(mPimpl->ring.getNumVars() == mPimpl->conf.varCount());
- MATHICGB_ASSERT(mPimpl->ring.charac() == mPimpl->conf.modulus());
- return true;
- }
-}
-
-// ** Implementation of class mgbi::PimplOf
-namespace mgbi {
- class PimplOf {
- public:
- template<class T>
- typename T::Pimpl& operator()(T& t) {
- MATHICGB_ASSERT(t.mPimpl != 0);
- return *t.mPimpl;
- }
- };
-}
-
-// ** Implementation of mgbi::IdealAdapter
-namespace mgbi {
- struct IdealAdapter::Pimpl {
- std::unique_ptr<Basis> basis;
- };
-
- IdealAdapter::IdealAdapter():
- mPimpl(new Pimpl()) {
- }
-
- IdealAdapter::~IdealAdapter() {
- MATHICGB_ASSERT(mPimpl != 0);
- delete mPimpl;
- }
-
- auto IdealAdapter::varCount() const -> VarIndex {
- MATHICGB_ASSERT(mPimpl->basis.get() != 0);
- return mPimpl->basis->ring().getNumVars();
- }
-
- size_t IdealAdapter::polyCount() const {
- MATHICGB_ASSERT(mPimpl->basis.get() != 0);
- return mPimpl->basis->size();
- }
-
- size_t IdealAdapter::termCount(PolyIndex poly) const {
- MATHICGB_ASSERT(mPimpl->basis.get() != 0);
- MATHICGB_ASSERT(poly < mPimpl->basis->size());
- return mPimpl->basis->getPoly(poly)->nTerms();
- }
-
- auto IdealAdapter::term(
- PolyIndex poly,
- TermIndex term
- ) const -> std::pair<Coefficient, const Exponent*> {
- MATHICGB_ASSERT(mPimpl->basis.get() != 0);
- MATHICGB_ASSERT(poly < mPimpl->basis->size());
- const auto& p = *mPimpl->basis->getPoly(poly);
-
- MATHICGB_ASSERT(term < p.nTerms());
- return std::make_pair(
- p.coefficientAt(term),
- p.monomialAt(term).unsafeGetRepresentation() + 1
- );
- }
-}
-
-namespace {
- class CallbackAdapter : public ClassicGBAlg::Callback {
- public:
- typedef mgb::GroebnerConfiguration::Callback::Action Action;
-
- CallbackAdapter(void* data, Action (*callback) (void*)):
- mData(data),
- mCallback(callback),
- mLastAction(Action::ContinueAction)
- {
- MATHICGB_ASSERT(mCallback != 0 || mData == 0);
- }
-
- const bool isNull() const {return mCallback == 0;}
- Action lastAction() const {return mLastAction;}
-
- virtual bool call() {
- if (isNull())
- return true;
- mLastAction = mCallback(mData);
- return mLastAction == Action::ContinueAction;
- }
-
- private:
- void* const mData;
- Action (* const mCallback) (void*);
- Action mLastAction;
- };
-}
-
-// ** Implementation of function mgbi::internalComputeGroebnerBasis
-namespace mgbi {
- bool internalComputeGroebnerBasis(
- GroebnerInputIdealStream& inputWhichWillBeCleared,
- IdealAdapter& output
- ) {
- /// @todo: make a scheme where the output Groebner basis is freed
- /// polynomial-by-polynomial as data is transferred to out. Also
- /// make it so that ideal is not copied.
-
- auto&& basis = PimplOf()(inputWhichWillBeCleared).basis;
- auto&& conf = inputWhichWillBeCleared.configuration();
- auto&& ring = basis.ring();
- const auto varCount = ring.getNumVars();
- MATHICGB_ASSERT(PimplOf()(conf).debugAssertValid());
-
- // Tell tbb how many threads to use
- const auto maxThreadCount = int(conf.maxThreadCount());
- const auto tbbMaxThreadCount = maxThreadCount == 0 ?
- mgb::tbb::task_scheduler_init::automatic : maxThreadCount;
- mgb::tbb::task_scheduler_init scheduler(tbbMaxThreadCount);
-
- // Set up logging
- LogDomainSet::singleton().reset();
- LogDomainSet::singleton().performLogCommands(conf.logging());
-
- // Make reducer
- typedef GroebnerConfiguration GConf;
- Reducer::ReducerType reducerType;
- switch (conf.reducer()) {
- case GConf::ClassicReducer:
- reducerType = Reducer::Reducer_BjarkeGeo;
- break;
-
- default:
- case GConf::DefaultReducer:
- case GConf::MatrixReducer:
- reducerType = Reducer::Reducer_F4_New;
- break;
- }
- const auto reducer = Reducer::makeReducer(reducerType, ring);
- CallbackAdapter callback(
- PimplOf()(conf).mCallbackData,
- PimplOf()(conf).mCallback
- );
-
- // Set up and configure algorithm
- ClassicGBAlg alg(basis, *reducer, 2, true, 0);
- alg.setReducerMemoryQuantum(100 * 1024);
- alg.setUseAutoTopReduction(true);
- alg.setUseAutoTailReduction(false);
- alg.setSPairGroupSize(conf.maxSPairGroupSize());
- if (!callback.isNull())
- alg.setCallback(&callback);
-
- // Compute Groebner basis
- alg.computeGrobnerBasis();
- typedef mgb::GroebnerConfiguration::Callback::Action Action;
- if (callback.lastAction() != Action::StopWithNoOutputAction) {
- PimplOf()(output).basis = alg.basis().toBasisAndRetireAll();
- return true;
- } else
- return false;
- }
-}
+#include "mathicgb/stdinc.h"
+#include "mathicgb.h"
+
+#include "mathicgb/Basis.hpp"
+#include "mathicgb/PolyRing.hpp"
+#include "mathicgb/Poly.hpp"
+#include "mathicgb/Reducer.hpp"
+#include "mathicgb/ClassicGBAlg.hpp"
+#include "mathicgb/mtbb.hpp"
+#include "mathicgb/LogDomainSet.hpp"
+#include <mathic.h>
+
+#ifndef MATHICGB_ASSERT
+#ifdef MATHICGB_DEBUG
+#include <cassert>
+#define MATHICGB_ASSERT(X) assert(X)
+#else
+#define MATHICGB_ASSERT(X)
+#endif
+#endif
+
+#define MATHICGB_STREAM_CHECK(X, MSG) \
+ do { \
+ const bool value = (X); \
+ if (!value) { \
+ const bool ignoreMe = false; \
+ MATHICGB_ASSERT(( \
+ "MathicGB stream protocol error: "#MSG \
+ "\nAssert expression: "#X"\n", \
+ false \
+ )); \
+ throw std::invalid_argument( \
+ "MathicGB stream protocol error: "#MSG \
+ "\nAssert expression: "#X"\n" \
+ ); \
+ } \
+ } while (false)
+
+extern "C" {
+ void libmathicgbIsPresent(void) {}
+}
+
+MATHICGB_NAMESPACE_BEGIN
+
+using namespace mgbi;
+
+namespace {
+ bool isPrime(unsigned int n) {
+ if (n == 0 || n == 1)
+ return false;
+ if (n == 2 || n == 3)
+ return true;
+ return true; // todo: make better test
+ }
+};
+
+bool logTime(const char* logName, double& time) {
+ auto log = LogDomainSet::singleton().logDomain(logName);
+ if (log == 0 || !log->enabled())
+ return false;
+ time = log->loggedSecondsReal();
+ return true;
+}
+
+bool logNumber(const char* logName, double& number) {
+ auto log = LogDomainSet::singleton().logDomain(logName);
+ if (log == 0 || !log->enabled())
+ return false;
+ number = static_cast<double>(log->count());
+ return true;
+}
+
+namespace mgbi {
+ struct StreamStateChecker::Pimpl {
+ Pimpl(Coefficient modulus, VarIndex varCount):
+ modulus(modulus),
+ varCount(varCount),
+ state(Initial),
+
+ hasClaimedPolyCount(false),
+ claimedPolyCount(0),
+ seenPolyCount(0),
+
+ hasClaimedTermCount(false),
+ claimedTermCount(0),
+ seenTermCount(0),
+
+ lastVar(0)
+ {}
+
+ bool debugAssertValid() const;
+
+ enum State {
+ Initial,
+ MakingIdeal,
+ MakingPoly,
+ MakingTerm,
+ HasIdeal
+ };
+
+ const Coefficient modulus;
+ const VarIndex varCount;
+
+ State state;
+
+ bool hasClaimedPolyCount;
+ size_t claimedPolyCount;
+ size_t seenPolyCount;
+
+ bool hasClaimedTermCount;
+ size_t claimedTermCount;
+ size_t seenTermCount;
+
+ VarIndex lastVar;
+ };
+
+ bool StreamStateChecker::Pimpl::debugAssertValid() const {
+#ifdef MATHICGB_DEBUG
+ MATHICGB_ASSERT(this != 0);
+ switch (state) {
+ case Initial:
+ case MakingIdeal:
+ case MakingPoly:
+ case MakingTerm:
+ case HasIdeal:
+ break;
+
+ default:
+ MATHICGB_ASSERT(false);
+ return false;
+ }
+#endif
+ return true;
+ };
+
+ StreamStateChecker::StreamStateChecker(const Coefficient modulus, const VarIndex varCount):
+ mPimpl(new Pimpl(modulus, varCount))
+ {
+ try {
+ MATHICGB_STREAM_CHECK(isPrime(modulus), "The modulus must be prime");
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ } catch (...) {
+ delete mPimpl;
+ }
+ }
+
+ StreamStateChecker::~StreamStateChecker() {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ delete mPimpl;
+ }
+
+ void StreamStateChecker::idealBegin() {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state == Pimpl::Initial || mPimpl->state == Pimpl::HasIdeal,
+ "idealBegin() must not be called twice "
+ "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() {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state != Pimpl::Initial && mPimpl->state != Pimpl::HasIdeal,
+ "appendPolynomialBegin() must only be called after idealBegin() and "
+ "before idealEnd()."
+ );
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state == Pimpl::MakingIdeal,
+ "appendPolynomialBegin() must not be called twice without "
+ "an intervening call to appendPolynomialDone()."
+ );
+ MATHICGB_STREAM_CHECK(
+ !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;
+
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ }
+
+ void StreamStateChecker::appendTermBegin() {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state != Pimpl::Initial &&
+ mPimpl->state != Pimpl::HasIdeal &&
+ mPimpl->state != Pimpl::MakingIdeal,
+ "appendTermBegin() must only be called after appendPolynomialBegin() "
+ "and before appendPolynomialDone()."
+ );
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state == Pimpl::MakingPoly,
+ "appendTermBegin() must not be called twice without an intervening "
+ "call to appendTermDone()."
+ );
+ MATHICGB_STREAM_CHECK(
+ !mPimpl->hasClaimedTermCount ||
+ mPimpl->seenTermCount < mPimpl->claimedTermCount,
+ "The number of terms in a polynomial must not exceed the amount "
+ "passed to appendPolynomialBegin()."
+ );
+
+ mPimpl->state = Pimpl::MakingTerm;
+ mPimpl->seenTermCount += 1;
+ mPimpl->lastVar = std::numeric_limits<decltype(mPimpl->lastVar)>::max();
+
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ }
+
+ void StreamStateChecker::appendExponent(VarIndex index, Exponent exponent) {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state == Pimpl::MakingTerm,
+ "appendExponent must only be called after appendTermBegin() and before "
+ "appendTermDone()."
+ );
+ MATHICGB_STREAM_CHECK(
+ index < mPimpl->varCount,
+ "The index passed to appendExponent must be strictly less than "
+ "the number of variables."
+ );
+ MATHICGB_STREAM_CHECK(
+ mPimpl->lastVar ==
+ std::numeric_limits<decltype(mPimpl->lastVar)>::max() ||
+ mPimpl->lastVar < index,
+ "The variable indices passed to appendExponent must be in strictly "
+ "increasing order within each monomial."
+ );
+
+ mPimpl->lastVar = index;
+
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ }
+
+ void StreamStateChecker::appendTermDone(Coefficient coefficient) {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+
+ MATHICGB_STREAM_CHECK(
+ coefficient > 0,
+ "The coefficient passed to appendTermDone() must be strictly positive."
+ );
+ MATHICGB_STREAM_CHECK(
+ coefficient < mPimpl->modulus,
+ "The coefficient passed to appendTermDone() must be strictly less "
+ "then the modulus."
+ );
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state == Pimpl::MakingTerm,
+ "appendTermDone() must only be called after appendTermBegin()."
+ );
+ mPimpl->state = Pimpl::MakingPoly;
+
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ }
+
+ void StreamStateChecker::appendPolynomialDone() {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state == Pimpl::MakingPoly,
+ "appendPolynomialDone() must only be called after appendPolynomialBegin()."
+ );
+ MATHICGB_STREAM_CHECK(
+ !mPimpl->hasClaimedTermCount ||
+ mPimpl->seenTermCount == mPimpl->claimedTermCount,
+ "The number of terms in a polynomial must match the amount "
+ "passed to appendPolynomialBegin()."
+ );
+ mPimpl->state = Pimpl::MakingIdeal;
+
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ }
+
+ void StreamStateChecker::idealDone() {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+
+ MATHICGB_STREAM_CHECK(
+ mPimpl->state == Pimpl::MakingIdeal,
+ "idealDone() must only be called after idealBegin()."
+ );
+ MATHICGB_STREAM_CHECK(
+ !mPimpl->hasClaimedPolyCount ||
+ mPimpl->seenPolyCount == mPimpl->claimedPolyCount,
+ "The number of polynomials in an ideal must match the amount "
+ "passed to idealBegin()."
+ );
+
+ mPimpl->state = Pimpl::HasIdeal;
+
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ }
+
+ bool StreamStateChecker::hasIdeal() const {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ return mPimpl->state == Pimpl::HasIdeal;
+ }
+}
+
+// ** Implementation of the class GroebnerConfiguration
+
+struct GroebnerConfiguration::Pimpl {
+ Pimpl(Coefficient modulus, VarIndex varCount):
+ mModulus(modulus),
+ mVarCount(varCount),
+ mBaseOrder(ReverseLexicographicBaseOrder),
+ mGradings(varCount, 1),
+ mComponentBefore(ComponentAfterBaseOrder),
+ mComponentsAscending(true),
+ mSchreyering(true),
+ mReducer(DefaultReducer),
+ mMaxSPairGroupSize(0),
+ mMaxThreadCount(0),
+ mLogging(),
+ mCallbackData(0),
+ mCallback(0)
+#ifdef MATHICGB_DEBUG
+ , mHasBeenDestroyed(false)
+#endif
+ {
+ }
+
+ ~Pimpl() {
+ MATHICGB_ASSERT(debugAssertValid());
+ MATHICGB_IF_DEBUG(mHasBeenDestroyed = true;)
+ }
+
+ static bool baseOrderValid(const BaseOrder order) {
+ return
+ order == LexicographicBaseOrder ||
+ order == ReverseLexicographicBaseOrder;
+ }
+
+ static bool reducerValid(const Reducer reducer) {
+ return
+ reducer == DefaultReducer ||
+ reducer == ClassicReducer ||
+ reducer == MatrixReducer;
+ }
+
+ bool debugAssertValid() const {
+#ifdef MATHICGB_DEBUG
+ MATHICGB_ASSERT(this != 0);
+ MATHICGB_ASSERT(baseOrderValid(mBaseOrder));
+ MATHICGB_ASSERT(reducerValid(mReducer));
+ MATHICGB_ASSERT(mModulus != 0);
+ MATHICGB_ASSERT(mCallback != 0 || mCallbackData == 0);
+ MATHICGB_ASSERT_NO_ASSUME(!mHasBeenDestroyed);
+#endif
+ return true;
+ }
+
+ const Coefficient mModulus;
+ const VarIndex mVarCount;
+ BaseOrder mBaseOrder;
+ std::vector<Exponent> mGradings;
+ size_t mComponentBefore;
+ bool mComponentsAscending;
+ bool mSchreyering;
+ Reducer mReducer;
+ unsigned int mMaxSPairGroupSize;
+ unsigned int mMaxThreadCount;
+ std::string mLogging;
+ void* mCallbackData;
+ Callback::Action (*mCallback) (void*);
+ MATHICGB_IF_DEBUG(bool mHasBeenDestroyed);
+};
+
+GroebnerConfiguration::GroebnerConfiguration(
+ Coefficient modulus,
+ VarIndex varCount
+):
+ mPimpl(new Pimpl(modulus, varCount))
+{
+ if (modulus > std::numeric_limits<unsigned short>::max()) {
+ MATHICGB_ASSERT_NO_ASSUME(false);
+ std::ostringstream str;
+ str << "Modulus " << modulus
+ << " is too large. MathicGB only supports 16 bit moduli.";
+ mathic::reportError(str.str());
+ }
+ if (!isPrime(modulus)) {
+ MATHICGB_ASSERT_NO_ASSUME(false);
+ std::ostringstream str;
+ str << "Modulus " << modulus
+ << " is not prime. MathicGB only supports prime fields.";
+ mathic::reportError(str.str());
+ }
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+}
+
+GroebnerConfiguration::GroebnerConfiguration(
+ const GroebnerConfiguration& conf
+):
+ mPimpl(new Pimpl(*conf.mPimpl))
+{
+ MATHICGB_ASSERT(conf.mPimpl->debugAssertValid());
+}
+
+GroebnerConfiguration::~GroebnerConfiguration() {
+ MATHICGB_ASSERT(mPimpl->debugAssertValid());
+ delete mPimpl;
+}
+
+auto GroebnerConfiguration::modulus() const -> Coefficient {
+ return mPimpl->mModulus;
+}
+
+auto GroebnerConfiguration::varCount() const -> VarIndex {
+ return mPimpl->mVarCount;
+}
+
+bool GroebnerConfiguration::setMonomialOrderInternal(
+ MonomialOrderData order
+) {
+ MATHICGB_ASSERT(Pimpl::baseOrderValid(order.baseOrder));
+ MATHICGB_ASSERT(varCount() != 0 || order.gradingsSize == 0);
+ MATHICGB_ASSERT(varCount() == 0 || order.gradingsSize % varCount() == 0);
+
+ // Check if order is global.
+ if (varCount() != 0) {
+ const size_t rowCount = order.gradingsSize / varCount();
+ for (VarIndex var = 0; var < varCount(); ++var) {
+ // check if 1 < x_var.
+ for (size_t row = 0; row < rowCount; ++row) {
+ const Exponent e = order.gradings[row * varCount() + var];
+ if (e < 0)
+ return false; // order not global
+ if (e > 0)
+ goto orderGlobalForVar;
+ }
+ if (order.baseOrder == ReverseLexicographicBaseOrder)
+ return false; // order not global
+ orderGlobalForVar:;
+ }
+ }
+
+ mPimpl->mBaseOrder = order.baseOrder;
+ mPimpl->mGradings.assign
+ (order.gradings, order.gradings + order.gradingsSize);
+ return true;
+}
+
+auto GroebnerConfiguration::monomialOrderInternal() const ->
+ MonomialOrderData
+{
+ const MonomialOrderData data = {
+ mPimpl->mBaseOrder,
+ mPimpl->mGradings.data(),
+ mPimpl->mGradings.size()
+ };
+ return data;
+}
+
+void GroebnerConfiguration::setCallbackInternal(
+ void* data,
+ Callback::Action (*func) (void*)
+) {
+ MATHICGB_ASSERT(func != 0 || data == 0);
+ mPimpl->mCallbackData = data;
+ mPimpl->mCallback = func;
+}
+
+void* GroebnerConfiguration::callbackDataInternal() const {
+ return mPimpl->mCallbackData;
+}
+
+void GroebnerConfiguration::setComponentBefore(size_t value) {
+ mPimpl->mComponentBefore = value;
+}
+
+size_t GroebnerConfiguration::componentBefore() const {
+ return mPimpl->mComponentBefore;
+}
+
+void GroebnerConfiguration::setComponentsAscending(bool value) {
+ mPimpl->mComponentsAscending = value;
+}
+
+bool GroebnerConfiguration::componentsAscending() const {
+ return mPimpl->mComponentsAscending;
+}
+
+void GroebnerConfiguration::setSchreyering(bool value) {
+ mPimpl->mSchreyering = value;
+}
+
+bool GroebnerConfiguration::schreyering() const {
+ return mPimpl->mSchreyering;
+}
+
+void GroebnerConfiguration::setReducer(Reducer reducer) {
+ MATHICGB_ASSERT(Pimpl::reducerValid(reducer));
+ mPimpl->mReducer = reducer;
+}
+
+auto GroebnerConfiguration::reducer() const -> Reducer {
+ return mPimpl->mReducer;
+}
+
+void GroebnerConfiguration::setMaxSPairGroupSize(unsigned int size) {
+ mPimpl->mMaxSPairGroupSize = size;
+}
+
+uint32 GroebnerConfiguration::maxSPairGroupSize() const {
+ return mPimpl->mMaxSPairGroupSize;
+}
+
+void GroebnerConfiguration::setMaxThreadCount(unsigned int maxThreadCount) {
+ mPimpl->mMaxThreadCount = maxThreadCount;
+}
+
+unsigned int GroebnerConfiguration::maxThreadCount() const {
+ return mPimpl->mMaxThreadCount;
+}
+
+void GroebnerConfiguration::setLogging(const char* logging) {
+ if (logging == 0)
+ mPimpl->mLogging.clear();
+ else
+ mPimpl->mLogging = logging;
+}
+
+const char* GroebnerConfiguration::logging() const {
+ return mPimpl->mLogging.c_str();
+}
+
+// ** Implementation of class GroebnerInputIdealStream
+struct GroebnerInputIdealStream::Pimpl {
+ Pimpl(const GroebnerConfiguration& conf):
+ ring(
+ PolyRing::Field(conf.modulus()),
+ PolyRing::Monoid::Order(
+ conf.varCount(),
+ std::move(conf.monomialOrder().second),
+ conf.monomialOrder().first ==
+ GroebnerConfiguration::LexicographicBaseOrder ?
+ PolyRing::Monoid::Order::LexBaseOrder :
+ PolyRing::Monoid::Order::RevLexBaseOrder,
+ conf.componentBefore(),
+ conf.componentsAscending(),
+ conf.schreyering()
+ )
+ ),
+ basis(ring),
+ poly(ring),
+ monomial(ring.allocMonomial()),
+ conf(conf)
+#ifdef MATHICGB_DEBUG
+ , hasBeenDestroyed(false),
+ checker(conf.modulus(), conf.varCount())
+#endif
+ {}
+
+ ~Pimpl() {
+ ring.freeMonomial(monomial);
+ }
+
+ const PolyRing ring;
+ Basis basis;
+ Poly poly;
+ Monomial monomial;
+ const GroebnerConfiguration conf;
+ MATHICGB_IF_DEBUG(bool hasBeenDestroyed);
+ MATHICGB_IF_DEBUG(StreamStateChecker checker);
+};
+
+GroebnerInputIdealStream::GroebnerInputIdealStream(
+ const GroebnerConfiguration& conf
+):
+ mExponents(new Exponent[conf.varCount()]),
+ mPimpl(new Pimpl(conf))
+{
+ MATHICGB_ASSERT(debugAssertValid());
+}
+
+GroebnerInputIdealStream::~GroebnerInputIdealStream() {
+ MATHICGB_ASSERT(debugAssertValid());
+ MATHICGB_ASSERT(mExponents != 0);
+ MATHICGB_ASSERT(mPimpl != 0);
+ MATHICGB_ASSERT_NO_ASSUME(!mPimpl->hasBeenDestroyed);
+ MATHICGB_IF_DEBUG(mPimpl->hasBeenDestroyed = true);
+ delete mPimpl;
+ delete[] mExponents;
+}
+
+const GroebnerConfiguration& GroebnerInputIdealStream::configuration() {
+ return mPimpl->conf;
+}
+
+auto GroebnerInputIdealStream::modulus() const -> Coefficient {
+ return mPimpl->conf.modulus();
+}
+
+auto GroebnerInputIdealStream::varCount() const -> VarIndex {
+ return mPimpl->conf.varCount();
+}
+
+void GroebnerInputIdealStream::idealBegin() {
+ MATHICGB_ASSERT(debugAssertValid());
+ MATHICGB_IF_DEBUG(mPimpl->checker.idealBegin());
+ MATHICGB_ASSERT(mPimpl->poly.isZero());
+ MATHICGB_ASSERT(mPimpl->basis.empty());
+
+ MATHICGB_ASSERT(debugAssertValid());
+}
+
+void GroebnerInputIdealStream::idealBegin(size_t polyCount) {
+ MATHICGB_ASSERT(debugAssertValid());
+ MATHICGB_IF_DEBUG(mPimpl->checker.idealBegin(polyCount));
+ MATHICGB_ASSERT(mPimpl->poly.isZero());
+ MATHICGB_ASSERT(mPimpl->basis.empty());
+
+ mPimpl->basis.reserve(polyCount);
+
+ 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));
+ MATHICGB_ASSERT(mPimpl->poly.isZero());
+
+ mPimpl->poly.reserve(termCount);
+
+ MATHICGB_ASSERT(debugAssertValid());
+}
+
+void GroebnerInputIdealStream::appendTermBegin() {
+ MATHICGB_ASSERT(debugAssertValid());
+ MATHICGB_IF_DEBUG(mPimpl->checker.appendTermBegin());
+
+ std::fill_n(mExponents, varCount(), 0);
+
+ MATHICGB_ASSERT(debugAssertValid());
+}
+
+void GroebnerInputIdealStream::appendTermDone(Coefficient coefficient) {
+ MATHICGB_ASSERT(debugAssertValid());
+ MATHICGB_IF_DEBUG(mPimpl->checker.appendTermDone(coefficient));
+
+ // @todo: do this directly into the polynomial instead of copying a second
+ // time.
+ mPimpl->ring.monomialSetExponents(mPimpl->monomial, mExponents);
+ mPimpl->poly.appendTerm(coefficient, mPimpl->monomial);
+
+ MATHICGB_ASSERT(debugAssertValid());
+}
+
+void GroebnerInputIdealStream::appendPolynomialDone() {
+ MATHICGB_ASSERT(debugAssertValid());
+ MATHICGB_IF_DEBUG(mPimpl->checker.appendPolynomialDone());
+
+ // todo: avoid copy here by the following changes
+ // todo: give Ideal a Poly&& insert
+ // todo: give Poly a Poly&& constructor
+ auto poly = make_unique<Poly>(std::move(mPimpl->poly));
+ if (!poly->termsAreInDescendingOrder())
+ poly->sortTermsDescending();
+ mPimpl->basis.insert(std::move(poly));
+ mPimpl->poly.setToZero();
+
+ MATHICGB_ASSERT(debugAssertValid());
+}
+
+void GroebnerInputIdealStream::idealDone() {
+ MATHICGB_ASSERT(debugAssertValid());
+ MATHICGB_IF_DEBUG(mPimpl->checker.idealDone());
+}
+
+bool GroebnerInputIdealStream::debugAssertValid() const {
+ MATHICGB_ASSERT(this != 0);
+ MATHICGB_ASSERT(mExponents != 0);
+ MATHICGB_ASSERT(mPimpl != 0);
+ MATHICGB_ASSERT_NO_ASSUME(!mPimpl->hasBeenDestroyed);
+ MATHICGB_ASSERT(!mPimpl->monomial.isNull());
+ MATHICGB_ASSERT(&mPimpl->basis.ring() == &mPimpl->ring);
+ MATHICGB_ASSERT(&mPimpl->poly.ring() == &mPimpl->ring);
+ MATHICGB_ASSERT(mPimpl->ring.getNumVars() == mPimpl->conf.varCount());
+ MATHICGB_ASSERT(mPimpl->ring.charac() == mPimpl->conf.modulus());
+ return true;
+}
+
+// ** Implementation of class mgbi::PimplOf
+namespace mgbi {
+ class PimplOf {
+ public:
+ template<class T>
+ typename T::Pimpl& operator()(T& t) {
+ MATHICGB_ASSERT(t.mPimpl != 0);
+ return *t.mPimpl;
+ }
+ };
+}
+
+// ** Implementation of mgbi::IdealAdapter
+namespace mgbi {
+ struct IdealAdapter::Pimpl {
+ std::unique_ptr<Basis> basis;
+ };
+
+ IdealAdapter::IdealAdapter():
+ mPimpl(new Pimpl()) {
+ }
+
+ IdealAdapter::~IdealAdapter() {
+ MATHICGB_ASSERT(mPimpl != 0);
+ delete mPimpl;
+ }
+
+ auto IdealAdapter::varCount() const -> VarIndex {
+ MATHICGB_ASSERT(mPimpl->basis.get() != 0);
+ return mPimpl->basis->ring().getNumVars();
+ }
+
+ size_t IdealAdapter::polyCount() const {
+ MATHICGB_ASSERT(mPimpl->basis.get() != 0);
+ return mPimpl->basis->size();
+ }
+
+ size_t IdealAdapter::termCount(PolyIndex poly) const {
+ MATHICGB_ASSERT(mPimpl->basis.get() != 0);
+ MATHICGB_ASSERT(poly < mPimpl->basis->size());
+ return mPimpl->basis->getPoly(poly)->nTerms();
+ }
+
+ auto IdealAdapter::term(
+ PolyIndex poly,
+ TermIndex term
+ ) const -> std::pair<Coefficient, const Exponent*> {
+ MATHICGB_ASSERT(mPimpl->basis.get() != 0);
+ MATHICGB_ASSERT(poly < mPimpl->basis->size());
+ const auto& p = *mPimpl->basis->getPoly(poly);
+
+ MATHICGB_ASSERT(term < p.nTerms());
+ return std::make_pair(
+ p.coefficientAt(term),
+ p.monomialAt(term).unsafeGetRepresentation() + 1
+ );
+ }
+}
+
+namespace {
+ class CallbackAdapter : public mgb::ClassicGBAlg::Callback {
+ public:
+ typedef mgb::GroebnerConfiguration::Callback::Action Action;
+
+ CallbackAdapter(void* data, Action (*callback) (void*)):
+ mData(data),
+ mCallback(callback),
+ mLastAction(Action::ContinueAction)
+ {
+ MATHICGB_ASSERT(mCallback != 0 || mData == 0);
+ }
+
+ const bool isNull() const {return mCallback == 0;}
+ Action lastAction() const {return mLastAction;}
+
+ virtual bool call() {
+ if (isNull())
+ return true;
+ mLastAction = mCallback(mData);
+ return mLastAction == Action::ContinueAction;
+ }
+
+ private:
+ void* const mData;
+ Action (* const mCallback) (void*);
+ Action mLastAction;
+ };
+}
+
+// ** Implementation of function mgbi::internalComputeGroebnerBasis
+namespace mgbi {
+ bool internalComputeGroebnerBasis(
+ GroebnerInputIdealStream& inputWhichWillBeCleared,
+ IdealAdapter& output
+ ) {
+ /// @todo: make a scheme where the output Groebner basis is freed
+ /// polynomial-by-polynomial as data is transferred to out. Also
+ /// make it so that ideal is not copied.
+
+ auto&& basis = PimplOf()(inputWhichWillBeCleared).basis;
+ auto&& conf = inputWhichWillBeCleared.configuration();
+ auto&& ring = basis.ring();
+ const auto varCount = ring.getNumVars();
+ MATHICGB_ASSERT(PimplOf()(conf).debugAssertValid());
+
+ // Tell tbb how many threads to use
+ const auto maxThreadCount = int(conf.maxThreadCount());
+ const auto tbbMaxThreadCount = maxThreadCount == 0 ?
+ mgb::mtbb::task_scheduler_init::automatic : maxThreadCount;
+ mgb::mtbb::task_scheduler_init scheduler(tbbMaxThreadCount);
+
+ // Set up logging
+ LogDomainSet::singleton().reset();
+ LogDomainSet::singleton().performLogCommands(conf.logging());
+
+ // Make reducer
+ typedef GroebnerConfiguration GConf;
+ Reducer::ReducerType reducerType;
+ switch (conf.reducer()) {
+ case GConf::ClassicReducer:
+ reducerType = Reducer::Reducer_BjarkeGeo;
+ break;
+
+ default:
+ case GConf::DefaultReducer:
+ case GConf::MatrixReducer:
+ reducerType = Reducer::Reducer_F4_New;
+ break;
+ }
+ const auto reducer = Reducer::makeReducer(reducerType, ring);
+ CallbackAdapter callback(
+ PimplOf()(conf).mCallbackData,
+ PimplOf()(conf).mCallback
+ );
+
+ // Set up and configure algorithm
+ ClassicGBAlg alg(basis, *reducer, 2, true, 0);
+ alg.setReducerMemoryQuantum(100 * 1024);
+ alg.setUseAutoTopReduction(true);
+ alg.setUseAutoTailReduction(false);
+ alg.setSPairGroupSize(conf.maxSPairGroupSize());
+ if (!callback.isNull())
+ alg.setCallback(&callback);
+
+ // Compute Groebner basis
+ alg.computeGrobnerBasis();
+ typedef mgb::GroebnerConfiguration::Callback::Action Action;
+ if (callback.lastAction() != Action::StopWithNoOutputAction) {
+ PimplOf()(output).basis = alg.basis().toBasisAndRetireAll();
+ return true;
+ } else
+ return false;
+ }
+}
+
+MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb.h b/src/mathicgb.h
index 70ddf1e..7483ee4 100755
--- a/src/mathicgb.h
+++ b/src/mathicgb.h
@@ -9,18 +9,25 @@
// preceding that function for an example of how to use this library
// interface.
-/// Code in this namespace is not part of the public interface of MathicGB.
-/// If you take a dependency on code in this namespace, except indirectly
-/// through using code in the mgb namespace, then you are not using the
-/// library interface as intended.
-namespace mgbi { // Not part of the public interface of MathicGB
- class PimplOf;
+extern "C" {
+ // Put a C function in the library so that it can be detected by the autoconf
+ // macro AC_CHECK_LIB. That macro can only check for libraries that contain
+ // at least one C function.
+ void libmathicgbIsPresent(void); // This function does nothing.
}
/// The classes and functions in this namespace make up the public interface
/// of MathicGB. You should not have to update your code when upgrading to a
/// newer minor revision of MathicGB if you only use the public interface.
namespace mgb { // Part of the public interface of MathicGB
+ /// Code in this namespace is not part of the public interface of MathicGB.
+ /// If you take a dependency on code in this namespace, except indirectly
+ /// through using code in the mgb namespace, then you are not using the
+ /// library interface as intended.
+ namespace mgbi { // Not part of the public interface of MathicGB
+ class PimplOf;
+ }
+
/// Sets time to the number of seconds accumulated on the internal
/// MathicGB log named logName. Returns true if the logName log was
/// found and false otherwise.
@@ -410,43 +417,38 @@ namespace mgb { // Part of the public interface of MathicGB
template<class OutputStream>
void streamSimpleIdeal(OutputStream& output);
-}
-
-namespace mgbi { // Not part of the public interface of MathicGB
- using namespace mgb;
-
- /// Class that checks to see if the protocol for an ideal stream is followed.
- /// A method will return false if that is not the case. This class is not
- /// itself an ideal stream - it is intended to be used with ideal streams for
- /// debugging.
- class StreamStateChecker {
- public:
- typedef GroebnerConfiguration::Coefficient Coefficient;
- typedef GroebnerConfiguration::VarIndex VarIndex;
- typedef GroebnerConfiguration::Exponent Exponent;
-
- 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);
- void appendTermDone(Coefficient coefficient);
- void appendPolynomialDone();
- void idealDone();
-
- bool hasIdeal() const;
-
- private:
- struct Pimpl;
- Pimpl* const mPimpl;
- };
-}
-namespace mgb { // Part of the public interface of MathicGB
+ namespace mgbi { // Not part of the public interface of MathicGB
+ /// Class that checks to see if the protocol for an ideal stream is followed.
+ /// A method will return false if that is not the case. This class is not
+ /// itself an ideal stream - it is intended to be used with ideal streams for
+ /// debugging.
+ class StreamStateChecker {
+ public:
+ typedef GroebnerConfiguration::Coefficient Coefficient;
+ typedef GroebnerConfiguration::VarIndex VarIndex;
+ typedef GroebnerConfiguration::Exponent Exponent;
+
+ 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);
+ void appendTermDone(Coefficient coefficient);
+ void appendPolynomialDone();
+ void idealDone();
+
+ bool hasIdeal() const;
+
+ private:
+ struct Pimpl;
+ Pimpl* const mPimpl;
+ };
+ }
/// Use this class to check that you are following the correct protocol
/// for calling methods on an ideal stream. This has significant overhead
@@ -477,17 +479,10 @@ namespace mgb { // Part of the public interface of MathicGB
private:
Stream& mStream;
- ::mgbi::StreamStateChecker mChecker;
+ mgbi::StreamStateChecker mChecker;
};
}
-extern "C" {
- // Put a C function in the library so that it can be detected by the autoconf
- // macro AC_CHECK_LIB. That macro can only check for libraries that contain
- // at least one C function.
- void libmathicgbIsPresent(void); // This function does nothing.
-}
-
// ********************************************************
// Nothing below this line is part of the public interface of MathicGB.
@@ -760,41 +755,39 @@ namespace mgb {
VarIndex varCount
):
mModulus(modulus), mVarCount(varCount) {}
-}
-
-namespace mgbi {
- /// Used to read an internal MathicGB ideal without exposing the type of
- /// the ideal.
- class IdealAdapter {
- public:
- typedef GroebnerConfiguration::Coefficient Coefficient;
- typedef GroebnerConfiguration::VarIndex VarIndex;
- typedef GroebnerConfiguration::Exponent Exponent;
- typedef std::pair<Coefficient, const Exponent*> ConstTerm;
- typedef size_t PolyIndex;
- typedef size_t TermIndex;
-
- IdealAdapter();
- ~IdealAdapter();
-
- VarIndex varCount() const;
- size_t polyCount() const;
- size_t termCount(PolyIndex poly) const;
- ConstTerm term(PolyIndex poly, TermIndex term) const;
- private:
- friend class ::mgbi::PimplOf;
- struct Pimpl;
- Pimpl* mPimpl;
- };
+ namespace mgbi {
+ /// Used to read an internal MathicGB ideal without exposing the type of
+ /// the ideal.
+ class IdealAdapter {
+ public:
+ typedef GroebnerConfiguration::Coefficient Coefficient;
+ typedef GroebnerConfiguration::VarIndex VarIndex;
+ typedef GroebnerConfiguration::Exponent Exponent;
+ typedef std::pair<Coefficient, const Exponent*> ConstTerm;
+ typedef size_t PolyIndex;
+ typedef size_t TermIndex;
+
+ IdealAdapter();
+ ~IdealAdapter();
+
+ VarIndex varCount() const;
+ size_t polyCount() const;
+ size_t termCount(PolyIndex poly) const;
+ ConstTerm term(PolyIndex poly, TermIndex term) const;
+
+ private:
+ friend class mgbi::PimplOf;
+ struct Pimpl;
+ Pimpl* mPimpl;
+ };
- bool internalComputeGroebnerBasis(
- GroebnerInputIdealStream& inputWhichWillBeCleared,
- IdealAdapter& output
- );
-}
+ bool internalComputeGroebnerBasis(
+ GroebnerInputIdealStream& inputWhichWillBeCleared,
+ IdealAdapter& output
+ );
+ }
-namespace mgb {
template<class OutputStream>
void computeGroebnerBasis(
GroebnerInputIdealStream& inputWhichWillBeCleared,
diff --git a/src/mathicgb/Atomic.hpp b/src/mathicgb/Atomic.hpp
index 779e6f9..a0c2645 100755
--- a/src/mathicgb/Atomic.hpp
+++ b/src/mathicgb/Atomic.hpp
@@ -3,8 +3,8 @@
#ifndef MATHICGB_ATOMIC_GUARD
#define MATHICGB_ATOMIC_GUARD
-// We need this include for ::std::memory_order even if we are not
-// using ::std::atomic.
+// We need this include for std::memory_order even if we are not
+// using std::atomic.
#include <atomic>
MATHICGB_NAMESPACE_BEGIN
@@ -33,7 +33,9 @@ namespace AtomicInternal {
}
#if defined(_MSC_VER) && defined(MATHICGB_USE_CUSTOM_ATOMIC_X86_X64)
+MATHICGB_NAMESPACE_END
#include <Windows.h>
+MATHICGB_NAMESPACE_BEGIN
namespace AtomicInternal {
template<class T, size_t size = sizeof(T)>
struct SeqCst {};
@@ -100,8 +102,8 @@ namespace AtomicInternal {
public:
FakeAtomic(): mValue() {}
FakeAtomic(T value): mValue(value) {}
- T load(const ::std::memory_order) const {return mValue;}
- void store(const T value, const ::std::memory_order order) {mValue = value;}
+ T load(const std::memory_order) const {return mValue;}
+ void store(const T value, const std::memory_order order) {mValue = value;}
private:
T mValue;
@@ -114,11 +116,11 @@ namespace AtomicInternal {
#else
/// Class for deciding which implementation of atomic to use. The default is
- /// to use ::std::atomic which is a fine choice if ::std::atomic is implemented
+ /// to use std::atomic which is a fine choice if std::atomic is implemented
/// in a reasonable way by the standard library implementation you are using.
template<class T, size_t size>
struct ChooseAtomic {
- typedef ::std::atomic<T> type;
+ typedef std::atomic<T> type;
};
#endif
}
@@ -130,7 +132,7 @@ namespace AtomicInternal {
/// writes are guaranteed to be atomic - this class only takes care of the
/// ordering constraints using CPU and compiler fences. Since the directives
/// to achieve this are coming from the compiler it is surprising that
- /// any compiler ships with a ::std::atomic that is worse than this - but
+ /// any compiler ships with a std::atomic that is worse than this - but
/// that is very much the case. Though implementing atomic load and store
/// is very little code, as you can see, it is quite tricky and took me
/// a long time to understand everything well enough to actually know what
@@ -186,9 +188,9 @@ namespace AtomicInternal {
CustomAtomicX86X64(T value): mValue(value) {}
MATHICGB_INLINE
- T load(const ::std::memory_order order) const {
+ T load(const std::memory_order order) const {
switch (order) {
- case ::std::memory_order_relaxed:
+ case std::memory_order_relaxed:
// There are two constraints for memory_order_relaxed. The first
// constraint is that if you read *p, then you will never
// after that read a value of *p that was stored before the value
@@ -203,7 +205,7 @@ namespace AtomicInternal {
// this constraint is broken, but clearly the written value must turn
// up eventually. This constraint could be broken in cases like this:
//
- // while (x.load(::std::memory_order_relaxed) == 0) {
+ // while (x.load(std::memory_order_relaxed) == 0) {
// // do something that does not write to x
// }
//
@@ -212,7 +214,7 @@ namespace AtomicInternal {
// the value for every iteration, so the code can safely be transformed
// to:
//
- // if (x.load(::std::memory_order_relaxed) == 0) {
+ // if (x.load(std::memory_order_relaxed) == 0) {
// while (true) {
// // ...
// }
@@ -233,7 +235,7 @@ namespace AtomicInternal {
// volatile read since it is the best choice on GCC.
return const_cast<volatile T&>(mValue);
- case ::std::memory_order_consume: {
+ case std::memory_order_consume: {
// Loads in this thread that depend on the loaded value must not be
// reordered to before this load. So no DLL reorderings past this
// load from after to before (up). So we need a read barrier AFTER the
@@ -244,7 +246,7 @@ namespace AtomicInternal {
return value;
}
- case ::std::memory_order_acquire: {
+ case std::memory_order_acquire: {
// Loads in this thread must not be reordered to before this load.
// So no LL reorderings past this load from after to before (up).
// So we need a read barrier AFTER the load. It is a compiler only
@@ -254,35 +256,35 @@ namespace AtomicInternal {
return value;
}
- case ::std::memory_order_seq_cst: {
+ case std::memory_order_seq_cst: {
// There must be some global order in which all sequentially consistent
// atomic operations are considered to have happened in. On x86 and x64
// this is guaranteed by just a normal read as long as all writes use
// locked instructions like XHCG. See: http://goo.gl/U8xTK
//
// We still need to prevent the compiler from reordering the reads,
- // which is the same constraint as for ::std::memory_order_acquire.
+ // which is the same constraint as for std::memory_order_acquire.
const auto value = mValue;
compilerReadMemoryBarrier();
return value;
}
- case ::std::memory_order_release: // not available for load
- case ::std::memory_order_acq_rel: // not available for load
- default: // specified value is not a known ::std::memory_order
+ case std::memory_order_release: // not available for load
+ case std::memory_order_acq_rel: // not available for load
+ default: // specified value is not a known std::memory_order
MATHICGB_UNREACHABLE;
}
}
MATHICGB_INLINE
- void store(const T value, const ::std::memory_order order) {
+ void store(const T value, const std::memory_order order) {
switch (order) {
- case ::std::memory_order_relaxed:
+ case std::memory_order_relaxed:
// There are no reordering constraints here but we need to tell the
// compiler that it must actually write out the value to memory in
// a scenario like this:
//
- // x.store(1, ::std::memory_order_relaxed);
+ // x.store(1, std::memory_order_relaxed);
// while (true) {}
//
// So as for relaxed store we need either a volatile access or a memory
@@ -291,7 +293,7 @@ namespace AtomicInternal {
const_cast<volatile T&>(mValue) = value;
break;
- case ::std::memory_order_release:
+ case std::memory_order_release:
// Stores in this thread must not be reordered to after this store.
// So no SS reorderings past this load from before to after (down).
// So we need a barrier BEFORE the load. It is a compiler only barrier
@@ -300,9 +302,9 @@ namespace AtomicInternal {
mValue = value;
break;
- case ::std::memory_order_acq_rel:
- // Combine the guarantees for ::std::memory_order_acquire and
- // ::std::memory_order_release. So no loads moved up past here (SL) and
+ case std::memory_order_acq_rel:
+ // Combine the guarantees for std::memory_order_acquire and
+ // std::memory_order_release. So no loads moved up past here (SL) and
// no stores moved down past here (LL). We need a compiler barrier
// BEFORE the load to avoid LL and a CPU (+compiler) barrier AFTER the
// load to avoid SL, since x86 and x64 CPUs can in fact do SL
@@ -312,15 +314,15 @@ namespace AtomicInternal {
cpuReadWriteMemoryBarrier();
break;
- case ::std::memory_order_seq_cst:
+ case std::memory_order_seq_cst:
// All operations happen in a globally consistent total order.
seqCstStore(value, mValue);
break;
- case ::std::memory_order_consume: // not available for store
- case ::std::memory_order_acquire: // not available for store
- default: // specified value is not a known ::std::memory_order
+ case std::memory_order_consume: // not available for store
+ case std::memory_order_acquire: // not available for store
+ default: // specified value is not a known std::memory_order
MATHICGB_UNREACHABLE;
}
}
@@ -345,18 +347,18 @@ namespace AtomicInternal {
}
#endif
-/// This class is equivalent to ::std::atomic<T>. Some functions from the
-/// interface of ::std::atomic are missing - add them as necessary. Do not add
+/// This class is equivalent to std::atomic<T>. Some functions from the
+/// interface of std::atomic are missing - add them as necessary. Do not add
/// operator= and operator T() --- it is better to make the code explicit
/// about when and how loading and storing of atomic variables occurs.
///
/// The purpose of the class is that it performs far better than
-/// ::std::atomic for some implementations. For example the ::std::atomic in MSVC
+/// std::atomic for some implementations. For example the std::atomic in MSVC
/// 2012 performs a compare-and-swap operation on a load even with the
-/// paramter ::std::memory_order_relaxed.
+/// paramter std::memory_order_relaxed.
///
/// We force all the functions to be inline because they can contain switches
-/// on the value of ::std::memory_order. This will usually be a compile-time
+/// on the value of std::memory_order. This will usually be a compile-time
/// constant parameter so that after inlining the switch will disappear. Yet
/// the code size of the switch may make some compilers avoid the inline.
template<class T>
@@ -374,7 +376,7 @@ public:
MATHICGB_INLINE
void store(
const T value,
- const ::std::memory_order order = ::std::memory_order_seq_cst
+ const std::memory_order order = std::memory_order_seq_cst
) {
MATHICGB_ASSERT(debugAligned());
mValue.store(value, order);
@@ -392,4 +394,5 @@ private:
};
MATHICGB_NAMESPACE_END
+
#endif
diff --git a/src/mathicgb/Basis.hpp b/src/mathicgb/Basis.hpp
index 44af198..acea0a3 100755
--- a/src/mathicgb/Basis.hpp
+++ b/src/mathicgb/Basis.hpp
@@ -20,13 +20,13 @@ class Basis {
public:
Basis(const PolyRing &R) : mRing(R) {}
Basis(Basis&& basis):
- mRing(basis.ring()), mGenerators(::std::move(basis.mGenerators)) {}
+ mRing(basis.ring()), mGenerators(std::move(basis.mGenerators)) {}
- void insert(::std::unique_ptr<Poly>&& p);
+ void insert(std::unique_ptr<Poly>&& p);
/// inverse operation to parse().
void display(
- ::std::ostream &o,
+ std::ostream &o,
bool print_comp,
bool componentIncreasingDesired
) const;
@@ -34,7 +34,7 @@ public:
const PolyRing& ring() const { return mRing; }
const PolyRing *getPolyRing() const { return &mRing; }
- const ::std::vector< ::std::unique_ptr<Poly>>& viewGenerators() {
+ const std::vector< std::unique_ptr<Poly>>& viewGenerators() {
return mGenerators;
}
const Poly *getPoly(size_t i) const {
@@ -51,7 +51,7 @@ private:
Basis(const Basis&); // not available
const PolyRing& mRing;
- ::std::vector< ::std::unique_ptr<Poly>> mGenerators;
+ std::vector< std::unique_ptr<Poly>> mGenerators;
};
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/CFile.hpp b/src/mathicgb/CFile.hpp
index 257e239..c4293bb 100755
--- a/src/mathicgb/CFile.hpp
+++ b/src/mathicgb/CFile.hpp
@@ -22,10 +22,10 @@ public:
/// Sets the handle to null if the file cannot be opened - does not
/// throw an exception. The purpose of the NoTrowTag parameter is only
/// to indicate that no exception should be thrown on error.
- CFile(const ::std::string& fileName, const char* mode, NoThrowTag);
+ CFile(const std::string& fileName, const char* mode, NoThrowTag);
/// Opens the file and throws an exception if the file cannot be opened.
- CFile(const ::std::string& fileName, const char* mode);
+ CFile(const std::string& fileName, const char* mode);
~CFile();
diff --git a/src/mathicgb/DivisorLookup.hpp b/src/mathicgb/DivisorLookup.hpp
index 009de78..860a41d 100755
--- a/src/mathicgb/DivisorLookup.hpp
+++ b/src/mathicgb/DivisorLookup.hpp
@@ -40,27 +40,27 @@ public:
// but the outcome must be deterministic.
virtual size_t classicReducer(const_monomial mon) const = 0;
- virtual ::std::string getName() const = 0;
+ virtual std::string getName() const = 0;
virtual size_t getMemoryUse() const = 0;
virtual size_t highBaseDivisor(size_t newGenerator) const = 0;
virtual void lowBaseDivisors(
- ::std::vector<size_t>& divisors,
+ std::vector<size_t>& divisors,
size_t maxDivisors,
size_t newGenerator) const = 0;
virtual size_t minimalLeadInSig(const_monomial sig) const = 0;
virtual int type() const = 0;
- static void displayDivisorLookupTypes(::std::ostream &o);
+ static void displayDivisorLookupTypes(std::ostream &o);
class Factory {
public:
- virtual ::std::unique_ptr<DivisorLookup> create
+ virtual std::unique_ptr<DivisorLookup> create
(bool preferSparseReducers, bool allowRemovals) const = 0;
};
- static ::std::unique_ptr<Factory> makeFactory
+ static std::unique_ptr<Factory> makeFactory
(const PolyRing& ring, int type);
// choices for type: 1: divlist, 2:kdtree.
diff --git a/src/mathicgb/F4MatrixBuilder.cpp b/src/mathicgb/F4MatrixBuilder.cpp
index c5bf37f..988aa25 100755
--- a/src/mathicgb/F4MatrixBuilder.cpp
+++ b/src/mathicgb/F4MatrixBuilder.cpp
@@ -4,7 +4,6 @@
#include "F4MatrixBuilder.hpp"
#include "LogDomain.hpp"
-#include "mtbb.hpp"
MATHICGB_DEFINE_LOG_DOMAIN(
F4MatrixBuild,
@@ -14,7 +13,7 @@ MATHICGB_DEFINE_LOG_DOMAIN(
MATHICGB_NAMESPACE_BEGIN
MATHICGB_NO_INLINE
-::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
F4MatrixBuilder::findOrCreateColumn(
const const_monomial monoA,
const const_monomial monoB,
@@ -24,12 +23,12 @@ F4MatrixBuilder::findOrCreateColumn(
MATHICGB_ASSERT(!monoB.isNull());
const auto col = ColReader(mMap).findProduct(monoA, monoB);
if (col.first != 0)
- return ::std::make_pair(*col.first, col.second);
+ return std::make_pair(*col.first, col.second);
return createColumn(monoA, monoB, feeder);
}
MATHICGB_INLINE
-::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
F4MatrixBuilder::findOrCreateColumn(
const const_monomial monoA,
const const_monomial monoB,
@@ -41,7 +40,7 @@ F4MatrixBuilder::findOrCreateColumn(
const auto col = colMap.findProduct(monoA, monoB);
if (col.first == 0)
return findOrCreateColumn(monoA, monoB, feeder);
- return ::std::make_pair(*col.first, col.second);
+ return std::make_pair(*col.first, col.second);
}
MATHICGB_NO_INLINE
@@ -70,7 +69,7 @@ F4MatrixBuilder::F4MatrixBuilder(
{
// This assert to be _NO_ASSUME since otherwise the compiler will assume that
// the error checking branch here cannot be taken and optimize it away.
- const Scalar maxScalar = ::std::numeric_limits<Scalar>::max();
+ const Scalar maxScalar = std::numeric_limits<Scalar>::max();
MATHICGB_ASSERT_NO_ASSUME(ring().charac() <= maxScalar);
if (ring().charac() > maxScalar)
mathic::reportInternalError("F4MatrixBuilder: too large characteristic.");
@@ -138,19 +137,19 @@ void F4MatrixBuilder::buildMatrixAndClear(QuadMatrix& matrix) {
monomial tmp2;
};
- mgb::tbb::enumerable_thread_specific<ThreadData> threadData([&](){
+ mgb::mtbb::enumerable_thread_specific<ThreadData> threadData([&](){
ThreadData data = {QuadMatrixBuilder(
ring(), mMap, mMonomialsLeft, mMonomialsRight, mBuilder.memoryQuantum()
)};
{
- mgb::tbb::mutex::scoped_lock guard(mCreateColumnLock);
+ mgb::mtbb::mutex::scoped_lock guard(mCreateColumnLock);
data.tmp1 = ring().allocMonomial();
data.tmp2 = ring().allocMonomial();
}
- return ::std::move(data);
+ return std::move(data);
});
- mgb::tbb::parallel_do(mTodo.begin(), mTodo.end(),
+ mgb::mtbb::parallel_do(mTodo.begin(), mTodo.end(),
[&](const RowTask& task, TaskFeeder& feeder)
{
auto& data = threadData.local();
@@ -230,7 +229,7 @@ void F4MatrixBuilder::buildMatrixAndClear(QuadMatrix& matrix) {
mMap.clearNonConcurrent();
}
-::std::pair<F4MatrixBuilder::LeftRightColIndex, ConstMonomial>
+std::pair<F4MatrixBuilder::LeftRightColIndex, ConstMonomial>
F4MatrixBuilder::createColumn(
const const_monomial monoA,
const const_monomial monoB,
@@ -239,12 +238,12 @@ F4MatrixBuilder::createColumn(
MATHICGB_ASSERT(!monoA.isNull());
MATHICGB_ASSERT(!monoB.isNull());
- mgb::tbb::mutex::scoped_lock lock(mCreateColumnLock);
+ mgb::mtbb::mutex::scoped_lock lock(mCreateColumnLock);
// see if the column exists now after we have synchronized
{
const auto found(ColReader(mMap).findProduct(monoA, monoB));
if (found.first != 0)
- return ::std::make_pair(*found.first, found.second);
+ return std::make_pair(*found.first, found.second);
}
// The column really does not exist, so we need to create it
@@ -258,10 +257,10 @@ F4MatrixBuilder::createColumn(
// Create the new left or right column
auto& colCount = insertLeft ? mLeftColCount : mRightColCount;
- if (colCount == ::std::numeric_limits<ColIndex>::max())
- throw ::std::overflow_error("Too many columns in QuadMatrix");
+ if (colCount == std::numeric_limits<ColIndex>::max())
+ throw std::overflow_error("Too many columns in QuadMatrix");
const auto inserted = mMap.insert
- (::std::make_pair(mTmp, LeftRightColIndex(colCount, insertLeft)));
+ (std::make_pair(mTmp, LeftRightColIndex(colCount, insertLeft)));
++colCount;
MATHICGB_ASSERT(inserted.second);
MATHICGB_ASSERT(inserted.first.first != 0);
@@ -275,7 +274,7 @@ F4MatrixBuilder::createColumn(
feeder.add(task);
}
- return ::std::make_pair(*inserted.first.first, inserted.first.second);
+ return std::make_pair(*inserted.first.first, inserted.first.second);
}
void F4MatrixBuilder::appendRowBottom(
@@ -307,7 +306,7 @@ updateReader:
MATHICGB_ASSERT(origScalar != 0);
const auto maybeNegated =
negate ? ring().coefficientNegateNonZero(origScalar) : origScalar;
- MATHICGB_ASSERT(maybeNegated < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(maybeNegated < std::numeric_limits<Scalar>::max());
builder.appendEntryBottom(*col.first, static_cast<Scalar>(maybeNegated));
}
builder.rowDoneBottomLeftAndRight();
@@ -325,11 +324,11 @@ void F4MatrixBuilder::appendRowTop(
auto it = poly.begin();
const auto end = poly.end();
- if ((::std::distance(it, end) % 2) == 1) {
+ if ((std::distance(it, end) % 2) == 1) {
ColReader reader(mMap);
const auto col = findOrCreateColumn
(it.getMonomial(), multiple, reader, feeder);
- MATHICGB_ASSERT(it.getCoefficient() < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(it.getCoefficient() < std::numeric_limits<Scalar>::max());
MATHICGB_ASSERT(it.getCoefficient());
builder.appendEntryTop
(col.first, static_cast<Scalar>(it.getCoefficient()));
@@ -337,16 +336,16 @@ void F4MatrixBuilder::appendRowTop(
}
updateReader:
ColReader colMap(mMap);
- MATHICGB_ASSERT((::std::distance(it, end) % 2) == 0);
+ MATHICGB_ASSERT((std::distance(it, end) % 2) == 0);
while (it != end) {
- MATHICGB_ASSERT(it.getCoefficient() < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(it.getCoefficient() < std::numeric_limits<Scalar>::max());
MATHICGB_ASSERT(it.getCoefficient() != 0);
const auto scalar1 = static_cast<Scalar>(it.getCoefficient());
const const_monomial mono1 = it.getMonomial();
auto it2 = it;
++it2;
- MATHICGB_ASSERT(it2.getCoefficient() < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(it2.getCoefficient() < std::numeric_limits<Scalar>::max());
MATHICGB_ASSERT(it2.getCoefficient() != 0);
const auto scalar2 = static_cast<Scalar>(it2.getCoefficient());
const const_monomial mono2 = it2.getMonomial();
@@ -424,7 +423,7 @@ void F4MatrixBuilder::appendRowBottom(
col = colB.first;
++itB;
}
- MATHICGB_ASSERT(coeff < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(coeff < std::numeric_limits<Scalar>::max());
if (coeff != 0)
builder.appendEntryBottom(col, static_cast<Scalar>(coeff));
}
diff --git a/src/mathicgb/F4MatrixBuilder.hpp b/src/mathicgb/F4MatrixBuilder.hpp
index 91a53e6..63a3750 100755
--- a/src/mathicgb/F4MatrixBuilder.hpp
+++ b/src/mathicgb/F4MatrixBuilder.hpp
@@ -85,13 +85,13 @@ private:
const Poly* sPairPoly;
monomial sPairMultiply;
};
- typedef ::mgb::tbb::parallel_do_feeder<RowTask> TaskFeeder;
+ typedef ::mgb::mtbb::parallel_do_feeder<RowTask> TaskFeeder;
/// Creates a column with monomial label x and schedules a new row to
/// reduce that column if possible. Here x is monoA if monoB is
/// null and otherwise x is the product of monoA and monoB.
MATHICGB_NO_INLINE
- ::std::pair<LeftRightColIndex, ConstMonomial>
+ std::pair<LeftRightColIndex, ConstMonomial>
createColumn(
const_monomial monoA,
const_monomial monoB,
@@ -122,7 +122,7 @@ private:
);
MATHICGB_NO_INLINE
- ::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+ std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
findOrCreateColumn(
const_monomial monoA,
const_monomial monoB,
@@ -130,7 +130,7 @@ private:
);
MATHICGB_INLINE
- ::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+ std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
findOrCreateColumn(
const_monomial monoA,
const_monomial monoB,
@@ -146,7 +146,7 @@ private:
TaskFeeder& feeder
);
- mgb::tbb::mutex mCreateColumnLock;
+ mgb::mtbb::mutex mCreateColumnLock;
ColIndex mLeftColCount;
ColIndex mRightColCount;
monomial mTmp;
@@ -155,7 +155,7 @@ private:
Monomials mMonomialsRight;
QuadMatrixBuilder mBuilder;
Map mMap;
- ::std::vector<RowTask> mTodo;
+ std::vector<RowTask> mTodo;
};
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/F4MatrixBuilder2.cpp b/src/mathicgb/F4MatrixBuilder2.cpp
index 3fc82d8..dcdf43a 100755
--- a/src/mathicgb/F4MatrixBuilder2.cpp
+++ b/src/mathicgb/F4MatrixBuilder2.cpp
@@ -19,7 +19,7 @@ MATHICGB_DEFINE_LOG_DOMAIN(
MATHICGB_NAMESPACE_BEGIN
MATHICGB_NO_INLINE
-::std::pair<F4MatrixBuilder2::ColIndex, ConstMonomial>
+std::pair<F4MatrixBuilder2::ColIndex, ConstMonomial>
F4MatrixBuilder2::findOrCreateColumn(
const const_monomial monoA,
const const_monomial monoB,
@@ -29,12 +29,12 @@ F4MatrixBuilder2::findOrCreateColumn(
MATHICGB_ASSERT(!monoB.isNull());
const auto col = ColReader(mMap).findProduct(monoA, monoB);
if (col.first != 0)
- return ::std::make_pair(*col.first, col.second);
+ return std::make_pair(*col.first, col.second);
return createColumn(monoA, monoB, feeder);
}
MATHICGB_INLINE
-::std::pair<F4MatrixBuilder2::ColIndex, ConstMonomial>
+std::pair<F4MatrixBuilder2::ColIndex, ConstMonomial>
F4MatrixBuilder2::findOrCreateColumn(
const const_monomial monoA,
const const_monomial monoB,
@@ -46,7 +46,7 @@ F4MatrixBuilder2::findOrCreateColumn(
const auto col = colMap.findProduct(monoA, monoB);
if (col.first == 0)
return findOrCreateColumn(monoA, monoB, feeder);
- return ::std::make_pair(*col.first, col.second);
+ return std::make_pair(*col.first, col.second);
}
MATHICGB_NO_INLINE
@@ -71,7 +71,7 @@ F4MatrixBuilder2::F4MatrixBuilder2(
{
// This assert has to be _NO_ASSUME since otherwise the compiler will assume
// that the error checking branch here cannot be taken and optimize it away.
- const Scalar maxScalar = ::std::numeric_limits<Scalar>::max();
+ const Scalar maxScalar = std::numeric_limits<Scalar>::max();
MATHICGB_ASSERT_NO_ASSUME(ring().charac() <= maxScalar);
if (ring().charac() > maxScalar)
mathic::reportInternalError("F4MatrixBuilder2: too large characteristic.");
@@ -132,7 +132,7 @@ void F4MatrixBuilder2::buildMatrixAndClear(QuadMatrix& quadMatrix) {
// Use halves of S-pairs as reducers to decrease the number of entries that
// need to be looked up.
- mgb::tbb::parallel_sort(mTodo.begin(), mTodo.end(),
+ mgb::mtbb::parallel_sort(mTodo.begin(), mTodo.end(),
[&](const RowTask& a, const RowTask& b)
{
if (a.sPairPoly == 0)
@@ -150,11 +150,11 @@ void F4MatrixBuilder2::buildMatrixAndClear(QuadMatrix& quadMatrix) {
MATHICGB_ASSERT(ColReader(mMap).find(mTodo[i].desiredLead).first == 0);
// Create column for the lead term that cancels in the S-pair
- if (mIsColumnToLeft.size() >= ::std::numeric_limits<ColIndex>::max())
- throw ::std::overflow_error("Too many columns in QuadMatrix");
+ if (mIsColumnToLeft.size() >= std::numeric_limits<ColIndex>::max())
+ throw std::overflow_error("Too many columns in QuadMatrix");
const auto newIndex = static_cast<ColIndex>(mIsColumnToLeft.size());
const auto inserted =
- mMap.insert(::std::make_pair(mTodo[i].desiredLead, newIndex));
+ mMap.insert(std::make_pair(mTodo[i].desiredLead, newIndex));
mIsColumnToLeft.push_back(true);
const auto& mono = inserted.first.second;
@@ -201,18 +201,18 @@ void F4MatrixBuilder2::buildMatrixAndClear(QuadMatrix& quadMatrix) {
monomial tmp2;
};
- mgb::tbb::enumerable_thread_specific<ThreadData> threadData([&](){
+ mgb::mtbb::enumerable_thread_specific<ThreadData> threadData([&](){
ThreadData data;
{
- mgb::tbb::mutex::scoped_lock guard(mCreateColumnLock);
+ mgb::mtbb::mutex::scoped_lock guard(mCreateColumnLock);
data.tmp1 = ring().allocMonomial();
data.tmp2 = ring().allocMonomial();
}
- return ::std::move(data);
+ return std::move(data);
});
// Construct the matrix as pre-blocks
- mgb::tbb::parallel_do(mTodo.begin(), mTodo.end(),
+ mgb::mtbb::parallel_do(mTodo.begin(), mTodo.end(),
[&](const RowTask& task, TaskFeeder& feeder)
{
auto& data = threadData.local();
@@ -260,19 +260,19 @@ void F4MatrixBuilder2::buildMatrixAndClear(QuadMatrix& quadMatrix) {
(ring(), static_cast<ColIndex>(mMap.entryCount()));
const auto end = threadData.end();
for (auto it = threadData.begin(); it != end; ++it) {
- projection.addProtoMatrix(::std::move(it->block));
+ projection.addProtoMatrix(std::move(it->block));
ring().freeMonomial(it->tmp1);
ring().freeMonomial(it->tmp2);
}
// Sort columns by monomial and tell the projection of the resulting order
MonomialMap<ColIndex>::Reader reader(mMap);
- typedef ::std::pair<ColIndex, ConstMonomial> IndexMono;
- ::std::vector<IndexMono> columns(reader.begin(), reader.end());
+ typedef std::pair<ColIndex, ConstMonomial> IndexMono;
+ std::vector<IndexMono> columns(reader.begin(), reader.end());
const auto cmp = [&](const IndexMono& a, const IndexMono b) {
return ring().monomialLT(b.second, a.second);
};
- mgb::tbb::parallel_sort(columns.begin(), columns.end(), cmp);
+ mgb::mtbb::parallel_sort(columns.begin(), columns.end(), cmp);
const auto colEnd = columns.end();
for (auto it = columns.begin(); it != colEnd; ++it) {
@@ -289,7 +289,7 @@ void F4MatrixBuilder2::buildMatrixAndClear(QuadMatrix& quadMatrix) {
<< " by "
<< mathic::ColumnPrinter::commafy(
quadMatrix.computeLeftColCount() + quadMatrix.computeRightColCount())
- << "]" << ::std::endl;
+ << "]" << std::endl;
#ifdef MATHICGB_DEBUG
for (size_t side = 0; side < 2; ++side) {
@@ -307,7 +307,7 @@ void F4MatrixBuilder2::buildMatrixAndClear(QuadMatrix& quadMatrix) {
#endif
}
-::std::pair<F4MatrixBuilder2::ColIndex, ConstMonomial>
+std::pair<F4MatrixBuilder2::ColIndex, ConstMonomial>
F4MatrixBuilder2::createColumn(
const const_monomial monoA,
const const_monomial monoB,
@@ -316,12 +316,12 @@ F4MatrixBuilder2::createColumn(
MATHICGB_ASSERT(!monoA.isNull());
MATHICGB_ASSERT(!monoB.isNull());
- mgb::tbb::mutex::scoped_lock lock(mCreateColumnLock);
+ mgb::mtbb::mutex::scoped_lock lock(mCreateColumnLock);
// see if the column exists now after we have synchronized
{
const auto found(ColReader(mMap).findProduct(monoA, monoB));
if (found.first != 0)
- return ::std::make_pair(*found.first, found.second);
+ return std::make_pair(*found.first, found.second);
}
// The column really does not exist, so we need to create it
@@ -334,10 +334,10 @@ F4MatrixBuilder2::createColumn(
const bool insertLeft = (reducerIndex != static_cast<size_t>(-1));
// Create the new left or right column
- if (mIsColumnToLeft.size() >= ::std::numeric_limits<ColIndex>::max())
- throw ::std::overflow_error("Too many columns in QuadMatrix");
+ if (mIsColumnToLeft.size() >= std::numeric_limits<ColIndex>::max())
+ throw std::overflow_error("Too many columns in QuadMatrix");
const auto newIndex = static_cast<ColIndex>(mIsColumnToLeft.size());
- const auto inserted = mMap.insert(::std::make_pair(mTmp, newIndex));
+ const auto inserted = mMap.insert(std::make_pair(mTmp, newIndex));
mIsColumnToLeft.push_back(insertLeft);
// schedule new task if we found a reducer
@@ -348,7 +348,7 @@ F4MatrixBuilder2::createColumn(
feeder.add(task);
}
- return ::std::make_pair(*inserted.first.first, inserted.first.second);
+ return std::make_pair(*inserted.first.first, inserted.first.second);
}
void F4MatrixBuilder2::appendRow(
@@ -361,8 +361,8 @@ void F4MatrixBuilder2::appendRow(
const auto begin = poly.begin();
const auto end = poly.end();
- const auto count = static_cast<size_t>(::std::distance(begin, end));
- MATHICGB_ASSERT(count < ::std::numeric_limits<ColIndex>::max());
+ const auto count = static_cast<size_t>(std::distance(begin, end));
+ MATHICGB_ASSERT(count < std::numeric_limits<ColIndex>::max());
auto indices = block.makeRowWithTheseScalars(poly);
auto it = begin;
@@ -370,7 +370,7 @@ void F4MatrixBuilder2::appendRow(
ColReader reader(mMap);
const auto col = findOrCreateColumn
(it.getMonomial(), multiple, reader, feeder);
- MATHICGB_ASSERT(it.getCoefficient() < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(it.getCoefficient() < std::numeric_limits<Scalar>::max());
MATHICGB_ASSERT(it.getCoefficient());
//matrix.appendEntry(col.first, static_cast<Scalar>(it.getCoefficient()));
*indices = col.first;
@@ -381,16 +381,16 @@ void F4MatrixBuilder2::appendRow(
}
updateReader:
ColReader colMap(mMap);
- MATHICGB_ASSERT((::std::distance(it, end) % 2) == 0);
+ MATHICGB_ASSERT((std::distance(it, end) % 2) == 0);
while (it != end) {
- MATHICGB_ASSERT(it.getCoefficient() < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(it.getCoefficient() < std::numeric_limits<Scalar>::max());
MATHICGB_ASSERT(it.getCoefficient() != 0);
const auto scalar1 = static_cast<Scalar>(it.getCoefficient());
const const_monomial mono1 = it.getMonomial();
auto it2 = it;
++it2;
- MATHICGB_ASSERT(it2.getCoefficient() < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(it2.getCoefficient() < std::numeric_limits<Scalar>::max());
MATHICGB_ASSERT(it2.getCoefficient() != 0);
const auto scalar2 = static_cast<Scalar>(it2.getCoefficient());
const const_monomial mono2 = it2.getMonomial();
@@ -445,7 +445,7 @@ void F4MatrixBuilder2::appendRowSPair(
// @todo: handle overflow of termCount addition here
MATHICGB_ASSERT(poly->termCount() + sPairPoly->termCount() - 2 <=
- ::std::numeric_limits<ColIndex>::max());
+ std::numeric_limits<ColIndex>::max());
const auto maxCols =
static_cast<ColIndex>(poly->termCount() + sPairPoly->termCount() - 2);
auto row = block.makeRow(maxCols);
@@ -474,7 +474,7 @@ void F4MatrixBuilder2::appendRowSPair(
col = colB.first;
++itB;
}
- MATHICGB_ASSERT(coeff < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(coeff < std::numeric_limits<Scalar>::max());
if (coeff != 0) {
//matrix.appendEntry(col, static_cast<Scalar>(coeff));
*row.first++ = col;
diff --git a/src/mathicgb/F4MatrixBuilder2.hpp b/src/mathicgb/F4MatrixBuilder2.hpp
index ab6bb1b..dde14f0 100755
--- a/src/mathicgb/F4MatrixBuilder2.hpp
+++ b/src/mathicgb/F4MatrixBuilder2.hpp
@@ -72,7 +72,7 @@ public:
private:
typedef const Map::Reader ColReader;
- typedef ::std::vector<monomial> Monomials;
+ typedef std::vector<monomial> Monomials;
/// Represents the task of adding a row to the matrix. If sPairPoly is null
/// then the row to add is multiply * poly. Otherwise, the row to add is
@@ -84,13 +84,13 @@ private:
const Poly* poly;
const Poly* sPairPoly;
};
- typedef mgb::tbb::parallel_do_feeder<RowTask> TaskFeeder;
+ typedef mgb::mtbb::parallel_do_feeder<RowTask> TaskFeeder;
/// Creates a column with monomial label x and schedules a new row to
/// reduce that column if possible. Here x is monoA if monoB is
/// null and otherwise x is the product of monoA and monoB.
MATHICGB_NO_INLINE
- ::std::pair<ColIndex, ConstMonomial> createColumn(
+ std::pair<ColIndex, ConstMonomial> createColumn(
const_monomial monoA,
const_monomial monoB,
TaskFeeder& feeder
@@ -112,14 +112,14 @@ private:
);
MATHICGB_NO_INLINE
- ::std::pair<ColIndex, ConstMonomial> findOrCreateColumn(
+ std::pair<ColIndex, ConstMonomial> findOrCreateColumn(
const_monomial monoA,
const_monomial monoB,
TaskFeeder& feeder
);
MATHICGB_INLINE
- ::std::pair<ColIndex, ConstMonomial> findOrCreateColumn(
+ std::pair<ColIndex, ConstMonomial> findOrCreateColumn(
const_monomial monoA,
const_monomial monoB,
const ColReader& colMap,
@@ -134,13 +134,13 @@ private:
TaskFeeder& feeder
);
- ::std::vector<char> mIsColumnToLeft;
+ std::vector<char> mIsColumnToLeft;
const size_t mMemoryQuantum;
- mgb::tbb::mutex mCreateColumnLock;
+ mgb::mtbb::mutex mCreateColumnLock;
monomial mTmp;
const PolyBasis& mBasis;
Map mMap;
- ::std::vector<RowTask> mTodo;
+ std::vector<RowTask> mTodo;
};
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/F4MatrixProjection.cpp b/src/mathicgb/F4MatrixProjection.cpp
index 0855170..a59321d 100755
--- a/src/mathicgb/F4MatrixProjection.cpp
+++ b/src/mathicgb/F4MatrixProjection.cpp
@@ -47,27 +47,27 @@ struct RowData : F4ProtoMatrix::Row {
RowData(const F4ProtoMatrix::Row& row): F4ProtoMatrix::Row(row) {}
};
-typedef ::std::pair<RowData, SparseMatrix::Scalar> RowProjectFrom;
+typedef std::pair<RowData, SparseMatrix::Scalar> RowProjectFrom;
template<class Row>
class F4MatrixProjection::TopBottom {
public:
- typedef ::std::pair<Row, Scalar> RowMultiple;
- typedef ::std::vector<RowMultiple> RowVector;
+ typedef std::pair<Row, Scalar> RowMultiple;
+ typedef std::vector<RowMultiple> RowVector;
TopBottom(const size_t leftColCount, const PolyRing& ring):
mModulus(static_cast<Scalar>(ring.charac())),
mTopRows(leftColCount)
{
- MATHICGB_ASSERT(ring.charac() <= ::std::numeric_limits<Scalar>::max());
- MATHICGB_ASSERT(leftColCount <= ::std::numeric_limits<ColIndex>::max());
+ MATHICGB_ASSERT(ring.charac() <= std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(leftColCount <= std::numeric_limits<ColIndex>::max());
}
void addRow(const Row& row, ColIndex leadIndex, Scalar leadScalar) {
if (row.entryCount == 0)
return; // Skip zero rows.
- if (leadIndex == ::std::numeric_limits<ColIndex>::max()) {
+ if (leadIndex == std::numeric_limits<ColIndex>::max()) {
// this row has no left entries, so it cannot be a top row.
mBottomRows.push_back(RowMultiple(row, 1));
return;
@@ -81,7 +81,7 @@ public:
mBottomRows.push_back(RowMultiple(row, 1));
} else {
if (currentTop.entryCount != 0)
- mBottomRows.push_back(::std::make_pair(currentTop, 1));
+ mBottomRows.push_back(std::make_pair(currentTop, 1));
MATHICGB_ASSERT(leadScalar != 0);
const auto inverse = leadScalar == 1 ? // 1 is a common case
1 : modularInverse(leadScalar, mModulus);
@@ -95,8 +95,8 @@ public:
MATHICGB_ASSERT(r.first.entryCount > 0);
MATHICGB_ASSERT(r.second != 0);
};
- ::std::for_each(mTopRows.begin(), mTopRows.end(), check);
- ::std::for_each(mBottomRows.begin(), mBottomRows.end(), check);
+ std::for_each(mTopRows.begin(), mTopRows.end(), check);
+ std::for_each(mBottomRows.begin(), mBottomRows.end(), check);
#endif
return true;
}
@@ -120,7 +120,7 @@ public:
typedef F4ProtoMatrix::Row Row;
LeftRight(
- const ::std::vector<ColProjectTo>& colProjectTo,
+ const std::vector<ColProjectTo>& colProjectTo,
const PolyRing& ring,
const size_t quantum
):
@@ -129,19 +129,19 @@ public:
mLeft(quantum),
mRight(quantum)
{
- MATHICGB_ASSERT(ring.charac() < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(ring.charac() < std::numeric_limits<Scalar>::max());
mLeft.clear();
mRight.clear();
}
template<class Pair>
- void appendRowsPermuted(const ::std::vector<Pair>& rows) {
+ void appendRowsPermuted(const std::vector<Pair>& rows) {
const auto end = rows.end();
for (auto it = rows.begin(); it != end; ++it)
appendRow(it->first, it->second);
}
- void appendRows(const ::std::vector<F4ProtoMatrix*>& preBlocks) {
+ void appendRows(const std::vector<F4ProtoMatrix*>& preBlocks) {
const auto end = preBlocks.end();
for (auto it = preBlocks.begin(); it != end; ++it) {
auto& block = **it;
@@ -198,7 +198,7 @@ public:
}
void appendEntry(const ColIndex projectMe, const ExternalScalar scalar) {
- MATHICGB_ASSERT(scalar <= ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(scalar <= std::numeric_limits<Scalar>::max());
appendEntry(projectMe, static_cast<Scalar>(scalar));
}
@@ -211,11 +211,11 @@ public:
const SparseMatrix& left() const {return mLeft;}
const SparseMatrix& right() const {return mRight;}
- SparseMatrix moveLeft() {return ::std::move(mLeft);}
- SparseMatrix moveRight() {return ::std::move(mRight);}
+ SparseMatrix moveLeft() {return std::move(mLeft);}
+ SparseMatrix moveRight() {return std::move(mRight);}
private:
- const ::std::vector<ColProjectTo>& mColProjectTo;
+ const std::vector<ColProjectTo>& mColProjectTo;
const Scalar mModulus;
SparseMatrix mLeft;
@@ -255,7 +255,7 @@ QuadMatrix F4MatrixProjection::makeAndClearOneStep(const size_t quantum) {
}
}
// Did not find any left entry.
- tb.addRow(row, ::std::numeric_limits<ColIndex>::max(), 0);
+ tb.addRow(row, std::numeric_limits<ColIndex>::max(), 0);
done:;
}
}
@@ -271,21 +271,21 @@ done:;
// Move the data into place
QuadMatrix qm;
qm.ring = &ring();
- qm.leftColumnMonomials = ::std::move(mLeftMonomials);
- qm.rightColumnMonomials = ::std::move(mRightMonomials);
+ qm.leftColumnMonomials = std::move(mLeftMonomials);
+ qm.rightColumnMonomials = std::move(mRightMonomials);
qm.topLeft = top.moveLeft();
qm.topRight = top.moveRight();
qm.bottomLeft = bottom.moveLeft();
qm.bottomRight = bottom.moveRight();
- return ::std::move(qm);
+ return std::move(qm);
}
namespace {
// Helper function for F4MatrixProjection::makeAndClearTwoStep
template<class TopBottom>
- ::std::pair<SparseMatrix, SparseMatrix> projectRows(
+ std::pair<SparseMatrix, SparseMatrix> projectRows(
const TopBottom& tb,
size_t quantum,
SparseMatrix&& in
@@ -313,7 +313,7 @@ namespace {
}
in.clear();
- return ::std::make_pair(::std::move(top), ::std::move(bottom));
+ return std::make_pair(std::move(top), std::move(bottom));
}
}
@@ -338,7 +338,7 @@ QuadMatrix F4MatrixProjection::makeAndClearTwoStep(const size_t quantum) {
const Row r = {row, entryCount};
if (leftEntryCount == 0)
- tb.addRow(r, ::std::numeric_limits<ColIndex>::max(), 0);
+ tb.addRow(r, std::numeric_limits<ColIndex>::max(), 0);
else {
const auto entry = lr.left().rowBegin(row);
tb.addRow(r, entry.index(), entry.scalar());
@@ -351,13 +351,13 @@ QuadMatrix F4MatrixProjection::makeAndClearTwoStep(const size_t quantum) {
auto right = projectRows(tb, quantum, lr.moveRight());
qm.ring = &ring();
- qm.topLeft = ::std::move(left.first);
- qm.bottomLeft = ::std::move(left.second);
- qm.topRight = ::std::move(right.first);
- qm.bottomRight = ::std::move(right.second);
- qm.leftColumnMonomials = ::std::move(mLeftMonomials);
- qm.rightColumnMonomials = ::std::move(mRightMonomials);
- return ::std::move(qm);
+ qm.topLeft = std::move(left.first);
+ qm.bottomLeft = std::move(left.second);
+ qm.topRight = std::move(right.first);
+ qm.bottomRight = std::move(right.second);
+ qm.leftColumnMonomials = std::move(mLeftMonomials);
+ qm.rightColumnMonomials = std::move(mRightMonomials);
+ return std::move(qm);
}
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/F4MatrixProjection.hpp b/src/mathicgb/F4MatrixProjection.hpp
index 66c8ffc..16eebed 100755
--- a/src/mathicgb/F4MatrixProjection.hpp
+++ b/src/mathicgb/F4MatrixProjection.hpp
@@ -45,11 +45,11 @@ private:
ColIndex index;
bool isLeft;
};
- ::std::vector<ColProjectTo> mColProjectTo;
+ std::vector<ColProjectTo> mColProjectTo;
- ::std::vector<F4ProtoMatrix*> mMatrices;
- ::std::vector<monomial> mLeftMonomials;
- ::std::vector<monomial> mRightMonomials;
+ std::vector<F4ProtoMatrix*> mMatrices;
+ std::vector<monomial> mLeftMonomials;
+ std::vector<monomial> mRightMonomials;
const PolyRing& mRing;
};
diff --git a/src/mathicgb/F4MatrixReducer.cpp b/src/mathicgb/F4MatrixReducer.cpp
index f556901..8a8cc27 100755
--- a/src/mathicgb/F4MatrixReducer.cpp
+++ b/src/mathicgb/F4MatrixReducer.cpp
@@ -151,7 +151,7 @@ namespace {
// method).
auto it = begin;
- if (::std::distance(begin, end) % 2 == 1) {
+ if (std::distance(begin, end) % 2 == 1) {
// Replacing this by a goto into the middle of the following loop
// (similar to Duff's device) made the code slower on MSVC 2012.
multiplyAdd(it.scalar(), multiple, entries[it.index()]);
@@ -188,7 +188,7 @@ namespace {
}
private:
- ::std::vector<ScalarProductSum> mEntries;
+ std::vector<ScalarProductSum> mEntries;
};
SparseMatrix reduce(
@@ -214,10 +214,10 @@ namespace {
// Store column indexes instead of row indices as the matrix is square
// anyway (so all indices fit) and we are going to store this as a column
// index later on.
- ::std::vector<SparseMatrix::ColIndex> rowThatReducesCol(pivotCount);
+ std::vector<SparseMatrix::ColIndex> rowThatReducesCol(pivotCount);
#ifdef MATHICGB_DEBUG
// fill in an invalid value that can be recognized by asserts to be invalid.
- ::std::fill(rowThatReducesCol.begin(), rowThatReducesCol.end(), pivotCount);
+ std::fill(rowThatReducesCol.begin(), rowThatReducesCol.end(), pivotCount);
#endif
for (SparseMatrix::ColIndex pivot = 0; pivot < pivotCount; ++pivot) {
MATHICGB_ASSERT(!reduceByLeft.emptyRow(pivot));
@@ -233,17 +233,17 @@ namespace {
SparseMatrix reduced(qm.topRight.memoryQuantum());
- mgb::tbb::enumerable_thread_specific<DenseRow> denseRowPerThread([&](){
+ mgb::mtbb::enumerable_thread_specific<DenseRow> denseRowPerThread([&](){
return DenseRow();
});
SparseMatrix tmp(qm.topRight.memoryQuantum());
- ::std::vector<SparseMatrix::RowIndex> rowOrder(rowCount);
+ std::vector<SparseMatrix::RowIndex> rowOrder(rowCount);
- mgb::tbb::mutex lock;
- mgb::tbb::parallel_for(mgb::tbb::blocked_range<SparseMatrix::RowIndex>(0, rowCount, 2),
- [&](const mgb::tbb::blocked_range<SparseMatrix::RowIndex>& range)
+ mgb::mtbb::mutex lock;
+ mgb::mtbb::parallel_for(mgb::mtbb::blocked_range<SparseMatrix::RowIndex>(0, rowCount, 2),
+ [&](const mgb::mtbb::blocked_range<SparseMatrix::RowIndex>& range)
{
auto& denseRow = denseRowPerThread.local();
for (auto it = range.begin(); it != range.end(); ++it) {
@@ -264,7 +264,7 @@ namespace {
MATHICGB_ASSERT(row < pivotCount);
MATHICGB_ASSERT(!reduceByLeft.emptyRow(row));
MATHICGB_ASSERT(reduceByLeft.leadCol(row) == pivot);
- MATHICGB_ASSERT(entry < ::std::numeric_limits<SparseMatrix::Scalar>::max());
+ MATHICGB_ASSERT(entry < std::numeric_limits<SparseMatrix::Scalar>::max());
denseRow.addRowMultiple(
static_cast<SparseMatrix::Scalar>(entry),
++reduceByLeft.rowBegin(row),
@@ -274,9 +274,9 @@ namespace {
}
}
}
- mgb::tbb::mutex::scoped_lock lockGuard(lock);
+ mgb::mtbb::mutex::scoped_lock lockGuard(lock);
for (size_t pivot = 0; pivot < pivotCount; ++pivot) {
- MATHICGB_ASSERT(denseRow[pivot] < ::std::numeric_limits<SparseMatrix::Scalar>::max());
+ MATHICGB_ASSERT(denseRow[pivot] < std::numeric_limits<SparseMatrix::Scalar>::max());
if (denseRow[pivot] != 0)
tmp.appendEntry(rowThatReducesCol[pivot], static_cast<SparseMatrix::Scalar>(denseRow[pivot]));
}
@@ -285,8 +285,8 @@ namespace {
}
});
- mgb::tbb::parallel_for(mgb::tbb::blocked_range<SparseMatrix::RowIndex>(0, rowCount),
- [&](const mgb::tbb::blocked_range<SparseMatrix::RowIndex>& range)
+ mgb::mtbb::parallel_for(mgb::mtbb::blocked_range<SparseMatrix::RowIndex>(0, rowCount),
+ [&](const mgb::mtbb::blocked_range<SparseMatrix::RowIndex>& range)
{for (auto iter = range.begin(); iter != range.end(); ++iter)
{
const auto i = iter;
@@ -303,7 +303,7 @@ namespace {
denseRow.addRowMultiple(it.scalar(), begin, end);
}
- mgb::tbb::mutex::scoped_lock lockGuard(lock);
+ mgb::mtbb::mutex::scoped_lock lockGuard(lock);
bool zero = true;
for (SparseMatrix::ColIndex col = 0; col < rightColCount; ++col) {
const auto entry =
@@ -316,7 +316,7 @@ namespace {
if (!zero)
reduced.rowDone();
}});
- return ::std::move(reduced);
+ return std::move(reduced);
}
SparseMatrix reduceToEchelonFormSparse(
@@ -329,7 +329,7 @@ namespace {
// pivotRowOfCol[i] is the pivot in column i or noRow
// if we have not identified such a pivot so far.
- ::std::vector<SparseMatrix::RowIndex> pivotRowOfCol(colCount, noRow);
+ std::vector<SparseMatrix::RowIndex> pivotRowOfCol(colCount, noRow);
DenseRow rowToReduce(colCount);
@@ -394,7 +394,7 @@ namespace {
pivotRowOfCol[pivotCol] = reduced.rowCount();
rowToReduce.appendTo(reduced);
}
- return ::std::move(reduced);
+ return std::move(reduced);
}
SparseMatrix reduceToEchelonForm(
@@ -405,9 +405,9 @@ namespace {
const auto rowCount = toReduce.rowCount();
// convert to dense representation
- ::std::vector<DenseRow> dense(rowCount);
- mgb::tbb::parallel_for(mgb::tbb::blocked_range<SparseMatrix::RowIndex>(0, rowCount),
- [&](const mgb::tbb::blocked_range<SparseMatrix::RowIndex>& range)
+ std::vector<DenseRow> dense(rowCount);
+ mgb::mtbb::parallel_for(mgb::mtbb::blocked_range<SparseMatrix::RowIndex>(0, rowCount),
+ [&](const mgb::mtbb::blocked_range<SparseMatrix::RowIndex>& range)
{for (auto it = range.begin(); it != range.end(); ++it)
{
const auto row = it;
@@ -418,31 +418,31 @@ namespace {
}});
// invariant: all columns in row to the left of leadCols[row] are zero.
- ::std::vector<SparseMatrix::ColIndex> leadCols(rowCount);
+ std::vector<SparseMatrix::ColIndex> leadCols(rowCount);
// pivot rows get copied here before being used to reduce the matrix.
SparseMatrix reduced(toReduce.memoryQuantum());
// (col,row) in nextReducers, then use row as a pivot in column col
// for the next iteration.
- ::std::vector< ::std::pair<SparseMatrix::ColIndex, SparseMatrix::RowIndex> > nextReducers;
+ std::vector< std::pair<SparseMatrix::ColIndex, SparseMatrix::RowIndex> > nextReducers;
// isPivotRow[row] is true if row is or has been used as a pivot.
- ::std::vector<bool> isPivotRow(rowCount);
+ std::vector<bool> isPivotRow(rowCount);
// columnHasPivot[col] is true if a pivot row for column col has
// been chosen.
- ::std::vector<bool> columnHasPivot(colCount);
+ std::vector<bool> columnHasPivot(colCount);
bool firstIteration = true;
while (firstIteration || reduced.rowCount() > 0) {
firstIteration = false;
size_t const reducerCount = reduced.rowCount();
- //::std::cout << "reducing " << reduced.rowCount() << " out of " << toReduce.rowCount() << ::std::endl;
- mgb::tbb::mutex lock;
- mgb::tbb::parallel_for(mgb::tbb::blocked_range<SparseMatrix::RowIndex>(0, rowCount),
- [&](const mgb::tbb::blocked_range<SparseMatrix::RowIndex>& range)
+ //std::cout << "reducing " << reduced.rowCount() << " out of " << toReduce.rowCount() << std::endl;
+ mgb::mtbb::mutex lock;
+ mgb::mtbb::parallel_for(mgb::mtbb::blocked_range<SparseMatrix::RowIndex>(0, rowCount),
+ [&](const mgb::mtbb::blocked_range<SparseMatrix::RowIndex>& range)
{for (auto it = range.begin(); it != range.end(); ++it)
{
const auto row = it;
@@ -477,21 +477,21 @@ namespace {
MATHICGB_ASSERT(col < colCount);
bool isNewReducer = false;
{
- mgb::tbb::mutex::scoped_lock lockGuard(lock);
+ mgb::mtbb::mutex::scoped_lock lockGuard(lock);
if (!columnHasPivot[col]) {
columnHasPivot[col] = true;
isNewReducer = true;
- nextReducers.push_back(::std::make_pair(col, row));
+ nextReducers.push_back(std::make_pair(col, row));
}
}
if (isNewReducer)
denseRow.makeUnitary(modulus, col);
}
}});
- //::std::cout << "done reducing that batch" << ::std::endl;
+ //std::cout << "done reducing that batch" << std::endl;
reduced.clear();
- ::std::sort(nextReducers.begin(), nextReducers.end());
+ std::sort(nextReducers.begin(), nextReducers.end());
for (size_t i = 0; i < nextReducers.size(); ++i) {
size_t const row = nextReducers[i].second;
@@ -508,8 +508,8 @@ namespace {
nextReducers.clear();
}
- mgb::tbb::parallel_for(mgb::tbb::blocked_range<size_t>(0, rowCount),
- [&](const mgb::tbb::blocked_range<size_t>& range)
+ mgb::mtbb::parallel_for(mgb::mtbb::blocked_range<size_t>(0, rowCount),
+ [&](const mgb::mtbb::blocked_range<size_t>& range)
{for (auto it = range.begin(); it != range.end(); ++it)
{
const size_t row = it;
@@ -517,7 +517,7 @@ namespace {
}});
#ifdef MATHICGB_DEBUG
- ::std::vector<char> sawPivot(colCount);
+ std::vector<char> sawPivot(colCount);
for (SparseMatrix::RowIndex row = 0; row < rowCount; ++row) {
if (dense[row].empty()) {
MATHICGB_ASSERT(!isPivotRow[row]);
@@ -549,7 +549,7 @@ namespace {
for (size_t row = 0; row < rowCount; ++row)
if (!dense[row].empty())
dense[row].appendTo(reduced);
- return ::std::move(reduced);
+ return std::move(reduced);
}
}
@@ -584,7 +584,7 @@ private:
};
*/
void addRowMultipleInplace(
- ::std::vector< ::std::vector<SparseMatrix::Scalar> >& matrix,
+ std::vector< std::vector<SparseMatrix::Scalar> >& matrix,
const SparseMatrix::RowIndex addRow,
const SparseMatrix::Scalar multiple,
const SparseMatrix::RowIndex row,
@@ -606,7 +606,7 @@ void addRowMultipleInplace(
}
void makeRowUnitary(
- ::std::vector< ::std::vector<SparseMatrix::Scalar>>& matrix,
+ std::vector< std::vector<SparseMatrix::Scalar>>& matrix,
const SparseMatrix::RowIndex row,
const SparseMatrix::ColIndex colCount,
const SparseMatrix::ColIndex leadingCol,
@@ -627,7 +627,7 @@ void makeRowUnitary(
// todo: make this take a parameter startAtCol ::DONE
SparseMatrix::ColIndex leadingColumn(
- const ::std::vector< ::std::vector<SparseMatrix::Scalar>>& matrix,
+ const std::vector< std::vector<SparseMatrix::Scalar>>& matrix,
const SparseMatrix::RowIndex row,
const SparseMatrix::ColIndex colCount,
SparseMatrix::ColIndex startAtCol
@@ -642,7 +642,7 @@ SparseMatrix::ColIndex leadingColumn(
}
void rowReducedEchelonMatrix(
- ::std::vector< ::std::vector<SparseMatrix::Scalar> >& matrix,
+ std::vector< std::vector<SparseMatrix::Scalar> >& matrix,
const SparseMatrix::ColIndex colCount,
const SparseMatrix::Scalar modulus
) {
@@ -651,7 +651,7 @@ void rowReducedEchelonMatrix(
static_cast<SparseMatrix::RowIndex>(matrix.size());
// pivotRowOfCol[i] is the pivot in column i or rowCount
// if we have not identified such a pivot so far.
- ::std::vector<SparseMatrix::RowIndex> pivotRowOfCol(colCount, rowCount);
+ std::vector<SparseMatrix::RowIndex> pivotRowOfCol(colCount, rowCount);
// row reduce to row echelon form
for(SparseMatrix::RowIndex row=0; row<rowCount;++row) {
@@ -696,7 +696,7 @@ SparseMatrix reduceToEchelonFormShrawan(
const auto colCount = toReduce.computeColCount();
// Convert input matrix to dense format
- ::std::vector< ::std::vector<SparseMatrix::Scalar>> matrix(rowCount);
+ std::vector< std::vector<SparseMatrix::Scalar>> matrix(rowCount);
for (SparseMatrix::RowIndex row = 0; row < rowCount; ++row) {
MATHICGB_ASSERT(!toReduce.emptyRow(row));
matrix[row].resize(colCount);
@@ -724,7 +724,7 @@ SparseMatrix reduceToEchelonFormShrawan(
if (!rowIsZero)
reduced.rowDone();
}
- return ::std::move(reduced);
+ return std::move(reduced);
}
SparseMatrix reduceToEchelonFormShrawanDelayedModulus(
@@ -736,7 +736,7 @@ SparseMatrix reduceToEchelonFormShrawanDelayedModulus(
const auto colCount = toReduce.computeColCount();
// Convert input matrix to dense format
- ::std::vector< ::std::vector<SparseMatrix::Scalar>> matrix(rowCount);
+ std::vector< std::vector<SparseMatrix::Scalar>> matrix(rowCount);
for (SparseMatrix::RowIndex row = 0; row < rowCount; ++row) {
MATHICGB_ASSERT(!toReduce.emptyRow(row));
matrix[row].resize(colCount);
@@ -762,7 +762,7 @@ SparseMatrix reduceToEchelonFormShrawanDelayedModulus(
if (!rowIsZero)
reduced.rowDone();
}
- return ::std::move(reduced);
+ return std::move(reduced);
}
SparseMatrix F4MatrixReducer::reduceToBottomRight(const QuadMatrix& matrix) {
@@ -818,9 +818,9 @@ namespace {
// this assert has to be NO_ASSUME as otherwise the branch below will get
// optimized out.
MATHICGB_ASSERT_NO_ASSUME(modulus <=
- ::std::numeric_limits<SparseMatrix::Scalar>::max());
- if (modulus > ::std::numeric_limits<SparseMatrix::Scalar>::max())
- throw ::std::overflow_error("Too large modulus in F4 matrix reduction.");
+ std::numeric_limits<SparseMatrix::Scalar>::max());
+ if (modulus > std::numeric_limits<SparseMatrix::Scalar>::max())
+ throw std::overflow_error("Too large modulus in F4 matrix reduction.");
return static_cast<SparseMatrix::Scalar>(modulus);
}
}
diff --git a/src/mathicgb/F4ProtoMatrix.cpp b/src/mathicgb/F4ProtoMatrix.cpp
index 90d0f65..bc7e091 100755
--- a/src/mathicgb/F4ProtoMatrix.cpp
+++ b/src/mathicgb/F4ProtoMatrix.cpp
@@ -23,12 +23,12 @@ auto F4ProtoMatrix::row(const RowIndex row) const -> Row {
auto F4ProtoMatrix::makeRowWithTheseScalars(const Poly& scalars) -> ColIndex*
{
- MATHICGB_ASSERT(rowCount() < ::std::numeric_limits<RowIndex>::max());
- MATHICGB_ASSERT(scalars.termCount() < ::std::numeric_limits<ColIndex>::max());
+ MATHICGB_ASSERT(rowCount() < std::numeric_limits<RowIndex>::max());
+ MATHICGB_ASSERT(scalars.termCount() < std::numeric_limits<ColIndex>::max());
InternalRow row;
row.indicesBegin = mIndices.size();
- row.scalarsBegin = ::std::numeric_limits<decltype(row.scalarsBegin)>::max();
+ row.scalarsBegin = std::numeric_limits<decltype(row.scalarsBegin)>::max();
row.entryCount = static_cast<ColIndex>(scalars.termCount());
row.externalScalars = scalars.coefficientBegin();
mRows.push_back(row);
@@ -37,8 +37,8 @@ auto F4ProtoMatrix::makeRowWithTheseScalars(const Poly& scalars) -> ColIndex*
return mIndices.data() + row.indicesBegin;
}
-auto F4ProtoMatrix::makeRow(ColIndex entryCount) -> ::std::pair<ColIndex*, Scalar*> {
- MATHICGB_ASSERT(rowCount() < ::std::numeric_limits<RowIndex>::max());
+auto F4ProtoMatrix::makeRow(ColIndex entryCount) -> std::pair<ColIndex*, Scalar*> {
+ MATHICGB_ASSERT(rowCount() < std::numeric_limits<RowIndex>::max());
InternalRow row;
row.indicesBegin = mIndices.size();
@@ -49,7 +49,7 @@ auto F4ProtoMatrix::makeRow(ColIndex entryCount) -> ::std::pair<ColIndex*, Scala
mIndices.resize(mIndices.size() + entryCount);
mScalars.resize(mScalars.size() + entryCount);
- return ::std::make_pair(
+ return std::make_pair(
mIndices.data() + row.indicesBegin,
mScalars.data() + row.scalarsBegin
);
diff --git a/src/mathicgb/F4ProtoMatrix.hpp b/src/mathicgb/F4ProtoMatrix.hpp
index cb5f797..6648050 100755
--- a/src/mathicgb/F4ProtoMatrix.hpp
+++ b/src/mathicgb/F4ProtoMatrix.hpp
@@ -29,7 +29,7 @@ public:
ColIndex* makeRowWithTheseScalars(const Poly& scalars);
- ::std::pair<ColIndex*, Scalar*> makeRow(ColIndex entryCount);
+ std::pair<ColIndex*, Scalar*> makeRow(ColIndex entryCount);
void removeLastEntries(const RowIndex row, const ColIndex count);
@@ -41,9 +41,9 @@ private:
const ExternalScalar* externalScalars;
};
- ::std::vector<ColIndex> mIndices;
- ::std::vector<Scalar> mScalars;
- ::std::vector<InternalRow> mRows;
+ std::vector<ColIndex> mIndices;
+ std::vector<Scalar> mScalars;
+ std::vector<InternalRow> mRows;
};
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/F4Reducer.cpp b/src/mathicgb/F4Reducer.cpp
index 53df836..503b902 100755
--- a/src/mathicgb/F4Reducer.cpp
+++ b/src/mathicgb/F4Reducer.cpp
@@ -59,58 +59,58 @@ unsigned int F4Reducer::preferredSetSize() const {
return 100000;
}
-void F4Reducer::writeMatricesTo(::std::string file, size_t minEntries) {
- mStoreToFile = ::std::move(file);
+void F4Reducer::writeMatricesTo(std::string file, size_t minEntries) {
+ mStoreToFile = std::move(file);
mMinEntryCountForStore = minEntries;
mMatrixSaveCount = 0;
}
-::std::unique_ptr<Poly> F4Reducer::classicReduce
+std::unique_ptr<Poly> F4Reducer::classicReduce
(const Poly& poly, const PolyBasis& basis) {
if (tracingLevel >= 2)
- ::std::cerr <<
+ std::cerr <<
"F4Reducer: Using fall-back reducer for single classic reduction\n";
auto p = mFallback->classicReduce(poly, basis);
mSigStats = mFallback->sigStats();
mClassicStats = mFallback->classicStats();
- return ::std::move(p);
+ return std::move(p);
}
-::std::unique_ptr<Poly> F4Reducer::classicTailReduce
+std::unique_ptr<Poly> F4Reducer::classicTailReduce
(const Poly& poly, const PolyBasis& basis) {
if (tracingLevel >= 2)
- ::std::cerr <<
+ std::cerr <<
"F4Reducer: Using fall-back reducer for single classic tail reduction\n";
auto p = mFallback->classicTailReduce(poly, basis);
mSigStats = mFallback->sigStats();
mClassicStats = mFallback->classicStats();
- return ::std::move(p);
+ return std::move(p);
}
-::std::unique_ptr<Poly> F4Reducer::classicReduceSPoly(
+std::unique_ptr<Poly> F4Reducer::classicReduceSPoly(
const Poly& a,
const Poly& b,
const PolyBasis& basis
) {
if (tracingLevel >= 2)
- ::std::cerr << "F4Reducer: "
+ std::cerr << "F4Reducer: "
"Using fall-back reducer for single classic S-pair reduction\n";
auto p = mFallback->classicReduceSPoly(a, b, basis);
mSigStats = mFallback->sigStats();
mClassicStats = mFallback->classicStats();
- return ::std::move(p);
+ return std::move(p);
}
void F4Reducer::classicReduceSPolySet(
- ::std::vector< ::std::pair<size_t, size_t> >& spairs,
+ std::vector< std::pair<size_t, size_t> >& spairs,
const PolyBasis& basis,
- ::std::vector< ::std::unique_ptr<Poly> >& reducedOut
+ std::vector< std::unique_ptr<Poly> >& reducedOut
) {
if (spairs.size() <= 1 && false) {
if (tracingLevel >= 2)
- ::std::cerr << "F4Reducer: Using fall-back reducer for "
+ std::cerr << "F4Reducer: Using fall-back reducer for "
<< spairs.size() << " S-pairs.\n";
mFallback->classicReduceSPolySet(spairs, basis, reducedOut);
mSigStats = mFallback->sigStats();
@@ -121,10 +121,10 @@ void F4Reducer::classicReduceSPolySet(
MATHICGB_ASSERT(!spairs.empty());
if (tracingLevel >= 2 && false)
- ::std::cerr << "F4Reducer: Reducing " << spairs.size() << " S-polynomials.\n";
+ std::cerr << "F4Reducer: Reducing " << spairs.size() << " S-polynomials.\n";
SparseMatrix reduced;
- ::std::vector<monomial> monomials;
+ std::vector<monomial> monomials;
{
QuadMatrix qm;
{
@@ -151,20 +151,20 @@ void F4Reducer::classicReduceSPolySet(
saveMatrix(qm);
reduced = F4MatrixReducer(basis.ring().charac()).
reducedRowEchelonFormBottomRight(qm);
- monomials = ::std::move(qm.rightColumnMonomials);
+ monomials = std::move(qm.rightColumnMonomials);
const auto end = qm.leftColumnMonomials.end();
for (auto it = qm.leftColumnMonomials.begin(); it != end; ++it)
mRing.freeMonomial(*it);
}
if (tracingLevel >= 2 && false)
- ::std::cerr << "F4Reducer: Extracted " << reduced.rowCount()
+ std::cerr << "F4Reducer: Extracted " << reduced.rowCount()
<< " non-zero rows\n";
for (SparseMatrix::RowIndex row = 0; row < reduced.rowCount(); ++row) {
auto p = make_unique<Poly>(basis.ring());
reduced.rowToPolynomial(row, monomials, *p);
- reducedOut.push_back(::std::move(p));
+ reducedOut.push_back(std::move(p));
}
const auto end = monomials.end();
for (auto it = monomials.begin(); it != end; ++it)
@@ -172,13 +172,13 @@ void F4Reducer::classicReduceSPolySet(
}
void F4Reducer::classicReducePolySet
-(const ::std::vector< ::std::unique_ptr<Poly> >& polys,
+(const std::vector< std::unique_ptr<Poly> >& polys,
const PolyBasis& basis,
- ::std::vector< ::std::unique_ptr<Poly> >& reducedOut)
+ std::vector< std::unique_ptr<Poly> >& reducedOut)
{
if (polys.size() <= 1 && false) {
if (tracingLevel >= 2)
- ::std::cerr << "F4Reducer: Using fall-back reducer for "
+ std::cerr << "F4Reducer: Using fall-back reducer for "
<< polys.size() << " polynomials.\n";
mFallback->classicReducePolySet(polys, basis, reducedOut);
mSigStats = mFallback->sigStats();
@@ -190,10 +190,10 @@ void F4Reducer::classicReducePolySet
MATHICGB_ASSERT(!polys.empty());
if (tracingLevel >= 2 && false)
- ::std::cerr << "F4Reducer: Reducing " << polys.size() << " polynomials.\n";
+ std::cerr << "F4Reducer: Reducing " << polys.size() << " polynomials.\n";
SparseMatrix reduced;
- ::std::vector<monomial> monomials;
+ std::vector<monomial> monomials;
{
QuadMatrix qm;
{
@@ -216,20 +216,20 @@ void F4Reducer::classicReducePolySet
saveMatrix(qm);
reduced = F4MatrixReducer(basis.ring().charac()).
reducedRowEchelonFormBottomRight(qm);
- monomials = ::std::move(qm.rightColumnMonomials);
+ monomials = std::move(qm.rightColumnMonomials);
for (auto it = qm.leftColumnMonomials.begin();
it != qm.leftColumnMonomials.end(); ++it)
mRing.freeMonomial(*it);
}
if (tracingLevel >= 2 && false)
- ::std::cerr << "F4Reducer: Extracted " << reduced.rowCount()
+ std::cerr << "F4Reducer: Extracted " << reduced.rowCount()
<< " non-zero rows\n";
for (SparseMatrix::RowIndex row = 0; row < reduced.rowCount(); ++row) {
auto p = make_unique<Poly>(basis.ring());
reduced.rowToPolynomial(row, monomials, *p);
- reducedOut.push_back(::std::move(p));
+ reducedOut.push_back(std::move(p));
}
const auto end = monomials.end();
for (auto it = monomials.begin(); it != end; ++it)
@@ -243,19 +243,19 @@ Poly* F4Reducer::regularReduce(
const SigPolyBasis& basis
) {
if (tracingLevel >= 2)
- ::std::cerr <<
+ std::cerr <<
"F4Reducer: Using fall-back reducer for single regular reduction\n";
auto p = mFallback->regularReduce(sig, multiple, basisElement, basis);
mSigStats = mFallback->sigStats();
mClassicStats = mFallback->classicStats();
- return ::std::move(p);
+ return std::move(p);
}
void F4Reducer::setMemoryQuantum(size_t quantum) {
mMemoryQuantum = quantum;
}
-::std::string F4Reducer::description() const {
+std::string F4Reducer::description() const {
return "F4 reducer";
}
@@ -270,10 +270,10 @@ void F4Reducer::saveMatrix(const QuadMatrix& matrix) {
if (mMinEntryCountForStore > entryCount)
return;
++mMatrixSaveCount;
- ::std::ostringstream fileName;
+ std::ostringstream fileName;
fileName << mStoreToFile << '-' << mMatrixSaveCount << ".qmat";
if (tracingLevel > 2)
- ::std::cerr << "F4Reducer: Saving matrix to " << fileName.str() << '\n';
+ std::cerr << "F4Reducer: Saving matrix to " << fileName.str() << '\n';
FILE* file = fopen(fileName.str().c_str(), "wb");
// @todo: fix leak of file on exception
matrix.write(static_cast<SparseMatrix::Scalar>(mRing.charac()), file);
diff --git a/src/mathicgb/FixedSizeMonomialMap.h b/src/mathicgb/FixedSizeMonomialMap.h
index 9751e7b..650ae10 100755
--- a/src/mathicgb/FixedSizeMonomialMap.h
+++ b/src/mathicgb/FixedSizeMonomialMap.h
@@ -4,8 +4,8 @@
#define MATHICGB_FIXED_SIZE_MONOMIAL_MAP_GUARD
#include "Atomic.hpp"
-#include "PolyRing.hpp"
#include "mtbb.hpp"
+#include "PolyRing.hpp"
#include <memtailor.h>
#include <limits>
#include <vector>
@@ -27,7 +27,7 @@ template<class T>
class FixedSizeMonomialMap {
public:
typedef T mapped_type;
- typedef ::std::pair<const_monomial, mapped_type> value_type;
+ typedef std::pair<const_monomial, mapped_type> value_type;
/// Iterates through entries in the hash table.
class const_iterator;
@@ -46,7 +46,7 @@ public:
mRing(ring),
mNodeAlloc(sizeofNode(ring))
{
- // Calling new int[x] does not zero the array. ::std::atomic has a trivial
+ // Calling new int[x] does not zero the array. std::atomic has a trivial
// constructor so the same thing is true of new atomic[x]. Calling
// new int[x]() is supposed to zero initialize but this apparently
// does not work on GCC. So we have to fill the table with nulls
@@ -72,7 +72,7 @@ public:
make_unique_array<Atomic<Node*>>(hashMaskToBucketCount(mHashToIndexMask))
),
mRing(map.ring()),
- mNodeAlloc(::std::move(map.mNodeAlloc))
+ mNodeAlloc(std::move(map.mNodeAlloc))
{
// We can store relaxed as the constructor does not run concurrently.
setTableEntriesToNullRelaxed();
@@ -82,7 +82,7 @@ public:
const size_t index = hashToIndex(mRing.monomialHashValue(node->mono));
Node* const next = node->next.load();
node->next.store(mBuckets[index].load());
- mBuckets[index].store(node, ::std::memory_order_relaxed);
+ mBuckets[index].store(node, std::memory_order_relaxed);
node = next;
}
}
@@ -113,44 +113,44 @@ public:
/// Returns the value associated to mono or null if there is no such value.
/// Also returns an internal monomial that equals mono of such a monomial
/// exists.
- ::std::pair<const mapped_type*, ConstMonomial>
+ std::pair<const mapped_type*, ConstMonomial>
find(const const_monomial mono) const {
const HashValue monoHash = mRing.monomialHashValue(mono);
const Node* node = bucketAtIndex(hashToIndex(monoHash));
- for (; node != 0; node = node->next.load(::std::memory_order_consume)) {
+ for (; node != 0; node = node->next.load(std::memory_order_consume)) {
// To my surprise, it seems to be faster to comment out this branch.
// I guess the hash table has too few collisions to make it worth it.
//if (monoHash != mRing.monomialHashValue(node->mono))
// continue;
if (mRing.monomialEqualHintTrue(mono, node->mono))
- return ::std::make_pair(&node->value, node->mono);
+ return std::make_pair(&node->value, node->mono);
}
- return ::std::make_pair(static_cast<const mapped_type*>(0), ConstMonomial(0));
+ return std::make_pair(static_cast<const mapped_type*>(0), ConstMonomial(0));
}
// As find on the product a*b but also returns the monomial that is the
// product.
MATHICGB_INLINE
- ::std::pair<const mapped_type*, ConstMonomial> findProduct(
+ std::pair<const mapped_type*, ConstMonomial> findProduct(
const const_monomial a,
const const_monomial b
) const {
const HashValue abHash = mRing.monomialHashOfProduct(a, b);
const Node* node = bucketAtIndex(hashToIndex(abHash));
- for (; node != 0; node = node->next.load(::std::memory_order_consume)) {
+ for (; node != 0; node = node->next.load(std::memory_order_consume)) {
// To my surprise, it seems to be faster to comment out this branch.
// I guess the hash table has too few collisions to make it worth it.
//if (abHash != mRing.monomialHashValue(node->mono))
// continue;
if (mRing.monomialIsProductOfHintTrue(a, b, node->mono))
- return ::std::make_pair(&node->value, node->mono);
+ return std::make_pair(&node->value, node->mono);
}
- return ::std::make_pair(static_cast<const mapped_type*>(0), ConstMonomial(0));
+ return std::make_pair(static_cast<const mapped_type*>(0), ConstMonomial(0));
}
/// As findProduct but looks for a1*b and a2*b at one time.
MATHICGB_INLINE
- ::std::pair<const mapped_type*, const mapped_type*> findTwoProducts(
+ std::pair<const mapped_type*, const mapped_type*> findTwoProducts(
const const_monomial a1,
const const_monomial a2,
const const_monomial b
@@ -163,9 +163,9 @@ public:
if (node1 != 0 && node2 != 0 && mRing.monomialIsTwoProductsOfHintTrue
(a1, a2, b, node1->mono, node2->mono)
)
- return ::std::make_pair(&node1->value, &node2->value);
+ return std::make_pair(&node1->value, &node2->value);
else
- return ::std::make_pair(findProduct(a1, b).first, findProduct(a2, b).first);
+ return std::make_pair(findProduct(a1, b).first, findProduct(a2, b).first);
}
/// Makes value.first map to value.second unless value.first is already
@@ -176,9 +176,9 @@ public:
/// inserted value equals the already present value.
///
/// p.first.second is a internal monomial that equals value.first.
- ::std::pair< ::std::pair<const mapped_type*, ConstMonomial>, bool>
+ std::pair< std::pair<const mapped_type*, ConstMonomial>, bool>
insert(const value_type& value) {
- const mgb::tbb::mutex::scoped_lock lockGuard(mInsertionMutex);
+ const mgb::mtbb::mutex::scoped_lock lockGuard(mInsertionMutex);
// find() loads buckets with memory_order_consume, so it may seem like
// we need some extra synchronization to make sure that we have the
// most up to date view of the bucket that value.first goes in -
@@ -190,7 +190,7 @@ public:
{
const auto found = find(value.first);
if (found.first != 0)
- return ::std::make_pair(found, false); // key already present
+ return std::make_pair(found, false); // key already present
}
const auto node = static_cast<Node*>(mNodeAlloc.alloc());
@@ -205,8 +205,8 @@ public:
// we cannot store with memory_order_relaxed here because unlocking the
// lock only synchronizes with threads who later grab the lock - it does
// not synchronize with reading threads since they do not grab the lock.
- mBuckets[index].store(node, ::std::memory_order_release);
- return ::std::make_pair(::std::make_pair(&node->value, node->mono), true); // successful insertion
+ mBuckets[index].store(node, std::memory_order_release);
+ return std::make_pair(std::make_pair(&node->value, node->mono), true); // successful insertion
}
/// This operation removes all entries from the table. This operation
@@ -235,7 +235,7 @@ private:
void setTableEntriesToNullRelaxed() {
const auto tableEnd = mBuckets.get() + bucketCount();
for (auto tableIt = mBuckets.get(); tableIt != tableEnd; ++tableIt)
- tableIt->store(0, ::std::memory_order_relaxed);
+ tableIt->store(0, std::memory_order_relaxed);
}
struct Node {
@@ -257,7 +257,7 @@ private:
// possible number of buckets based on the range of the hash
// value type. Only unsigned overflow is defined, so we need
// to assert that the hash type is unsigned.
- static_assert(!::std::numeric_limits<HashValue>::is_signed, "");
+ static_assert(!std::numeric_limits<HashValue>::is_signed, "");
const auto hashToIndexMask = static_cast<HashValue>(pow2 - 1);
MATHICGB_ASSERT(pow2 == hashMaskToBucketCount(hashToIndexMask));
return hashToIndexMask;
@@ -281,25 +281,25 @@ private:
Node* bucketAtIndex(size_t index) {
MATHICGB_ASSERT(index < bucketCount());
- return mBuckets[index].load(::std::memory_order_consume);
+ return mBuckets[index].load(std::memory_order_consume);
}
const Node* bucketAtIndex(size_t index) const {
MATHICGB_ASSERT(index < bucketCount());
- return mBuckets[index].load(::std::memory_order_consume);
+ return mBuckets[index].load(std::memory_order_consume);
}
const HashValue mHashToIndexMask;
- ::std::unique_ptr<Atomic<Node*>[]> const mBuckets;
+ std::unique_ptr<Atomic<Node*>[]> const mBuckets;
const PolyRing& mRing;
memt::BufferPool mNodeAlloc; // nodes are allocated from here.
- mgb::tbb::mutex mInsertionMutex;
+ mgb::mtbb::mutex mInsertionMutex;
public:
class const_iterator {
public:
- typedef ::std::forward_iterator_tag iterator_category;
- typedef ::std::pair<mapped_type, ConstMonomial> value_type;
+ typedef std::forward_iterator_tag iterator_category;
+ typedef std::pair<mapped_type, ConstMonomial> value_type;
typedef ptrdiff_t difference_type;
typedef size_t distance_type;
typedef value_type* pointer;
@@ -310,7 +310,7 @@ public:
const_iterator& operator++() {
MATHICGB_ASSERT(mNode != 0);
MATHICGB_ASSERT(mBucket != mBucketsEnd);
- const Node* const node = mNode->next.load(::std::memory_order_consume);
+ const Node* const node = mNode->next.load(std::memory_order_consume);
if (node != 0)
mNode = node;
else
@@ -329,7 +329,7 @@ public:
const value_type operator*() const {
MATHICGB_ASSERT(mNode != 0);
- return ::std::make_pair(mNode->value, mNode->mono);
+ return std::make_pair(mNode->value, mNode->mono);
}
private:
@@ -345,7 +345,7 @@ public:
mNode = 0;
return;
}
- const Node* const node = bucketBegin->load(::std::memory_order_consume);
+ const Node* const node = bucketBegin->load(std::memory_order_consume);
if (node != 0)
mNode = node;
else
@@ -360,7 +360,7 @@ public:
mNode = 0;
break;
}
- const Node* const node = mBucket->load(::std::memory_order_consume);
+ const Node* const node = mBucket->load(std::memory_order_consume);
if (node != 0) {
mNode = node;
break;
diff --git a/src/mathicgb/LogDomain.cpp b/src/mathicgb/LogDomain.cpp
index 006a073..8b32c2c 100755
--- a/src/mathicgb/LogDomain.cpp
+++ b/src/mathicgb/LogDomain.cpp
@@ -9,7 +9,7 @@
MATHICGB_NAMESPACE_BEGIN
-static const auto logDomainGlobalStartTime = mgb::tbb::tick_count::now();
+static const auto logDomainGlobalStartTime = mgb::mtbb::tick_count::now();
LogDomain<true>::LogDomain(
const char* const name,
@@ -96,7 +96,7 @@ void LogDomain<true>::Timer::stop() {
if (!mLogger.enabled())
return;
TimeInterval interval;
- interval.realSeconds = (mgb::tbb::tick_count::now() - mRealTicks).seconds();
+ interval.realSeconds = (mgb::mtbb::tick_count::now() - mRealTicks).seconds();
mLogger.recordTime(interval);
return;
}
@@ -105,7 +105,7 @@ void LogDomain<true>::Timer::start() {
if (!mLogger.enabled() || mTimerRunning)
return;
mTimerRunning = true;
- mRealTicks = mgb::tbb::tick_count::now();
+ mRealTicks = mgb::mtbb::tick_count::now();
}
LogDomainInternal::LogAliasRegisterer::LogAliasRegisterer(const char* alias, const char* of) {
diff --git a/src/mathicgb/LogDomain.hpp b/src/mathicgb/LogDomain.hpp
index 8fd741d..a4fb46b 100755
--- a/src/mathicgb/LogDomain.hpp
+++ b/src/mathicgb/LogDomain.hpp
@@ -50,7 +50,7 @@ public:
void setEnabled(const bool enabled) {mEnabled = enabled;}
void setStreamEnabled(const bool enabled) {mStreamEnabled = enabled;}
- ::std::ostream& stream();
+ std::ostream& stream();
/// Class for recording time that is logged. Movable.
class Timer;
@@ -90,7 +90,7 @@ private:
// for all threads, so that didn't work.
double realSeconds;
- void print(::std::ostream& out) const;
+ void print(std::ostream& out) const;
};
void recordTime(TimeInterval interval);
@@ -135,7 +135,7 @@ public:
private:
LogDomain<true>& mLogger;
bool mTimerRunning;
- mgb::tbb::tick_count mRealTicks; // high precision
+ mtbb::tick_count mRealTicks; // high precision
};
/// This is a compile-time disabled logger. You are not supposed to dynamically
@@ -164,9 +164,9 @@ public:
return Timer(*this);
}
- ::std::ostream& stream() {
+ std::ostream& stream() {
MATHICGB_ASSERT(false);
- return *static_cast< ::std::ostream*>(0);
+ return *static_cast< std::ostream*>(0);
}
typedef unsigned long long Counter;
@@ -272,7 +272,7 @@ MATHICGB_NAMESPACE_END
///
/// Example:
/// if (MATHICGB_LOGGER_TYPE(MyDomain)::compileTimeEnabled)
-/// ::std::ostream << "MyDomain is compiled time enabled";
+/// std::ostream << "MyDomain is compiled time enabled";
#define MATHICGB_LOGGER_TYPE(DOMAIN) ::mgb::logs::Type##DOMAIN
/// Runs the code in the following scope delimited by braces {} if the
@@ -283,14 +283,14 @@ MATHICGB_NAMESPACE_END
///
/// Example:
/// MATHICGB_IF_STREAM_LOG(MyDomain) {
-/// ::std::string msg;
+/// std::string msg;
/// expensiveFunction(msg);
/// stream << msg; // or log.stream() << msg;
/// }
#define MATHICGB_IF_STREAM_LOG(DOMAIN) \
if (MATHICGB_LOGGER(DOMAIN).streamEnabled()) \
LogDomainInternal::lambdaRunner(MATHICGB_LOGGER(DOMAIN)) + \
- [&](MATHICGB_LOGGER_TYPE(DOMAIN)& log, ::std::ostream& stream)
+ [&](MATHICGB_LOGGER_TYPE(DOMAIN)& log, std::ostream& stream)
/// Display information to the log using <<.
/// If domain is not enabled and stream enabled then the log message is not
diff --git a/src/mathicgb/LogDomainSet.cpp b/src/mathicgb/LogDomainSet.cpp
index 995a789..981e3ed 100755
--- a/src/mathicgb/LogDomainSet.cpp
+++ b/src/mathicgb/LogDomainSet.cpp
@@ -8,7 +8,7 @@
MATHICGB_NAMESPACE_BEGIN
LogDomainSet::LogDomainSet():
- mStartTime(mgb::tbb::tick_count::now()) {
+ mStartTime(mgb::mtbb::tick_count::now()) {
}
void LogDomainSet::registerLogDomain(LogDomain<true>& domain) {
@@ -148,7 +148,7 @@ void LogDomainSet::printCountReport(std::ostream& out) const {
}
void LogDomainSet::printTimeReport(std::ostream& out) const {
- const auto allTime = (mgb::tbb::tick_count::now() - mStartTime).seconds();
+ const auto allTime = (mgb::mtbb::tick_count::now() - mStartTime).seconds();
mathic::ColumnPrinter pr;
auto& names = pr.addColumn(true);
@@ -200,7 +200,7 @@ void LogDomainSet::printTimeReport(std::ostream& out) const {
}
void LogDomainSet::reset() {
- mStartTime = mgb::tbb::tick_count::now();
+ mStartTime = mgb::mtbb::tick_count::now();
const auto end = logDomains().cend();
for (auto it = logDomains().cbegin(); it != end; ++it) {
MATHICGB_ASSERT(*it != 0);
diff --git a/src/mathicgb/LogDomainSet.hpp b/src/mathicgb/LogDomainSet.hpp
index cfa5ccd..8bde70b 100755
--- a/src/mathicgb/LogDomainSet.hpp
+++ b/src/mathicgb/LogDomainSet.hpp
@@ -88,7 +88,7 @@ private:
std::vector<LogDomain<true>*> mLogDomains;
std::vector<std::pair<const char*, const char*>> mAliases;
- mgb::tbb::tick_count mStartTime;
+ mgb::mtbb::tick_count mStartTime;
};
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index 151604e..c6c6e5e 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -40,8 +40,8 @@ namespace MonoMonoidInternal {
typedef size_t VarIndex;
typedef E Exponent;
- typedef typename ::std::make_unsigned<E>::type Component;
- typedef typename ::std::make_unsigned<E>::type HashValue;
+ typedef typename std::make_unsigned<E>::type Component;
+ typedef typename std::make_unsigned<E>::type HashValue;
typedef const Exponent* const_iterator;
typedef MonoOrder<Exponent> Order;
@@ -50,7 +50,7 @@ namespace MonoMonoidInternal {
mGradingCount(order.gradingCount()),
mOrderIndexBegin(HasComponent + order.varCount()),
mOrderIndexEnd(mOrderIndexBegin + StoreOrder * order.gradingCount()),
- mEntryCount(::std::max<VarIndex>(mOrderIndexEnd + StoreHash, 1)),
+ mEntryCount(std::max<VarIndex>(mOrderIndexEnd + StoreHash, 1)),
mHashCoefficients(makeHashCoefficients(order.varCount())),
mOrderIsTotalDegreeRevLex
(order.baseOrder() == Order::RevLexBaseOrder && order.isTotalDegree()),
@@ -73,8 +73,8 @@ namespace MonoMonoidInternal {
VarIndex componentGradingIndex() const {return mComponentGradingIndex;}
protected:
- typedef ::std::vector<Exponent> HashCoefficients;
- typedef ::std::vector<Exponent> Gradings;
+ typedef std::vector<Exponent> HashCoefficients;
+ typedef std::vector<Exponent> Gradings;
static Gradings makeGradings(const Order& order) {
auto gradings = order.gradings();
@@ -98,7 +98,7 @@ namespace MonoMonoidInternal {
const auto index = gradingsIndex(grading, var, varCount);
const auto oppositeIndex = gradingsOppositeRowIndex
(grading, gradingCount, var, varCount);
- ::std::swap(gradings[index], gradings[oppositeIndex]);
+ std::swap(gradings[index], gradings[oppositeIndex]);
}
}
}
@@ -171,10 +171,10 @@ namespace MonoMonoidInternal {
private:
HashCoefficients static makeHashCoefficients(const VarIndex varCount) {
- ::std::srand(0); // To use the same hash coefficients every time.
+ std::srand(0); // To use the same hash coefficients every time.
HashCoefficients coeffs(varCount);
for (VarIndex var = 0; var < varCount; ++var)
- coeffs[var] = static_cast<HashValue>(::std::rand());
+ coeffs[var] = static_cast<HashValue>(std::rand());
return coeffs;
}
@@ -204,7 +204,7 @@ namespace MonoMonoidInternal {
/// mOrderIsTotalDegreeRevLex is true then mGradings is empty but
/// implicitly it is a single grading consisting of all 1s and the
/// base order is revlex.
- ::std::vector<Exponent> mGradings;
+ std::vector<Exponent> mGradings;
};
}
@@ -214,7 +214,7 @@ private:
typedef MonoMonoidInternal::Base<E, HC, SH, SO> Base;
public:
- static_assert(::std::numeric_limits<E>::is_signed, "");
+ static_assert(std::numeric_limits<E>::is_signed, "");
// *** Types
@@ -282,7 +282,7 @@ public:
class MonoPool;
/// A vector of monomials. The interface is a subset of
- /// ::std::vector. Monomials can be appended (push_back). Only the
+ /// std::vector. Monomials can be appended (push_back). Only the
/// last monomial can be mutated and monomials cannot be reordered
/// or removed. These restrictions should make it easier to support
/// variable-sized monomials in future. Change it if you need to
@@ -310,7 +310,7 @@ public:
// *** Constructors and accessors
- MonoMonoid(MonoMonoid&& monoid): Base(::std::move(monoid)), mPool(*this) {
+ MonoMonoid(MonoMonoid&& monoid): Base(std::move(monoid)), mPool(*this) {
MATHICGB_ASSERT(debugAssertValid());
}
@@ -333,9 +333,9 @@ public:
/// indicates whether to do a Schreyer order. TODO: clearly this is
/// a mess that needs to be cleaned up. Step 1 is to move IO out of
/// MonoMonoid entirely.
- static ::std::pair<MonoMonoid, ::std::pair<bool, bool>> readMonoid(::std::istream& in);
+ static std::pair<MonoMonoid, std::pair<bool, bool>> readMonoid(std::istream& in);
void printMonoid
- (const bool componentsAscendingDesired, ::std::ostream& out) const;
+ (const bool componentsAscendingDesired, std::ostream& out) const;
/// Returns an Order object that is equivalent to the order that
/// this monoid was constructed with. The settings not handled by
@@ -346,13 +346,13 @@ public:
const bool componentsAscendingDesired,
const bool schreyering
) const {
- ::std::vector<Exponent> orderGradings(gradings());
+ std::vector<Exponent> orderGradings(gradings());
reverseGradings(varCount(), orderGradings);
if (!isLexBaseOrder())
negateGradings(orderGradings);
return Order(
varCount(),
- ::std::move(orderGradings),
+ std::move(orderGradings),
isLexBaseOrder() ? Order::LexBaseOrder : Order::RevLexBaseOrder,
Base::reverseComponentGradingIndex
(gradingCount(), componentGradingIndex()),
@@ -494,13 +494,13 @@ public:
MATHICGB_ASSERT(i == varCount() / 2 || access(a, i*2+1) >= 0);
uint64 A, B, AB;
- // We have to use ::std::memcpy here because just casting to a int64 breaks
+ // We have to use std::memcpy here because just casting to a int64 breaks
// the strict aliasing rule which implies undefined behavior. Both MSVC and
// gcc don't actually call memcpy here. MSVC is a tiny bit slower for this
// code than for casting while GCC seems to be exactly the same speed.
- ::std::memcpy(&A, ptr(a, i*2), 8);
- ::std::memcpy(&B, ptr(b, i*2), 8);
- ::std::memcpy(&AB, ptr(ab, i*2), 8);
+ std::memcpy(&A, ptr(a, i*2), 8);
+ std::memcpy(&B, ptr(b, i*2), 8);
+ std::memcpy(&AB, ptr(ab, i*2), 8);
orOfXor |= AB ^ (A + B);
}
MATHICGB_ASSERT((orOfXor == 0) == isProductOf(a, b, ab));
@@ -520,11 +520,11 @@ public:
uint64 orOfXor = 0;
for (VarIndex i = varCount() / 2; i != beforeEntriesIndexBegin(); --i) {
uint64 A1, A2, B, A1B, A2B;
- ::std::memcpy(&A1, ptr(a1, i*2), 8);
- ::std::memcpy(&A2, ptr(a2, i*2), 8);
- ::std::memcpy(&B, ptr(b, i*2), 8);
- ::std::memcpy(&A1B, ptr(a1b, i*2), 8);
- ::std::memcpy(&A2B, ptr(a2b, i*2), 8);
+ std::memcpy(&A1, ptr(a1, i*2), 8);
+ std::memcpy(&A2, ptr(a2, i*2), 8);
+ std::memcpy(&B, ptr(b, i*2), 8);
+ std::memcpy(&A1B, ptr(a1b, i*2), 8);
+ std::memcpy(&A2B, ptr(a2b, i*2), 8);
orOfXor |= (A1B ^ (A1 + B)) | (A2B ^ (A2 + B));
}
MATHICGB_ASSERT
@@ -544,7 +544,7 @@ public:
/// words, returns true if mono is the identity for multiplication
/// of monomials.
bool isIdentity(ConstMonoRef mono) const {
- return ::std::all_of(begin(mono), end(mono), [](Exponent e) {return e == 0;});
+ return std::all_of(begin(mono), end(mono), [](Exponent e) {return e == 0;});
}
/// Returns true if a divides b. Equal monomials divide each other.
@@ -622,7 +622,7 @@ public:
MATHICGB_ASSERT(debugValid(lcmAB));
for (auto i = exponentsIndexBegin(); i != exponentsIndexEnd(); ++i)
- if (access(lcmAB, i) != ::std::max(access(a, i), access(b, i)))
+ if (access(lcmAB, i) != std::max(access(a, i), access(b, i)))
return false;
return true;
}
@@ -652,7 +652,7 @@ public:
for (VarIndex var = 0; var < varCount(); ++var) {
if (
ptr(lcmAB, exponentsIndexBegin())[var] !=
- ::std::max(monoidA.exponent(a, var), monoidB.exponent(b, var))
+ std::max(monoidA.exponent(a, var), monoidB.exponent(b, var))
)
return false;
}
@@ -745,10 +745,10 @@ public:
// guaranteed that multiplying a and b together will not overflow
// the integers in the representation.
bool hasAmpleCapacity(ConstMonoRef mono) const {
- const auto halfMin = ::std::numeric_limits<Exponent>::min() / 2;
- const auto halfMax = ::std::numeric_limits<Exponent>::max() / 2;
+ const auto halfMin = std::numeric_limits<Exponent>::min() / 2;
+ const auto halfMax = std::numeric_limits<Exponent>::max() / 2;
MATHICGB_ASSERT(halfMin <= 0);
- const auto limit = ::std::min(-halfMin, halfMax);
+ const auto limit = std::min(-halfMin, halfMax);
const auto inRange = [&](Exponent value)
{return -limit <= value && value <= limit;};
@@ -791,7 +791,7 @@ public:
void copy(ConstMonoRef from, MonoRef to) const {
MATHICGB_ASSERT(debugValid(from));
- ::std::copy_n(rawPtr(from), entryCount(), rawPtr(to));
+ std::copy_n(rawPtr(from), entryCount(), rawPtr(to));
MATHICGB_ASSERT(debugValid(to));
}
@@ -807,7 +807,7 @@ public:
MATHICGB_ASSERT(monoidFrom.debugValid(from));
MATHICGB_ASSERT(monoidFrom.varCount() == varCount());
MATHICGB_ASSERT
- ((::std::is_same<Exponent, typename MonoidFrom::Exponent>::value));
+ ((std::is_same<Exponent, typename MonoidFrom::Exponent>::value));
if (HasComponent)
access(to, componentIndex()) = monoidFrom.component(from);
@@ -851,7 +851,7 @@ public:
if (HasComponent)
access(mono, componentIndex()) = 0;
- ::std::copy_n(exponents, varCount(), ptr(mono, exponentsIndexBegin()));
+ std::copy_n(exponents, varCount(), ptr(mono, exponentsIndexBegin()));
setOrderData(mono);
setHash(mono);
@@ -860,7 +860,7 @@ public:
/// Sets mono to 1, which is the identity for multiplication.
void setIdentity(MonoRef mono) const {
- ::std::fill_n(rawPtr(mono), entryCount(), static_cast<Exponent>(0));
+ std::fill_n(rawPtr(mono), entryCount(), static_cast<Exponent>(0));
MATHICGB_ASSERT(debugValid(mono));
MATHICGB_ASSERT(isIdentity(mono));
@@ -996,7 +996,7 @@ public:
for (auto i = exponentsIndexBegin(); i != exponentsIndexEnd(); ++i) {
const auto ae = access(a, i);
const auto be = access(b, i);
- const auto max = ::std::max(ae, be);
+ const auto max = std::max(ae, be);
access(aColonB, i) = max - be;
access(bColonA, i) = max - ae;
}
@@ -1016,7 +1016,7 @@ public:
access(lcmAB, componentIndex()) = access(a, componentIndex());
}
for (auto i = exponentsIndexBegin(); i != exponentsIndexEnd(); ++i)
- access(lcmAB, i) = ::std::max(access(a, i), access(b, i));
+ access(lcmAB, i) = std::max(access(a, i), access(b, i));
setOrderData(lcmAB);
setHash(lcmAB);
@@ -1041,7 +1041,7 @@ public:
for (VarIndex var = 0; var < varCount(); ++var) {
ptr(lcmAB, exponentsIndexBegin())[var] =
- ::std::max(monoidA.exponent(a, var), monoidB.exponent(b, var));
+ std::max(monoidA.exponent(a, var), monoidB.exponent(b, var));
}
setOrderData(lcmAB);
@@ -1052,7 +1052,7 @@ public:
}
Mono alloc() const {return mPool.alloc();}
- void free(Mono&& mono) const {mPool.free(::std::move(mono));}
+ void free(Mono&& mono) const {mPool.free(std::move(mono));}
void freeRaw(MonoRef mono) const {mPool.freeRaw(mono);}
bool fromPool(ConstMonoRef mono) const {mPool.fromPool(mono);}
@@ -1064,14 +1064,14 @@ public:
/// will be parsed as two separate monomials. A suffix like <2> puts
/// the monomial in component 2, so a5<2> is a^5e_2. The default
/// component is 0.
- void parseM2(::std::istream& in, MonoRef mono) const;
+ void parseM2(std::istream& in, MonoRef mono) const;
// Inverse of parseM2().
- void printM2(ConstMonoRef mono, ::std::ostream& out) const;
+ void printM2(ConstMonoRef mono, std::ostream& out) const;
// As printM2, but returns a string.
- ::std::string toString(ConstMonoRef mono) const {
- ::std::ostringstream out;
+ std::string toString(ConstMonoRef mono) const {
+ std::ostringstream out;
printM2(mono, out);
return out.str();
}
@@ -1174,7 +1174,7 @@ public:
}
bool isNull() const {return mMono.isNull();}
- void toNull() {mPool->free(::std::move(*this));}
+ void toNull() {mPool->free(std::move(*this));}
MonoPtr ptr() const {return mMono;}
@@ -1241,7 +1241,7 @@ public:
MonoPool(MonoPool&& pool):
mMonoid(pool.mMonoid),
- mPool(::std::move(pool.mPool))
+ mPool(std::move(pool.mPool))
{}
Mono alloc() {
@@ -1273,7 +1273,7 @@ public:
class MonoVector {
private:
- typedef ::std::vector<Exponent> RawVector;
+ typedef std::vector<Exponent> RawVector;
public:
/// Class for iterating through the monomials in a MonoVector.
@@ -1290,7 +1290,7 @@ public:
/// access.
class const_iterator {
public:
- typedef ::std::forward_iterator_tag iterator_category;
+ typedef std::forward_iterator_tag iterator_category;
typedef ConstMonoPtr value_type;
const_iterator(): mIt(), mEntriesPerMono(0) {}
@@ -1328,7 +1328,7 @@ public:
MonoVector(const MonoMonoid& monoid): mMonoid(monoid) {}
MonoVector(const MonoVector& v): mMonos(v.mMonos), mMonoid(v.monoid()) {}
MonoVector(MonoVector&& v):
- mMonos(::std::move(v.mMonos)), mMonoid(v.monoid()) {}
+ mMonos(std::move(v.mMonos)), mMonoid(v.monoid()) {}
MonoVector& operator=(const MonoVector& v) {
MATHICGB_ASSERT(monoid() == v.monoid());
@@ -1338,7 +1338,7 @@ public:
MonoVector& operator=(MonoVector&& v) {
MATHICGB_ASSERT(monoid() == v.monoid());
- mMonos = ::std::move(v.mMonos);
+ mMonos = std::move(v.mMonos);
return *this;
}
@@ -1432,7 +1432,7 @@ public:
/// As parseM2 on monoid, but accepts a non-empty space-separated
/// list of monomials. The monomials are appended to the end of
/// the vector.
- void parseM2(::std::istream& in) {
+ void parseM2(std::istream& in) {
while(true) {
push_back();
monoid().parseM2(in, back());
@@ -1443,7 +1443,7 @@ public:
}
/// The inverse of parseM2.
- void printM2(::std::ostream& out) const {
+ void printM2(std::ostream& out) const {
for (auto it = begin(); it != end(); ++it) {
if (it != begin())
out << ' ';
@@ -1533,9 +1533,9 @@ private:
MATHICGB_ASSERT(monoidA.varCount() == varCount());
MATHICGB_ASSERT(monoidB.varCount() == varCount());
MATHICGB_ASSERT
- ((::std::is_same<Exponent, typename MonoidA::Exponent>::value));
+ ((std::is_same<Exponent, typename MonoidA::Exponent>::value));
MATHICGB_ASSERT
- ((::std::is_same<Exponent, typename MonoidB::Exponent>::value));
+ ((std::is_same<Exponent, typename MonoidB::Exponent>::value));
MATHICGB_ASSERT
(HasComponent == (MonoidA::HasComponent || MonoidB::HasComponent));
MATHICGB_ASSERT(monoidA.debugValid(a));
@@ -1770,8 +1770,8 @@ namespace MonoMonoidHelper {
}
template<class E, bool HC, bool SH, bool SO>
-auto MonoMonoid<E, HC, SH, SO>::readMonoid(::std::istream& in) ->
- ::std::pair<MonoMonoid, ::std::pair<bool, bool>>
+auto MonoMonoid<E, HC, SH, SO>::readMonoid(std::istream& in) ->
+ std::pair<MonoMonoid, std::pair<bool, bool>>
{
using MonoMonoidHelper::unchar;
VarIndex varCount;
@@ -1779,12 +1779,12 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(::std::istream& in) ->
bool doSchreyer = false;
bool lexBaseOrder = false;
- ::std::string str;
+ std::string str;
char c;
in >> c;
in.unget();
- if (!::std::isdigit(c)) {
- ::std::string str;
+ if (!std::isdigit(c)) {
+ std::string str;
in >> str;
if (str == "schreyer") {
doSchreyer = true;
@@ -1810,8 +1810,8 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(::std::istream& in) ->
char c;
in >> c;
in.unget();
- if (!::std::isdigit(c)) {
- ::std::string str;
+ if (!std::isdigit(c)) {
+ std::string str;
in >> str;
if (str == "component")
@@ -1852,7 +1852,7 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(::std::istream& in) ->
in >> c;
in.unget();
- if (!::std::isdigit(c)) {
+ if (!std::isdigit(c)) {
in >> str;
if (str == "component")
componentsAscendingDesired = true;
@@ -1866,20 +1866,20 @@ auto MonoMonoid<E, HC, SH, SO>::readMonoid(::std::istream& in) ->
Order order(
varCount,
- ::std::move(gradings),
+ std::move(gradings),
lexBaseOrder ? Order::LexBaseOrder : Order::RevLexBaseOrder,
componentCompareIndex
);
- return ::std::make_pair(
+ return std::make_pair(
MonoMonoid(order),
- ::std::make_pair(componentsAscendingDesired, doSchreyer)
+ std::make_pair(componentsAscendingDesired, doSchreyer)
);
}
template<class E, bool HC, bool SH, bool SO>
void MonoMonoid<E, HC, SH, SO>::printMonoid(
const bool componentsAscendingDesired,
- ::std::ostream& out
+ std::ostream& out
) const {
using MonoMonoidHelper::unchar;
typedef typename unchar<Exponent>::type UncharredExponent;
@@ -1908,7 +1908,7 @@ void MonoMonoid<E, HC, SH, SO>::printMonoid(
}
template<class E, bool HC, bool SH, bool SO>
-void MonoMonoid<E, HC, SH, SO>::parseM2(::std::istream& in, MonoRef mono) const {
+void MonoMonoid<E, HC, SH, SO>::parseM2(std::istream& in, MonoRef mono) const {
using MonoMonoidHelper::unchar;
// todo: signal error on exponent overflow
@@ -1980,7 +1980,7 @@ void MonoMonoid<E, HC, SH, SO>::parseM2(::std::istream& in, MonoRef mono) const
template<class E, bool HC, bool SH, bool SO>
void MonoMonoid<E, HC, SH, SO>::printM2(
ConstMonoRef mono,
- ::std::ostream& out
+ std::ostream& out
) const {
using MonoMonoidHelper::unchar;
const auto letterCount = 'z' - 'a' + 1;
diff --git a/src/mathicgb/MonoOrder.hpp b/src/mathicgb/MonoOrder.hpp
index a1029c9..6877a2a 100755
--- a/src/mathicgb/MonoOrder.hpp
+++ b/src/mathicgb/MonoOrder.hpp
@@ -23,7 +23,7 @@ class MonoOrder {
public:
typedef W Weight;
typedef size_t VarIndex;
- typedef ::std::vector<Weight> Gradings;
+ typedef std::vector<Weight> Gradings;
static const size_t ComponentAfterBaseOrder = static_cast<size_t>(-1);
@@ -94,7 +94,7 @@ public:
const bool schreyering = true
):
mVarCount(varCount),
- mGradings(::std::move(gradings)),
+ mGradings(std::move(gradings)),
mBaseOrder(baseOrder),
mComponentGradingIndex(componentBefore),
mComponentsAscendingDesired(componentsAscendingDesired),
@@ -174,13 +174,13 @@ private:
const VarIndex componentBefore
) {
if (componentBefore == ComponentAfterBaseOrder)
- return ::std::move(gradings);
+ return std::move(gradings);
MATHICGB_ASSERT(componentBefore <= varCount);
gradings.resize(gradings.size() + varCount);
const auto newRow = gradings.begin() + varCount * componentBefore;
- ::std::copy_n(newRow, varCount, newRow + varCount);
- ::std::fill_n(newRow, varCount, static_cast<Weight>(0));
- return ::std::move(gradings);
+ std::copy_n(newRow, varCount, newRow + varCount);
+ std::fill_n(newRow, varCount, static_cast<Weight>(0));
+ return std::move(gradings);
}
bool debugAssertValid() {
diff --git a/src/mathicgb/MonomialMap.hpp b/src/mathicgb/MonomialMap.hpp
index 7787cd4..5cd4af2 100755
--- a/src/mathicgb/MonomialMap.hpp
+++ b/src/mathicgb/MonomialMap.hpp
@@ -4,9 +4,9 @@
#define MATHICGB_MONOMIAL_MAP_GUARD
#include "FixedSizeMonomialMap.h"
+#include "mtbb.hpp"
#include "Atomic.hpp"
#include "PolyRing.hpp"
-#include "mtbb.hpp"
#include <memtailor.h>
#include <limits>
#include <vector>
@@ -48,10 +48,10 @@ public:
MonomialMap(const PolyRing& ring):
mMap(new FixedSizeMap(InitialBucketCount, ring)),
mCapacityUntilGrowth
- (maxEntries(mMap.load(::std::memory_order_relaxed)->bucketCount())),
+ (maxEntries(mMap.load(std::memory_order_relaxed)->bucketCount())),
mRing(ring)
{
- // We can load mMap as ::std::memory_order_relaxed because we just stored it
+ // We can load mMap as std::memory_order_relaxed because we just stored it
// and the constructor cannot run concurrently.
}
@@ -81,9 +81,9 @@ public:
class Reader {
public:
Reader(const MonomialMap<T>& map):
- mMap(*map.mMap.load(::std::memory_order_seq_cst))
+ mMap(*map.mMap.load(std::memory_order_seq_cst))
{
- // We grab the hash table pointer with ::std::memory_order_seq_cst in order
+ // We grab the hash table pointer with std::memory_order_seq_cst in order
// to force a CPU cache flush - in this way we are more likely to get an
// up to date value.
}
@@ -92,14 +92,14 @@ public:
/// inserted. Also returns the internal monomial that matches mono if such
/// a monomial exists. Misses can be spurious! Read the comments on the parent
/// class.
- ::std::pair<const mapped_type*, ConstMonomial>
+ std::pair<const mapped_type*, ConstMonomial>
find(const_monomial mono) const {
return mMap.find(mono);
}
// As find but looks for the product of a and b and also returns the
// monomal that is the product.
- ::std::pair<const mapped_type*, ConstMonomial> findProduct(
+ std::pair<const mapped_type*, ConstMonomial> findProduct(
const const_monomial a,
const const_monomial b
) const {
@@ -110,7 +110,7 @@ public:
/// simultaneously. The purpose of this is similar to that of unrolling a
/// loop.
MATHICGB_INLINE
- ::std::pair<const mapped_type*, const mapped_type*> findTwoProducts(
+ std::pair<const mapped_type*, const mapped_type*> findTwoProducts(
const const_monomial a1,
const const_monomial a2,
const const_monomial b
@@ -141,13 +141,13 @@ public:
/// equal value.second if an insertion was not performed - unless the
/// inserted value equals the already present value. p.first.second is an
/// internal monomial that equals value.first.
- ::std::pair< ::std::pair<const mapped_type*, ConstMonomial>, bool>
+ std::pair< std::pair<const mapped_type*, ConstMonomial>, bool>
insert(const value_type& value) {
- const mgb::tbb::mutex::scoped_lock lockGuard(mInsertionMutex);
+ const mgb::mtbb::mutex::scoped_lock lockGuard(mInsertionMutex);
- // We can load mMap as ::std::memory_order_relaxed because we have already
+ // We can load mMap as std::memory_order_relaxed because we have already
// synchronized with all other mutators by locking mInsertionMutex;
- auto map = mMap.load(::std::memory_order_relaxed);
+ auto map = mMap.load(std::memory_order_relaxed);
// this is a loop since it is possible to set the growth factor and
// the initial size so low that several rounds are required. This should
@@ -156,21 +156,21 @@ public:
while (mCapacityUntilGrowth == 0) {
// Resize the table by making a bigger one and using that instead.
if (map->bucketCount() > // check overflow
- ::std::numeric_limits<size_t>::max() / GrowthFactor)
+ std::numeric_limits<size_t>::max() / GrowthFactor)
{
- throw ::std::bad_alloc();
+ throw std::bad_alloc();
}
const size_t newBucketCount = map->bucketCount() * GrowthFactor;
auto nextMap =
- make_unique<FixedSizeMap>(newBucketCount, ::std::move(*map));
+ make_unique<FixedSizeMap>(newBucketCount, std::move(*map));
mOldMaps.emplace_back(map);
mCapacityUntilGrowth =
maxEntries(nextMap->bucketCount()) - maxEntries(map->bucketCount());
- // Store with ::std::memory_order_seq_cst to force a memory flush so that
+ // Store with std::memory_order_seq_cst to force a memory flush so that
// readers see the new table as soon as possible.
map = nextMap.release();
- mMap.store(map, ::std::memory_order_seq_cst);
+ mMap.store(map, std::memory_order_seq_cst);
}
MATHICGB_ASSERT(mCapacityUntilGrowth > 0);
@@ -183,10 +183,10 @@ public:
/// Return the number of entries. This method requires locking so do not
/// call too much. The count may have
size_t entryCount() const {
- const mgb::tbb::mutex::scoped_lock lockGuard(mInsertionMutex);
- // We can load with ::std::memory_order_relaxed because we are holding the
+ const mgb::mtbb::mutex::scoped_lock lockGuard(mInsertionMutex);
+ // We can load with std::memory_order_relaxed because we are holding the
// lock.
- auto& map = *mMap.load(::std::memory_order_relaxed);
+ auto& map = *mMap.load(std::memory_order_relaxed);
return maxEntries(map.bucketCount()) - mCapacityUntilGrowth;
}
@@ -201,7 +201,7 @@ private:
Atomic<FixedSizeMap*> mMap;
const PolyRing& mRing;
- mutable mgb::tbb::mutex mInsertionMutex;
+ mutable mgb::mtbb::mutex mInsertionMutex;
/// Only access this field while holding the mInsertionMutex lock.
size_t mCapacityUntilGrowth;
@@ -211,7 +211,7 @@ private:
/// keep these around as we have no way to determine if there are still
/// readers looking at them. This could be changed at the cost of
/// more overhead in the Reader constructor and destructor.
- ::std::vector< ::std::unique_ptr<FixedSizeMap>> mOldMaps;
+ std::vector< std::unique_ptr<FixedSizeMap>> mOldMaps;
};
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/Poly.hpp b/src/mathicgb/Poly.hpp
index 484cfc4..81ca69c 100755
--- a/src/mathicgb/Poly.hpp
+++ b/src/mathicgb/Poly.hpp
@@ -16,27 +16,27 @@ class Poly {
public:
Poly(const PolyRing& ring) : R(&ring) {MATHICGB_ASSERT(R != 0);}
- void parse(::std::istream &i); // reads into this, sorts terms
- void parseDoNotOrder(::std::istream &i); // reads into this, does not sort terms
+ void parse(std::istream &i); // reads into this, sorts terms
+ void parseDoNotOrder(std::istream &i); // reads into this, does not sort terms
void display(FILE* file, bool printComponent = true) const;
- void display(::std::ostream& out, bool printComponent = true) const;
+ void display(std::ostream& out, bool printComponent = true) const;
void see(bool print_comp) const;
class iterator {
// only for const objects...
size_t monsize;
- ::std::vector<coefficient>::iterator ic;
- ::std::vector<exponent>::iterator im;
+ std::vector<coefficient>::iterator ic;
+ std::vector<exponent>::iterator im;
friend class Poly;
iterator(Poly& f) : monsize(f.getRing()->maxMonomialSize()), ic(f.coeffs.begin()), im(f.monoms.begin()) {}
iterator(Poly& f,int) : ic(f.coeffs.end()), im() {}
public:
- typedef ::std::random_access_iterator_tag iterator_category;
- typedef ::std::pair<coefficient, const const_monomial> value_type;
+ typedef std::random_access_iterator_tag iterator_category;
+ typedef std::pair<coefficient, const const_monomial> value_type;
typedef ptrdiff_t difference_type;
typedef value_type* pointer; // todo: is this OK?
- typedef ::std::pair<coefficient&, const const_monomial> reference;
+ typedef std::pair<coefficient&, const const_monomial> reference;
iterator() {}
iterator operator++() { ++ic; im += monsize; return *this; }
@@ -46,25 +46,25 @@ public:
friend bool operator==(const iterator &a, const iterator &b);
friend bool operator!=(const iterator &a, const iterator &b);
reference operator*() const {
- return ::std::pair<coefficient&, monomial>(getCoefficient(), getMonomial());
+ return std::pair<coefficient&, monomial>(getCoefficient(), getMonomial());
}
};
class const_iterator {
// only for const objects...
size_t monsize;
- ::std::vector<coefficient>::const_iterator ic;
- ::std::vector<exponent>::const_iterator im;
+ std::vector<coefficient>::const_iterator ic;
+ std::vector<exponent>::const_iterator im;
friend class Poly;
const_iterator(const Poly& f) : monsize(f.getRing()->maxMonomialSize()), ic(f.coeffs.begin()), im(f.monoms.begin()) {}
const_iterator(const Poly& f,int) : ic(f.coeffs.end()), im() {}
public:
- typedef ::std::random_access_iterator_tag iterator_category;
- typedef ::std::pair<const coefficient, const const_monomial> value_type;
+ typedef std::random_access_iterator_tag iterator_category;
+ typedef std::pair<const coefficient, const const_monomial> value_type;
typedef ptrdiff_t difference_type;
typedef value_type* pointer; // todo: is this OK?
- typedef ::std::pair<const coefficient&, const const_monomial> reference;
+ typedef std::pair<const coefficient&, const const_monomial> reference;
const_iterator() {}
const_iterator operator++() { ++ic; im += monsize; return *this; }
@@ -74,7 +74,7 @@ public:
friend bool operator==(const const_iterator &a, const const_iterator &b);
friend bool operator!=(const const_iterator &a, const const_iterator &b);
const value_type operator*() const {
- return ::std::pair<coefficient, const_monomial>
+ return std::pair<coefficient, const_monomial>
(getCoefficient(), getMonomial());
}
};
@@ -152,11 +152,11 @@ public:
private:
const PolyRing *R;
- ::std::vector<coefficient> coeffs;
- ::std::vector<exponent> monoms;
+ std::vector<coefficient> coeffs;
+ std::vector<exponent> monoms;
};
-::std::ostream& operator<<(::std::ostream& out, const Poly& p);
+std::ostream& operator<<(std::ostream& out, const Poly& p);
inline bool operator==(const Poly::iterator &a, const Poly::iterator &b)
{
diff --git a/src/mathicgb/PolyBasis.hpp b/src/mathicgb/PolyBasis.hpp
index a7d4d3a..719dfc1 100755
--- a/src/mathicgb/PolyBasis.hpp
+++ b/src/mathicgb/PolyBasis.hpp
@@ -20,19 +20,19 @@ public:
// Ring must live for as long as this object.
PolyBasis(
const PolyRing& ring,
- ::std::unique_ptr<DivisorLookup> divisorLookup
+ std::unique_ptr<DivisorLookup> divisorLookup
);
// Deletes the Poly's stored in the basis.
~PolyBasis();
// Returns the initial monomial basis of the basis.
- ::std::unique_ptr<Basis> initialIdeal() const;
+ std::unique_ptr<Basis> initialIdeal() const;
// Inserts a polynomial into the basis at index size().
// Lead monomials must be unique among basis elements.
// So the index is size() - 1 afterwards since size() will increase by 1.
- void insert(::std::unique_ptr<Poly> poly);
+ void insert(std::unique_ptr<Poly> poly);
// Returns the index of a basis element whose lead term divides mon.
// Returns -1 if there is no such basis element.
@@ -48,7 +48,7 @@ public:
// Replaces basis element at index with the given new value. The lead
// term of the new polynomial must be the same as the previous one.
// This is useful for auto-tail-reduction.
- void replaceSameLeadTerm(size_t index, ::std::unique_ptr<Poly> newValue) {
+ void replaceSameLeadTerm(size_t index, std::unique_ptr<Poly> newValue) {
MATHICGB_ASSERT(index < size());
MATHICGB_ASSERT(!retired(index));
MATHICGB_ASSERT(newValue.get() != 0);
@@ -76,12 +76,12 @@ public:
// Retires the basis element at index, which frees the memory associated
// to it, including the basis element polynomial, and marks it as retired.
- ::std::unique_ptr<Poly> retire(size_t index);
+ std::unique_ptr<Poly> retire(size_t index);
/// Returns an basis containing all non-retired basis elements and
/// retires all those basis elements. The point of the simultaneous
/// retirement is that this way no polynomials need be copied.
- ::std::unique_ptr<Basis> toBasisAndRetireAll();
+ std::unique_ptr<Basis> toBasisAndRetireAll();
// Returns true of the basis element at index has been retired.
bool retired(size_t index) const {
@@ -214,13 +214,13 @@ private:
mutable unsigned long long possibleReducerCount;
mutable unsigned long long nonSignatureReducerCount;
};
- typedef ::std::vector<Entry> EntryCont;
+ typedef std::vector<Entry> EntryCont;
typedef EntryCont::iterator EntryIter;
typedef EntryCont::const_iterator EntryCIter;
const PolyRing& mRing;
- ::std::unique_ptr<DivisorLookup> mDivisorLookup;
- ::std::vector<Entry> mEntries;
+ std::unique_ptr<DivisorLookup> mDivisorLookup;
+ std::vector<Entry> mEntries;
};
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/PolyRing.cpp b/src/mathicgb/PolyRing.cpp
index 0c7e398..fe742a0 100755
--- a/src/mathicgb/PolyRing.cpp
+++ b/src/mathicgb/PolyRing.cpp
@@ -57,7 +57,7 @@ void PolyRing::monomialSetIdentity(Monomial& result) const
monoid().setIdentity(result);
}
-void PolyRing::monomialEi(size_t i, Monomial &result) const
+void PolyRing::monomialEi(Monoid::Component i, Monomial &result) const
{
monoid().setIdentity(result);
monoid().setComponent(i, result);
diff --git a/src/mathicgb/PolyRing.hpp b/src/mathicgb/PolyRing.hpp
index 3be2658..dde7d17 100755
--- a/src/mathicgb/PolyRing.hpp
+++ b/src/mathicgb/PolyRing.hpp
@@ -22,8 +22,8 @@ MATHICGB_NAMESPACE_BEGIN
template<class T>
PrimeField<
- typename ::std::make_unsigned<
- typename ::std::remove_reference<T>::type
+ typename std::make_unsigned<
+ typename std::remove_reference<T>::type
>::type
> makeField(T charac) {
return charac;
@@ -153,7 +153,7 @@ public:
Monomial(exponent *val) : ConstMonomial(val) {}
void swap(Monomial& monomial) {
- ::std::swap(mValue, monomial.mValue);
+ std::swap(mValue, monomial.mValue);
}
exponent * unsafeGetRepresentation() { return const_cast<exponent *>(mValue); }
@@ -205,7 +205,7 @@ public:
coefficient charac,
int nvars,
bool lexBaseOrder,
- ::std::vector<exponent>&& weights
+ std::vector<exponent>&& weights
);
PolyRing(const Field& field, Monoid&& monoid);
@@ -217,11 +217,11 @@ public:
coefficient charac() const { return mField.charac(); }
size_t getNumVars() const { return varCount();}
size_t varCount() const {return monoid().varCount();}
- // const ::std::vector<int> °s,
- // const ::std::string &monorder);
+ // const std::vector<int> °s,
+ // const std::string &monorder);
- static ::std::pair<PolyRing*, ::std::pair<bool, bool>> read(::std::istream &i);
- void write(::std::ostream &o, bool componentIncreasingDesired) const;
+ static std::pair<PolyRing*, std::pair<bool, bool>> read(std::istream &i);
+ void write(std::ostream &o, bool componentIncreasingDesired) const;
// Format for ring
// <char> <mNumVars> <deg1> ... <deg_n> <monorder>
@@ -234,7 +234,7 @@ public:
// fill with value that do not make sense to catch bugs in debug
// mode. The maximum value of setting all bits increases the
// chances of getting an assert.
- ::std::fill_n(reinterpret_cast<char*>(ptr), maxMonomialByteSize(),
+ std::fill_n(reinterpret_cast<char*>(ptr), maxMonomialByteSize(),
~static_cast<char>(0));
#endif
return ptr;
@@ -256,7 +256,7 @@ public:
// fill with value that do not make sense to catch bugs in debug
// mode. The maximum value of setting all bits increases the
// chances of getting an assert.
- ::std::fill_n(reinterpret_cast<char*>(ptr), maxMonomialByteSize(),
+ std::fill_n(reinterpret_cast<char*>(ptr), maxMonomialByteSize(),
~static_cast<char>(0));
#endif
return ptr;
@@ -384,7 +384,7 @@ public:
void monomialSetIdentity(Monomial& result) const;
- void monomialEi(size_t i, Monomial &result) const;
+ void monomialEi(Monoid::Component i, Monomial &result) const;
void monomialMult(ConstMonomial a, ConstMonomial b, Monomial &result) const;
@@ -459,10 +459,10 @@ public:
ConstMonomial smaller1,
ConstMonomial smaller2) const;
- void monomialParse(::std::istream& i,
+ void monomialParse(std::istream& i,
Monomial& result) const;
- void monomialDisplay(::std::ostream& o,
+ void monomialDisplay(std::ostream& o,
ConstMonomial a,
bool print_comp=true,
bool print_one=true) const;
@@ -471,7 +471,7 @@ public:
bool printComponent = true,
bool printOne = true) const;
- void printMonomialFrobbyM2Format(::std::ostream& out, ConstMonomial m) const;
+ void printMonomialFrobbyM2Format(std::ostream& out, ConstMonomial m) const;
///////////////////////////////////////////
///////////////////////////////////////////
diff --git a/src/mathicgb/PrimeField.hpp b/src/mathicgb/PrimeField.hpp
index 1be98c5..58a88ef 100755
--- a/src/mathicgb/PrimeField.hpp
+++ b/src/mathicgb/PrimeField.hpp
@@ -11,7 +11,7 @@ MATHICGB_NAMESPACE_BEGIN
/// Implements arithmetic in a prime field. T must be an unsigned integer type
/// that is used to store the elements of the field. The characteristic of the
-/// field must be a prime not exceeding ::std::numeric_limits<T>::max().
+/// field must be a prime not exceeding std::numeric_limits<T>::max().
template<class T>
class PrimeField {
public:
@@ -19,8 +19,8 @@ public:
class Element {
public:
- static_assert(!::std::numeric_limits<T>::is_signed, "");
- static_assert(::std::numeric_limits<T>::is_integer, "");
+ static_assert(!std::numeric_limits<T>::is_signed, "");
+ static_assert(std::numeric_limits<T>::is_integer, "");
Element(const Element& e): mValue(e.value()) {}
@@ -55,19 +55,19 @@ public:
/// Assumes that i is in the range [0;charac()).
template<class Integer>
Element toElementInRange(Integer&& i) const {
- typedef typename ::std::remove_reference<Integer>::type NoRefInteger;
- static_assert(::std::numeric_limits<NoRefInteger>::is_integer, "");
+ typedef typename std::remove_reference<Integer>::type NoRefInteger;
+ static_assert(std::numeric_limits<NoRefInteger>::is_integer, "");
MATHICGB_ASSERT(0 <= i);
- typedef typename ::std::make_unsigned<NoRefInteger>::type Unsigned;
+ typedef typename std::make_unsigned<NoRefInteger>::type Unsigned;
MATHICGB_ASSERT(static_cast<Unsigned>(i) < charac());
return Element(i);
}
template<class Integer>
Element toElement(Integer&& i) const {
- typedef typename ::std::remove_reference<Integer>::type NoRefInteger;
- static_assert(::std::numeric_limits<NoRefInteger>::is_integer, "");
+ typedef typename std::remove_reference<Integer>::type NoRefInteger;
+ static_assert(std::numeric_limits<NoRefInteger>::is_integer, "");
// We need to take the modulus of i to put it into the range [0;charac()).
// That is more tricky to get right than it might seem.
@@ -78,11 +78,11 @@ public:
// converted to a signed integer since it might not be representable that
// way.
//
- // If Integer is signed and i is ::std::numeric_limits<Integer>::min() then
+ // If Integer is signed and i is std::numeric_limits<Integer>::min() then
// it is undefined behavior to evaluate the expression -i since -i is not
// representable, leading to a signed overflow. So we have to cast to
// unsigned before doing the minus.
- typedef typename ::std::make_unsigned<NoRefInteger>::type Unsigned;
+ typedef typename std::make_unsigned<NoRefInteger>::type Unsigned;
if (i < 0) {
// Negate i to get a positive number, then negate again to cancel out
// the first negation. The first cast to unsigned is to avoid
@@ -227,8 +227,8 @@ auto PrimeField<T>::inverse(const Element elementA) const -> Element {
template<class T>
-::std::ostream& operator<<(
- ::std::ostream& out,
+std::ostream& operator<<(
+ std::ostream& out,
typename PrimeField<T>::Element e
) {
out << e.value();
diff --git a/src/mathicgb/QuadMatrix.cpp b/src/mathicgb/QuadMatrix.cpp
index 58167f0..ddc8ff2 100755
--- a/src/mathicgb/QuadMatrix.cpp
+++ b/src/mathicgb/QuadMatrix.cpp
@@ -33,7 +33,7 @@ bool QuadMatrix::debugAssertValid() const {
#endif
}
-void QuadMatrix::print(::std::ostream& out) const {
+void QuadMatrix::print(std::ostream& out) const {
MATHICGB_ASSERT(debugAssertValid());
typedef SparseMatrix::ColIndex ColIndex;
@@ -78,22 +78,22 @@ SparseMatrix::ColIndex QuadMatrix::computeLeftColCount() const {
if (!leftColumnMonomials.empty()) {
MATHICGB_ASSERT(
leftColumnMonomials.size() <=
- ::std::numeric_limits<SparseMatrix::ColIndex>::max()
+ std::numeric_limits<SparseMatrix::ColIndex>::max()
);
return static_cast<SparseMatrix::ColIndex>(leftColumnMonomials.size());
}
- return ::std::max(topLeft.computeColCount(), bottomLeft.computeColCount());
+ return std::max(topLeft.computeColCount(), bottomLeft.computeColCount());
}
SparseMatrix::ColIndex QuadMatrix::computeRightColCount() const {
if (!rightColumnMonomials.empty()) {
MATHICGB_ASSERT(
rightColumnMonomials.size() <=
- ::std::numeric_limits<SparseMatrix::ColIndex>::max()
+ std::numeric_limits<SparseMatrix::ColIndex>::max()
);
return static_cast<SparseMatrix::ColIndex>(rightColumnMonomials.size());
}
- return ::std::max(topRight.computeColCount(), bottomRight.computeColCount());
+ return std::max(topRight.computeColCount(), bottomRight.computeColCount());
}
size_t QuadMatrix::entryCount() const {
@@ -102,8 +102,8 @@ size_t QuadMatrix::entryCount() const {
bottomLeft.entryCount() + bottomRight.entryCount();
}
-::std::string QuadMatrix::toString() const {
- ::std::ostringstream out;
+std::string QuadMatrix::toString() const {
+ std::ostringstream out;
print(out);
return out.str();
}
@@ -118,7 +118,7 @@ size_t QuadMatrix::memoryUseTrimmed() const {
bottomLeft.memoryUseTrimmed() + bottomRight.memoryUseTrimmed();
}
-void QuadMatrix::printStatistics(::std::ostream& out) const {
+void QuadMatrix::printStatistics(std::ostream& out) const {
typedef mathic::ColumnPrinter ColPr;
ColPr pr;
@@ -131,7 +131,7 @@ void QuadMatrix::printStatistics(::std::ostream& out) const {
const auto totalMemory = memoryUse();
auto printDataCol = [&](
- ::std::ostream& out,
+ std::ostream& out,
const SparseMatrix& top,
const SparseMatrix& bottom,
const SparseMatrix::ColIndex colCount
@@ -213,12 +213,12 @@ QuadMatrix QuadMatrix::toCanonical() const {
// todo: eliminate left/right code duplication here
QuadMatrix matrix;
{ // left side
- ::std::vector<SparseMatrix::RowIndex> rows;
+ std::vector<SparseMatrix::RowIndex> rows;
for (SparseMatrix::RowIndex row = 0; row < topLeft.rowCount(); ++row)
rows.push_back(row);
{
RowComparer comparer(topLeft);
- ::std::sort(rows.begin(), rows.end(), comparer);
+ std::sort(rows.begin(), rows.end(), comparer);
}
matrix.topLeft.clear();
@@ -229,12 +229,12 @@ QuadMatrix QuadMatrix::toCanonical() const {
}
}
{ // right side
- ::std::vector<SparseMatrix::RowIndex> rows;
+ std::vector<SparseMatrix::RowIndex> rows;
for (SparseMatrix::RowIndex row = 0; row < bottomLeft.rowCount(); ++row)
rows.push_back(row);
{
RowComparer comparer(bottomLeft);
- ::std::sort(rows.begin(), rows.end(), comparer);
+ std::sort(rows.begin(), rows.end(), comparer);
}
matrix.bottomLeft.clear();
@@ -249,10 +249,10 @@ QuadMatrix QuadMatrix::toCanonical() const {
matrix.rightColumnMonomials = rightColumnMonomials;
matrix.ring = ring;
- return ::std::move(matrix);
+ return std::move(matrix);
}
-::std::ostream& operator<<(::std::ostream& out, const QuadMatrix& qm) {
+std::ostream& operator<<(std::ostream& out, const QuadMatrix& qm) {
qm.print(out);
return out;
}
@@ -263,7 +263,7 @@ namespace {
ColumnComparer(const PolyRing& ring): mRing(ring) {}
typedef SparseMatrix::ColIndex ColIndex;
- typedef ::std::pair<monomial, ColIndex> Pair;
+ typedef std::pair<monomial, ColIndex> Pair;
bool operator()(const Pair& a, const Pair b) const {
return mRing.monomialLT(b.first, a.first);
}
@@ -272,20 +272,20 @@ namespace {
const PolyRing& mRing;
};
- ::std::vector<SparseMatrix::ColIndex> sortColumnMonomialsAndMakePermutation(
- ::std::vector<monomial>& monomials,
+ std::vector<SparseMatrix::ColIndex> sortColumnMonomialsAndMakePermutation(
+ std::vector<monomial>& monomials,
const PolyRing& ring
) {
typedef SparseMatrix::ColIndex ColIndex;
- MATHICGB_ASSERT(monomials.size() <= ::std::numeric_limits<ColIndex>::max());
+ MATHICGB_ASSERT(monomials.size() <= std::numeric_limits<ColIndex>::max());
const ColIndex colCount = static_cast<ColIndex>(monomials.size());
// Monomial needs to be non-const as we are going to put these
// monomials back into the vector of monomials which is not const.
- ::std::vector< ::std::pair<monomial, ColIndex>> columns;
+ std::vector< std::pair<monomial, ColIndex>> columns;
columns.reserve(colCount);
for (ColIndex col = 0; col < colCount; ++col)
- columns.push_back(::std::make_pair(monomials[col], col));
- ::std::sort(columns.begin(), columns.end(), ColumnComparer(ring));
+ columns.push_back(std::make_pair(monomials[col], col));
+ std::sort(columns.begin(), columns.end(), ColumnComparer(ring));
// Apply sorting permutation to monomials. This is why it is necessary to
// copy the values in monomial out of there: in-place application of a
@@ -299,23 +299,23 @@ namespace {
}
// Construct permutation of indices to match permutation of monomials
- ::std::vector<ColIndex> permutation(colCount);
+ std::vector<ColIndex> permutation(colCount);
for (ColIndex col = 0; col < colCount; ++col) {
// The monomial for column columns[col].second is now the
// monomial for col, so we need the inverse map for indices.
permutation[columns[col].second] = col;
}
- return ::std::move(permutation);
+ return std::move(permutation);
}
}
void QuadMatrix::sortColumnsLeftRightParallel() {
typedef SparseMatrix::ColIndex ColIndex;
- ::std::vector<ColIndex> leftPermutation;
- ::std::vector<ColIndex> rightPermutation;
+ std::vector<ColIndex> leftPermutation;
+ std::vector<ColIndex> rightPermutation;
- mgb::tbb::parallel_for(0, 2, 1, [&](int i) {
+ mgb::mtbb::parallel_for(0, 2, 1, [&](int i) {
if (i == 0)
leftPermutation =
sortColumnMonomialsAndMakePermutation(leftColumnMonomials, *ring);
@@ -324,7 +324,7 @@ void QuadMatrix::sortColumnsLeftRightParallel() {
sortColumnMonomialsAndMakePermutation(rightColumnMonomials, *ring);
});
- mgb::tbb::parallel_for(0, 4, 1, [&](int i) {
+ mgb::mtbb::parallel_for(0, 4, 1, [&](int i) {
if (i == 0)
topRight.applyColumnMap(rightPermutation);
else if (i == 1)
diff --git a/src/mathicgb/QuadMatrix.hpp b/src/mathicgb/QuadMatrix.hpp
index 81b9b0d..37127a5 100755
--- a/src/mathicgb/QuadMatrix.hpp
+++ b/src/mathicgb/QuadMatrix.hpp
@@ -25,18 +25,18 @@ public:
QuadMatrix() {}
QuadMatrix(QuadMatrix&& matrix):
- topLeft(::std::move(matrix.topLeft)),
- topRight(::std::move(matrix.topRight)),
- bottomLeft(::std::move(matrix.bottomLeft)),
- bottomRight(::std::move(matrix.bottomRight)),
- leftColumnMonomials(::std::move(matrix.leftColumnMonomials)),
- rightColumnMonomials(::std::move(matrix.rightColumnMonomials)),
+ topLeft(std::move(matrix.topLeft)),
+ topRight(std::move(matrix.topRight)),
+ bottomLeft(std::move(matrix.bottomLeft)),
+ bottomRight(std::move(matrix.bottomRight)),
+ leftColumnMonomials(std::move(matrix.leftColumnMonomials)),
+ rightColumnMonomials(std::move(matrix.rightColumnMonomials)),
ring(matrix.ring)
{}
QuadMatrix& operator=(QuadMatrix&& matrix) {
this->~QuadMatrix();
- new (this) QuadMatrix(::std::move(matrix));
+ new (this) QuadMatrix(std::move(matrix));
return *this;
}
@@ -44,21 +44,21 @@ public:
SparseMatrix topRight;
SparseMatrix bottomLeft;
SparseMatrix bottomRight;
- ::std::vector<monomial> leftColumnMonomials;
- ::std::vector<monomial> rightColumnMonomials;
+ std::vector<monomial> leftColumnMonomials;
+ std::vector<monomial> rightColumnMonomials;
const PolyRing* ring;
/// Prints whole matrix to out in human-readable format. Useful for
/// debugging.
- void print(::std::ostream& out) const;
+ void print(std::ostream& out) const;
- void printStatistics(::std::ostream& out) const;
+ void printStatistics(std::ostream& out) const;
size_t memoryUse() const;
size_t memoryUseTrimmed() const;
/// Shows whole matrix in a string. Useful for debugging.
- ::std::string toString() const;
+ std::string toString() const;
/// Return the combined number of non-zero entries.
size_t entryCount() const;
@@ -94,7 +94,7 @@ private:
void operator=(const QuadMatrix&); // not available
};
-::std::ostream& operator<<(::std::ostream& out, const QuadMatrix& qm);
+std::ostream& operator<<(std::ostream& out, const QuadMatrix& qm);
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/QuadMatrixBuilder.cpp b/src/mathicgb/QuadMatrixBuilder.cpp
index b963836..490ef5f 100755
--- a/src/mathicgb/QuadMatrixBuilder.cpp
+++ b/src/mathicgb/QuadMatrixBuilder.cpp
@@ -29,13 +29,12 @@ void QuadMatrixBuilder::takeRowsFrom(QuadMatrix&& matrix) {
MATHICGB_ASSERT(&ring() == matrix.ring);
MATHICGB_ASSERT(matrix.debugAssertValid());
- mTopLeft.takeRowsFrom(::std::move(matrix.topLeft));
- mTopRight.takeRowsFrom(::std::move(matrix.topRight));
- mBottomLeft.takeRowsFrom(::std::move(matrix.bottomLeft));
- mBottomRight.takeRowsFrom(::std::move(matrix.bottomRight));
+ mTopLeft.takeRowsFrom(std::move(matrix.topLeft));
+ mTopRight.takeRowsFrom(std::move(matrix.topRight));
+ mBottomLeft.takeRowsFrom(std::move(matrix.bottomLeft));
+ mBottomRight.takeRowsFrom(std::move(matrix.bottomRight));
}
-
namespace {
/// Creates a column and updates the associated data structures that
/// are passed in. Copies mono - ownership is not taken over. The
@@ -43,7 +42,7 @@ namespace {
/// template in order to avoid referring to private types of
/// QuadMatrixBuilder.
template<class ToMono, class ToCol>
- ::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+ std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
createCol(
const_monomial mono,
SparseMatrix& top,
@@ -57,15 +56,15 @@ namespace {
const auto colCount =
static_cast<QuadMatrixBuilder::ColIndex>(toMonomial.size());
- if (colCount == ::std::numeric_limits<QuadMatrixBuilder::ColIndex>::max())
- throw ::std::overflow_error("Too many columns in QuadMatrixBuilder");
+ if (colCount == std::numeric_limits<QuadMatrixBuilder::ColIndex>::max())
+ throw std::overflow_error("Too many columns in QuadMatrixBuilder");
toMonomial.push_back(0); // allocate memory now to avoid bad_alloc later
monomial copied = ring.allocMonomial();
ring.monomialCopy(mono, copied);
- ::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial> p;
+ std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial> p;
try {
- auto inserted = toCol.insert(::std::make_pair(
+ auto inserted = toCol.insert(std::make_pair(
copied, QuadMatrixBuilder::LeftRightColIndex(colCount, left))
);
MATHICGB_ASSERT(inserted.second);
@@ -75,7 +74,7 @@ namespace {
MATHICGB_ASSERT(ring.monomialEqualHintTrue(copied, p.second));
MATHICGB_ASSERT(*p.first == QuadMatrixBuilder::LeftRightColIndex(colCount, left));
- return ::std::make_pair(*p.first, p.second);
+ return std::make_pair(*p.first, p.second);
} catch (...) {
toMonomial.pop_back();
ring.freeMonomial(copied);
@@ -84,7 +83,7 @@ namespace {
}
}
-::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
QuadMatrixBuilder::createColumnLeft(
const_monomial monomialToBeCopied
) {
@@ -98,7 +97,7 @@ QuadMatrixBuilder::createColumnLeft(
true);
}
-::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
QuadMatrixBuilder::createColumnRight(
const_monomial monomialToBeCopied
) {
@@ -127,7 +126,7 @@ QuadMatrix QuadMatrixBuilder::buildMatrixAndClear() {
mBottomRight.clear();
MATHICGB_ASSERT(out.debugAssertValid());
- return ::std::move(out);
+ return std::move(out);
}
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/QuadMatrixBuilder.hpp b/src/mathicgb/QuadMatrixBuilder.hpp
index 8b2b556..ee6e3d7 100755
--- a/src/mathicgb/QuadMatrixBuilder.hpp
+++ b/src/mathicgb/QuadMatrixBuilder.hpp
@@ -34,7 +34,7 @@ class QuadMatrixBuilder {
class LeftRightColIndex {
public:
LeftRightColIndex():
- mRawIndex(::std::numeric_limits<ColIndex>::max()), mLeft(false) {}
+ mRawIndex(std::numeric_limits<ColIndex>::max()), mLeft(false) {}
LeftRightColIndex(ColIndex index, bool left):
mRawIndex(index), mLeft(left) {
}
@@ -67,7 +67,7 @@ class QuadMatrixBuilder {
}
bool valid() const {
- return mRawIndex != ::std::numeric_limits<ColIndex>::max();
+ return mRawIndex != std::numeric_limits<ColIndex>::max();
}
bool operator==(const LeftRightColIndex& index) const {
@@ -84,7 +84,7 @@ class QuadMatrixBuilder {
};
typedef MonomialMap<LeftRightColIndex> Map;
- typedef ::std::vector<monomial> MonomialsType;
+ typedef std::vector<monomial> MonomialsType;
QuadMatrixBuilder(
const PolyRing& ring,
@@ -165,13 +165,13 @@ class QuadMatrixBuilder {
/** Creates a new column associated to the monomial
monomialToBeCopied to the left matrices. There must not already
exist a column for this monomial on the left or on the right. */
- ::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+ std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
createColumnLeft(const_monomial monomialToBeCopied);
/** Creates a new column associated to the monomial monomialToBeCopied
to the right matrices. There must not already exist a column for
this monomial on the left or on the right. */
- ::std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
+ std::pair<QuadMatrixBuilder::LeftRightColIndex, ConstMonomial>
createColumnRight(const_monomial monomialToBeCopied);
// *** Querying columns
diff --git a/src/mathicgb/RawVector.hpp b/src/mathicgb/RawVector.hpp
index f54a949..10ea2d5 100755
--- a/src/mathicgb/RawVector.hpp
+++ b/src/mathicgb/RawVector.hpp
@@ -36,8 +36,8 @@ public:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
- typedef ::std::reverse_iterator<iterator> reverse_iterator;
- typedef ::std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
/// Initializes to the null state.
RawVector(): mBegin(0), mEnd(0), mCapacityEnd(0) {}
diff --git a/src/mathicgb/Scanner.hpp b/src/mathicgb/Scanner.hpp
index 4f32048..4c1af9d 100755
--- a/src/mathicgb/Scanner.hpp
+++ b/src/mathicgb/Scanner.hpp
@@ -110,9 +110,9 @@ public:
/// Returns true if the next character is a digit. Does not skip
/// whitespace.
- bool peekDigit() {return ::std::isdigit(peek());}
+ bool peekDigit() {return std::isdigit(peek());}
- bool peekAlpha() {return ::std::isalpha(peek());}
+ bool peekAlpha() {return std::isalpha(peek());}
/// Returns true if the next character is whitespace. Does not skip
/// whitespace. Whitespace is defined by std::isspace().
diff --git a/src/mathicgb/ScopeExit.hpp b/src/mathicgb/ScopeExit.hpp
index 2cb7f81..3189333 100755
--- a/src/mathicgb/ScopeExit.hpp
+++ b/src/mathicgb/ScopeExit.hpp
@@ -17,13 +17,13 @@ public:
private:
friend struct GuardMaker;
Guard(T&& action, const bool& active):
- mAction(::std::move(action)), mOwning(true), mActive(active) {}
+ mAction(std::move(action)), mOwning(true), mActive(active) {}
// Most compilers should elide the call to this construtor, but it must be
// here anyway and we should support even a crazy compiler that decides to
// call it.
Guard(Guard<T>&& guard):
- mAction(::std::move(guard.mAction)), mOwning(true), mActive(guard.mActive)
+ mAction(std::move(guard.mAction)), mOwning(true), mActive(guard.mActive)
{
assert(guard.mActive);
guard.mOwning = false; // to avoid calling mAction twice
@@ -51,7 +51,7 @@ public:
GuardMaker(const bool& active): mActive(active) {}
template<class T>
- Guard<T> operator+(T&& t) {return Guard<T>(::std::forward<T>(t), mActive);}
+ Guard<T> operator+(T&& t) {return Guard<T>(std::forward<T>(t), mActive);}
private:
const bool& mActive;
@@ -67,7 +67,7 @@ MATHICGB_NAMESPACE_END
// FILE* file = fopen("file.txt", "r");
// MATHICGB_SCOPE_EXIT() {
// fclose(file);
-// ::std::cout << "file closed";
+// std::cout << "file closed";
// };
// // ...
// return; // the file is closed
diff --git a/src/mathicgb/SigSPairQueue.cpp b/src/mathicgb/SigSPairQueue.cpp
index bfe97e5..1e894e8 100755
--- a/src/mathicgb/SigSPairQueue.cpp
+++ b/src/mathicgb/SigSPairQueue.cpp
@@ -1,204 +1,204 @@
-// MathicGB copyright 2012 all rights reserved. MathicGB comes with ABSOLUTELY
-// NO WARRANTY and is licensed as GPL v2.0 or later - see LICENSE.txt.
-#include "stdinc.h"
-#include "SigSPairQueue.hpp"
-
-#include "SigPolyBasis.hpp"
-
-MATHICGB_NAMESPACE_BEGIN
-
-SigSPairQueue::~SigSPairQueue() {}
-
-namespace {
- class Comparer {
- public:
- typedef PolyRing::Monoid Monoid;
-
- Comparer(const Monoid& monoid): mMonoid(monoid) {}
- bool operator()(const PreSPair& a, const PreSPair& b) const {
- return mMonoid.lessThan(a.signature, b.signature);
- }
- private:
- const Monoid& mMonoid;
- };
-
- // Iterator that accesses the field i based on a passed-in iterator.
- template<class PairIterator>
- class IndexIterator {
- public:
-
- typedef typename PairIterator::iterator_category iterator_category;
- typedef decltype(reinterpret_cast<typename PairIterator::value_type*>(0)->i) value_type;
- typedef typename PairIterator::difference_type difference_type;
- typedef value_type* pointer;
- typedef value_type& reference;
-
- IndexIterator(PairIterator pairIterator): mIterator(pairIterator) {}
- IndexIterator& operator++() {++mIterator; return *this;}
- const value_type operator*() const {return mIterator->i;}
- difference_type operator-(const IndexIterator<PairIterator>& it) const {
- return mIterator - it.mIterator;
- }
- bool operator==(const IndexIterator<PairIterator>& it) const {
- return mIterator == it.mIterator;
- }
- bool operator!=(const IndexIterator<PairIterator>& it) const {
- return mIterator != it.mIterator;
- }
-
- private:
- PairIterator mIterator;
- };
-}
-
-
-class ConcreteSigSPairQueue : public SigSPairQueue {
-public:
- ConcreteSigSPairQueue(SigPolyBasis const& basis):
- mPairQueue(Configuration(basis)) {}
-
- virtual monomial popSignature(Pairs& pairs) {
- pairs.clear();
- if (mPairQueue.empty())
- return 0;
- monomial sig = ring().allocMonomial();
- ring().monomialCopy(mPairQueue.topPairData(), sig);
- do {
- pairs.push_back(mPairQueue.topPair());
- mPairQueue.pop();
- } while
- (!mPairQueue.empty() && ring().monomialEQ(mPairQueue.topPairData(), sig));
- return sig;
- }
-
- virtual void pushPairs(size_t pairWith, IndexSigs& pairs) {
-#ifdef DEBUG
- monomial tmp = ring().allocMonomial();
- for (size_t i = 0; i < pairs.size(); ++i) {
- MATHICGB_ASSERT(pairs[i].i < columnCount());
- mPairQueue.configuration().computePairData
- (columnCount(), pairs[i].i, tmp);
- MATHICGB_ASSERT(ring().monomialEQ(tmp, pairs[i].signature));
- }
- ring().freeMonomial(tmp);
-#endif
-
- if (columnCount() >= std::numeric_limits<BigIndex>::max())
- throw std::overflow_error
- ("Too large basis element index in constructing S-pairs.");
-
- // sort and insert new column
- Comparer cmp(ring().monoid());
- std::sort(pairs.begin(), pairs.end(), cmp);
- typedef IndexIterator<std::vector<PreSPair>::const_iterator> Iter;
- mPairQueue.addColumnDescending(Iter(pairs.begin()), Iter(pairs.end()));
-
- // free signatures
- std::vector<PreSPair>::iterator end = pairs.end();
- for (std::vector<PreSPair>::iterator it = pairs.begin(); it != end; ++it)
- ring().freeMonomial(it->signature);
- pairs.clear();
- }
-
- virtual std::string name() const {return "todo";}
-
- virtual size_t memoryUse() const {return mPairQueue.getMemoryUse();}
-
- virtual size_t pairCount() const {return mPairQueue.pairCount();}
-
- virtual size_t columnCount() const {return mPairQueue.columnCount();}
-
-private:
- ConcreteSigSPairQueue(const ConcreteSigSPairQueue&); // not available
- void operator=(const ConcreteSigSPairQueue&); // not available
-
- // Configuration of mathic::PairTriangle for use with signature queues.
- class Configuration {
- public:
- Configuration(SigPolyBasis const& basis): mBasis(basis) {}
-
- typedef monomial PairData;
- void computePairData(size_t col, size_t row, monomial sig) {
- MATHICGB_ASSERT(mBasis.ratioCompare(col, row) != EQ);
- // ensure that ratio(col) > ratio(row)
- if (mBasis.ratioCompare(col, row) == LT)
- std::swap(col, row);
- mBasis.ring().monomialFindSignature
- (mBasis.getLeadMonomial(col),
- mBasis.getLeadMonomial(row),
- mBasis.getSignature(col), sig);
- }
-
- typedef bool CompareResult;
- bool compare(int colA, int rowA, const_monomial a,
- int colB, int rowB, const_monomial b) const {
- return mBasis.ring().monoid().lessThan(b, a);
- }
- bool cmpLessThan(bool v) const {return v;}
-
- SigPolyBasis const& basis() const {return mBasis;}
-
- private:
- SigPolyBasis const& mBasis;
- };
-
- // the compiler should be able to resolve these accessors into a direct
- // offset as though these were member variables.
- const SigPolyBasis& basis() const {
- return mPairQueue.configuration().basis();
- }
- PolyRing const& ring() const {return basis().ring();}
-
- mathic::PairQueue<Configuration> mPairQueue;
- friend struct
- mathic::PairQueueNamespace::ConstructPairDataFunction<Configuration>;
- friend struct
- mathic::PairQueueNamespace::DestructPairDataFunction<Configuration>;
-};
-
-std::unique_ptr<SigSPairQueue> SigSPairQueue::create(
- SigPolyBasis const& basis
-) {
- return make_unique<ConcreteSigSPairQueue>(basis);
-}
-
-MATHICGB_NAMESPACE_END
-
-namespace mathic {
- namespace PairQueueNamespace {
- template<>
- struct ConstructPairDataFunction
- <mgb::ConcreteSigSPairQueue::Configuration>
- {
- inline static void function(
- void* memory,
- Index col,
- Index row,
- mgb::ConcreteSigSPairQueue::Configuration& conf
- ) {
- MATHICGB_ASSERT(memory != 0);
- MATHICGB_ASSERT(col > row);
- auto pd = new (memory)
- mgb::ConcreteSigSPairQueue::Configuration::PairData
- (conf.basis().ring().allocMonomial());
- conf.computePairData(col, row, *pd);
- }
- };
-
- template<>
- struct DestructPairDataFunction
- <mgb::ConcreteSigSPairQueue::Configuration>
- {
- inline static void function(
- mgb::ConcreteSigSPairQueue::Configuration::PairData* pd,
- Index col,
- Index row,
- mgb::ConcreteSigSPairQueue::Configuration& conf
- ) {
- MATHICGB_ASSERT(pd != 0);
- MATHICGB_ASSERT(col > row);
- conf.basis().ring().freeMonomial(*pd);
- }
- };
- }
-}
+// MathicGB copyright 2012 all rights reserved. MathicGB comes with ABSOLUTELY
+// NO WARRANTY and is licensed as GPL v2.0 or later - see LICENSE.txt.
+#include "stdinc.h"
+#include "SigSPairQueue.hpp"
+
+#include "SigPolyBasis.hpp"
+
+MATHICGB_NAMESPACE_BEGIN
+
+SigSPairQueue::~SigSPairQueue() {}
+
+namespace {
+ class Comparer {
+ public:
+ typedef PolyRing::Monoid Monoid;
+
+ Comparer(const Monoid& monoid): mMonoid(monoid) {}
+ bool operator()(const PreSPair& a, const PreSPair& b) const {
+ return mMonoid.lessThan(a.signature, b.signature);
+ }
+ private:
+ const Monoid& mMonoid;
+ };
+
+ // Iterator that accesses the field i based on a passed-in iterator.
+ template<class PairIterator>
+ class IndexIterator {
+ public:
+
+ typedef typename PairIterator::iterator_category iterator_category;
+ typedef decltype(reinterpret_cast<typename PairIterator::value_type*>(0)->i) value_type;
+ typedef typename PairIterator::difference_type difference_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+
+ IndexIterator(PairIterator pairIterator): mIterator(pairIterator) {}
+ IndexIterator& operator++() {++mIterator; return *this;}
+ const value_type operator*() const {return mIterator->i;}
+ difference_type operator-(const IndexIterator<PairIterator>& it) const {
+ return mIterator - it.mIterator;
+ }
+ bool operator==(const IndexIterator<PairIterator>& it) const {
+ return mIterator == it.mIterator;
+ }
+ bool operator!=(const IndexIterator<PairIterator>& it) const {
+ return mIterator != it.mIterator;
+ }
+
+ private:
+ PairIterator mIterator;
+ };
+}
+
+
+class ConcreteSigSPairQueue : public SigSPairQueue {
+public:
+ ConcreteSigSPairQueue(SigPolyBasis const& basis):
+ mPairQueue(Configuration(basis)) {}
+
+ virtual monomial popSignature(Pairs& pairs) {
+ pairs.clear();
+ if (mPairQueue.empty())
+ return 0;
+ monomial sig = ring().allocMonomial();
+ ring().monomialCopy(mPairQueue.topPairData(), sig);
+ do {
+ pairs.push_back(mPairQueue.topPair());
+ mPairQueue.pop();
+ } while
+ (!mPairQueue.empty() && ring().monomialEQ(mPairQueue.topPairData(), sig));
+ return sig;
+ }
+
+ virtual void pushPairs(size_t pairWith, IndexSigs& pairs) {
+#ifdef DEBUG
+ monomial tmp = ring().allocMonomial();
+ for (size_t i = 0; i < pairs.size(); ++i) {
+ MATHICGB_ASSERT(pairs[i].i < columnCount());
+ mPairQueue.configuration().computePairData
+ (columnCount(), pairs[i].i, tmp);
+ MATHICGB_ASSERT(ring().monomialEQ(tmp, pairs[i].signature));
+ }
+ ring().freeMonomial(tmp);
+#endif
+
+ if (columnCount() >= std::numeric_limits<BigIndex>::max())
+ throw std::overflow_error
+ ("Too large basis element index in constructing S-pairs.");
+
+ // sort and insert new column
+ Comparer cmp(ring().monoid());
+ std::sort(pairs.begin(), pairs.end(), cmp);
+ typedef IndexIterator<std::vector<PreSPair>::const_iterator> Iter;
+ mPairQueue.addColumnDescending(Iter(pairs.begin()), Iter(pairs.end()));
+
+ // free signatures
+ std::vector<PreSPair>::iterator end = pairs.end();
+ for (std::vector<PreSPair>::iterator it = pairs.begin(); it != end; ++it)
+ ring().freeMonomial(it->signature);
+ pairs.clear();
+ }
+
+ virtual std::string name() const {return "todo";}
+
+ virtual size_t memoryUse() const {return mPairQueue.getMemoryUse();}
+
+ virtual size_t pairCount() const {return mPairQueue.pairCount();}
+
+ virtual size_t columnCount() const {return mPairQueue.columnCount();}
+
+private:
+ ConcreteSigSPairQueue(const ConcreteSigSPairQueue&); // not available
+ void operator=(const ConcreteSigSPairQueue&); // not available
+
+ // Configuration of mathic::PairTriangle for use with signature queues.
+ class Configuration {
+ public:
+ Configuration(SigPolyBasis const& basis): mBasis(basis) {}
+
+ typedef monomial PairData;
+ void computePairData(size_t col, size_t row, monomial sig) {
+ MATHICGB_ASSERT(mBasis.ratioCompare(col, row) != EQ);
+ // ensure that ratio(col) > ratio(row)
+ if (mBasis.ratioCompare(col, row) == LT)
+ std::swap(col, row);
+ mBasis.ring().monomialFindSignature
+ (mBasis.getLeadMonomial(col),
+ mBasis.getLeadMonomial(row),
+ mBasis.getSignature(col), sig);
+ }
+
+ typedef bool CompareResult;
+ bool compare(int colA, int rowA, const_monomial a,
+ int colB, int rowB, const_monomial b) const {
+ return mBasis.ring().monoid().lessThan(b, a);
+ }
+ bool cmpLessThan(bool v) const {return v;}
+
+ SigPolyBasis const& basis() const {return mBasis;}
+
+ private:
+ SigPolyBasis const& mBasis;
+ };
+
+ // the compiler should be able to resolve these accessors into a direct
+ // offset as though these were member variables.
+ const SigPolyBasis& basis() const {
+ return mPairQueue.configuration().basis();
+ }
+ PolyRing const& ring() const {return basis().ring();}
+
+ mathic::PairQueue<Configuration> mPairQueue;
+ friend struct
+ mathic::PairQueueNamespace::ConstructPairDataFunction<Configuration>;
+ friend struct
+ mathic::PairQueueNamespace::DestructPairDataFunction<Configuration>;
+};
+
+std::unique_ptr<SigSPairQueue> SigSPairQueue::create(
+ SigPolyBasis const& basis
+) {
+ return make_unique<ConcreteSigSPairQueue>(basis);
+}
+
+MATHICGB_NAMESPACE_END
+
+namespace mathic {
+ namespace PairQueueNamespace {
+ template<>
+ struct ConstructPairDataFunction
+ <mgb::ConcreteSigSPairQueue::Configuration>
+ {
+ inline static void function(
+ void* memory,
+ Index col,
+ Index row,
+ mgb::ConcreteSigSPairQueue::Configuration& conf
+ ) {
+ MATHICGB_ASSERT(memory != 0);
+ MATHICGB_ASSERT(col > row);
+ auto pd = new (memory)
+ mgb::ConcreteSigSPairQueue::Configuration::PairData
+ (conf.basis().ring().allocMonomial());
+ conf.computePairData(col, row, *pd);
+ }
+ };
+
+ template<>
+ struct DestructPairDataFunction
+ <mgb::ConcreteSigSPairQueue::Configuration>
+ {
+ inline static void function(
+ mgb::ConcreteSigSPairQueue::Configuration::PairData* pd,
+ Index col,
+ Index row,
+ mgb::ConcreteSigSPairQueue::Configuration& conf
+ ) {
+ MATHICGB_ASSERT(pd != 0);
+ MATHICGB_ASSERT(col > row);
+ conf.basis().ring().freeMonomial(*pd);
+ }
+ };
+ }
+}
diff --git a/src/mathicgb/SignatureGB.cpp b/src/mathicgb/SignatureGB.cpp
index f123f36..a5ac65c 100755
--- a/src/mathicgb/SignatureGB.cpp
+++ b/src/mathicgb/SignatureGB.cpp
@@ -53,10 +53,10 @@ SignatureGB::SignatureGB(
mProcessor->setComponentCount(componentCount);
// Populate GB
- for (size_t j = 0; j < basis.size(); j++)
+ for (Component j = 0; j < componentCount; j++)
GB->addComponent();
- for (size_t i = 0; i < basis.size(); i++) {
+ for (Component i = 0; i < componentCount; i++) {
Poly *g = new Poly(*R);
basis.getPoly(i)->copy(*g);
g->makeMonic();
diff --git a/src/mathicgb/SparseMatrix.cpp b/src/mathicgb/SparseMatrix.cpp
index 6a2afb7..fb7824f 100755
--- a/src/mathicgb/SparseMatrix.cpp
+++ b/src/mathicgb/SparseMatrix.cpp
@@ -13,7 +13,7 @@ void SparseMatrix::takeRowsFrom(SparseMatrix&& matrix) {
return;
if (mRows.empty()) {
- *this = ::std::move(matrix);
+ *this = std::move(matrix);
return;
}
@@ -24,8 +24,8 @@ void SparseMatrix::takeRowsFrom(SparseMatrix&& matrix) {
if (mBlock.mHasNoRows) // only put mBlock in chain of blocks if non-empty
oldestBlock->mPreviousBlock = mBlock.mPreviousBlock;
else
- oldestBlock->mPreviousBlock = new Block(::std::move(mBlock));
- mBlock = ::std::move(matrix.mBlock);
+ oldestBlock->mPreviousBlock = new Block(std::move(mBlock));
+ mBlock = std::move(matrix.mBlock);
mRows.insert(mRows.end(), matrix.mRows.begin(), matrix.mRows.end());
matrix.clear();
@@ -33,7 +33,7 @@ void SparseMatrix::takeRowsFrom(SparseMatrix&& matrix) {
void SparseMatrix::rowToPolynomial(
const RowIndex row,
- const ::std::vector<monomial>& colMonomials,
+ const std::vector<monomial>& colMonomials,
Poly& poly
) {
poly.setToZero();
@@ -51,7 +51,7 @@ void SparseMatrix::sortRowsByIncreasingPivots() {
SparseMatrix ordered;
const auto rowCount = this->rowCount();
- ::std::vector<RowIndex> rows(rowCount);
+ std::vector<RowIndex> rows(rowCount);
for (RowIndex row = 0; row < rowCount; ++row)
rows[row] = row;
@@ -70,16 +70,16 @@ void SparseMatrix::sortRowsByIncreasingPivots() {
}
return aIt == aEnd && bIt != bEnd;
};
- ::std::sort(rows.begin(), rows.end(), lexLess);
+ std::sort(rows.begin(), rows.end(), lexLess);
// construct ordered with pivot columns in increasing order
ordered.clear();
for (size_t i = 0; i < rowCount; ++i)
ordered.appendRow(*this, rows[i]);
- *this = ::std::move(ordered);
+ *this = std::move(ordered);
}
-void SparseMatrix::applyColumnMap(const ::std::vector<ColIndex>& colMap) {
+void SparseMatrix::applyColumnMap(const std::vector<ColIndex>& colMap) {
MATHICGB_ASSERT(colMap.size() >= computeColCount());
Block* block = &mBlock;
for (; block != 0; block = block->mPreviousBlock) {
@@ -100,7 +100,7 @@ void SparseMatrix::multiplyRow(
it.setScalar(modularProduct(it.scalar(), multiplier, modulus));
}
-void SparseMatrix::print(::std::ostream& out) const {
+void SparseMatrix::print(std::ostream& out) const {
if (rowCount() == 0)
out << "matrix with no rows\n";
for (RowIndex row = 0; row < rowCount(); ++row) {
@@ -112,7 +112,7 @@ void SparseMatrix::print(::std::ostream& out) const {
}
}
-void SparseMatrix::printStatistics(::std::ostream& out) const {
+void SparseMatrix::printStatistics(std::ostream& out) const {
typedef mathic::ColumnPrinter ColPr;
ColPr pr;
@@ -143,8 +143,8 @@ void SparseMatrix::printStatistics(::std::ostream& out) const {
out << '\n' << pr << "\n";
}
-::std::string SparseMatrix::toString() const {
- ::std::ostringstream out;
+std::string SparseMatrix::toString() const {
+ std::ostringstream out;
print(out);
return out.str();
}
@@ -203,7 +203,7 @@ SparseMatrix& SparseMatrix::operator=(const SparseMatrix& matrix) {
void SparseMatrix::swap(SparseMatrix& matrix) {
mBlock.swap(matrix.mBlock);
- using ::std::swap;
+ using std::swap;
swap(mRows, matrix.mRows);
swap(mMemoryQuantum, matrix.mMemoryQuantum);
}
@@ -232,7 +232,7 @@ SparseMatrix::ColIndex SparseMatrix::computeColCount() const {
for (RowIndex row = 0; row < rowCount(); ++row) {
const auto end = rowEnd(row);
for (auto it = rowBegin(row); it != end; ++it)
- colCount = ::std::max(colCount, it.index() + 1);
+ colCount = std::max(colCount, it.index() + 1);
}
return colCount;
}
@@ -253,7 +253,7 @@ void SparseMatrix::clear() {
}
void SparseMatrix::appendRowWithModulus(
- ::std::vector<uint64> const& v,
+ std::vector<uint64> const& v,
const Scalar modulus
) {
const auto count = static_cast<ColIndex>(v.size());
@@ -266,7 +266,7 @@ void SparseMatrix::appendRowWithModulus(
}
void SparseMatrix::appendRowWithModulusNormalized(
- ::std::vector<uint64> const& v,
+ std::vector<uint64> const& v,
const Scalar modulus
) {
uint16 multiply = 1;
@@ -290,7 +290,7 @@ void SparseMatrix::appendRowWithModulusNormalized(
}
bool SparseMatrix::appendRowWithModulusIfNonZero(
- ::std::vector<uint64> const& v,
+ std::vector<uint64> const& v,
const Scalar modulus
) {
appendRowWithModulus(v, modulus);
@@ -321,12 +321,12 @@ void SparseMatrix::reserveFreeEntries(const size_t freeCount) {
const size_t count = freeCount + ( // todo: detect overflow for this addition
mBlock.mHasNoRows ?
mBlock.mColIndices.size() :
- ::std::distance(mRows.back().mIndicesEnd, mBlock.mColIndices.end())
+ std::distance(mRows.back().mIndicesEnd, mBlock.mColIndices.end())
);
// @todo: fix memory leaks on exception
- auto oldBlock = new Block(::std::move(mBlock));
+ auto oldBlock = new Block(std::move(mBlock));
MATHICGB_ASSERT(mBlock.mColIndices.begin() == 0);
MATHICGB_ASSERT(mBlock.mScalars.begin() == 0);
MATHICGB_ASSERT(mBlock.mHasNoRows);
@@ -360,9 +360,9 @@ void SparseMatrix::reserveFreeEntries(const size_t freeCount) {
// remove the pending entries from old block so that counting the number
// of entries will give the correct result in future.
oldBlock->mColIndices.resize
- (::std::distance(oldBlock->mColIndices.begin(), mRows.back().mIndicesEnd));
+ (std::distance(oldBlock->mColIndices.begin(), mRows.back().mIndicesEnd));
oldBlock->mScalars.resize
- (::std::distance(oldBlock->mScalars.begin(), mRows.back().mScalarsEnd));
+ (std::distance(oldBlock->mScalars.begin(), mRows.back().mScalarsEnd));
mBlock.mPreviousBlock = oldBlock;
}
}
@@ -427,7 +427,7 @@ size_t SparseMatrix::Block::memoryUseTrimmed() const {
return mColIndices.memoryUseTrimmed() + mScalars.memoryUseTrimmed();
}
-::std::ostream& operator<<(::std::ostream& out, const SparseMatrix& matrix) {
+std::ostream& operator<<(std::ostream& out, const SparseMatrix& matrix) {
matrix.print(out);
return out;
}
@@ -448,7 +448,7 @@ namespace {
}
template<class T>
- void writeMany(const ::std::vector<T>& v, FILE* file) {
+ void writeMany(const std::vector<T>& v, FILE* file) {
if (v.empty())
return;
if (fwrite(v.data(), sizeof(T), v.size(), file) != v.size())
@@ -456,7 +456,7 @@ namespace {
}
template<class T>
- void readMany(FILE* file, size_t count, ::std::vector<T>& v) {
+ void readMany(FILE* file, size_t count, std::vector<T>& v) {
size_t const originalSize = v.size();
v.resize(originalSize + count);
if (fread(v.data() + originalSize, sizeof(T), count, file) != count)
@@ -487,7 +487,7 @@ void SparseMatrix::write(const Scalar modulus, FILE* file) const {
mathic::reportError("error while writing to file.");
}
- ::std::vector<uint32> entryCounts;
+ std::vector<uint32> entryCounts;
for (SparseMatrix::RowIndex row = 0; row < storedRowCount; ++row)
entryCounts.push_back(entryCountInRow(row));
writeMany<uint32>(entryCounts, file);
@@ -512,22 +512,22 @@ SparseMatrix::Scalar SparseMatrix::read(FILE* file) {
// Read scalars.
{
mBlock.mScalars.resize(entryCount);
- ::std::vector<uint16> scalars;
+ std::vector<uint16> scalars;
readMany(file, entryCount, scalars);
- ::std::copy(scalars.begin(), scalars.end(), mBlock.mScalars.begin());
+ std::copy(scalars.begin(), scalars.end(), mBlock.mScalars.begin());
}
// Read column indices.
{
mBlock.mColIndices.resize(entryCount);
- ::std::vector<uint32> indices;
+ std::vector<uint32> indices;
readMany(file, entryCount, indices);
- ::std::copy(indices.begin(), indices.end(), mBlock.mColIndices.begin());
+ std::copy(indices.begin(), indices.end(), mBlock.mColIndices.begin());
}
// Read where rows begin and end.
{
- ::std::vector<uint32> sizes;
+ std::vector<uint32> sizes;
readMany(file, rowCount, sizes);
uint32 runningOffset = 0;
for (auto it = sizes.begin(); it != sizes.end(); ++it) {
@@ -555,7 +555,7 @@ void SparseMatrix::writePBM(FILE* file) {
// Write PBM header
{
- ::std::stringstream out;
+ std::stringstream out;
out << "P1 " << colCount << ' ' << rowCount << '\n';
fputs(out.str().c_str(), file);
}
diff --git a/src/mathicgb/SparseMatrix.hpp b/src/mathicgb/SparseMatrix.hpp
index 1ef19f6..beeea73 100755
--- a/src/mathicgb/SparseMatrix.hpp
+++ b/src/mathicgb/SparseMatrix.hpp
@@ -59,15 +59,15 @@ public:
{}
SparseMatrix(SparseMatrix&& matrix):
- mRows(::std::move(matrix.mRows)),
- mBlock(::std::move(matrix.mBlock)),
+ mRows(std::move(matrix.mRows)),
+ mBlock(std::move(matrix.mBlock)),
mMemoryQuantum(matrix.mMemoryQuantum)
{
}
SparseMatrix& operator=(SparseMatrix&& matrix) {
this->~SparseMatrix();
- new (this) SparseMatrix(::std::move(matrix));
+ new (this) SparseMatrix(std::move(matrix));
return *this;
}
@@ -159,11 +159,11 @@ public:
/// Prints the matrix in a human readable format to out.
/// Useful for debugging.
- void print(::std::ostream& out) const;
+ void print(std::ostream& out) const;
- void printStatistics(::std::ostream& out) const;
+ void printStatistics(std::ostream& out) const;
- ::std::string toString() const;
+ std::string toString() const;
/// Removes the leading trimThisMany columns. The columns are
/// removed by replacing all column indices col by col -
@@ -222,26 +222,26 @@ public:
void appendRow(const SparseMatrix& matrix, RowIndex row);
- void appendRowWithModulus(const ::std::vector<uint64>& v, Scalar modulus);
+ void appendRowWithModulus(const std::vector<uint64>& v, Scalar modulus);
template<class T>
- void appendRow(const ::std::vector<T>& v, ColIndex leadCol = 0);
+ void appendRow(const std::vector<T>& v, ColIndex leadCol = 0);
- void appendRowWithModulusNormalized(const ::std::vector<uint64>& v, Scalar modulus);
+ void appendRowWithModulusNormalized(const std::vector<uint64>& v, Scalar modulus);
// Returns true if the row was non-zero. Otherwise the row was not
// appended.
- bool appendRowWithModulusIfNonZero(const ::std::vector<uint64>& v, Scalar modulus);
+ bool appendRowWithModulusIfNonZero(const std::vector<uint64>& v, Scalar modulus);
/// Replaces all column indices i with colMap[i].
- void applyColumnMap(const ::std::vector<ColIndex>& colMap);
+ void applyColumnMap(const std::vector<ColIndex>& colMap);
void multiplyRow(RowIndex row, Scalar multiplier, Scalar modulus);
/// Let poly be the dot product of colMonomials and the given row.
void rowToPolynomial(
RowIndex row,
- const ::std::vector<monomial>& colMonomials,
+ const std::vector<monomial>& colMonomials,
Poly& poly);
/// Reorders the rows so that the index of the leading column in
@@ -262,12 +262,12 @@ public:
/// Iterates through the entries in a row.
class ConstRowIterator {
public:
- typedef const ::std::pair<ColIndex, Scalar> value_type;
+ typedef const std::pair<ColIndex, Scalar> value_type;
typedef ptrdiff_t difference_type;
typedef size_t distance_type;
typedef value_type* pointer;
typedef value_type& reference;
- typedef ::std::random_access_iterator_tag iterator_category;
+ typedef std::random_access_iterator_tag iterator_category;
ConstRowIterator& operator++() {
++mScalarIt;
@@ -317,12 +317,12 @@ public:
/// Iterates through the entries in a row.
class RowIterator {
public:
- typedef const ::std::pair<ColIndex, Scalar> value_type;
+ typedef const std::pair<ColIndex, Scalar> value_type;
typedef ptrdiff_t difference_type;
typedef size_t distance_type;
typedef value_type* pointer;
typedef value_type& reference;
- typedef ::std::random_access_iterator_tag iterator_category;
+ typedef std::random_access_iterator_tag iterator_category;
RowIterator& operator++() {
++mScalarIt;
@@ -388,20 +388,20 @@ private:
bool empty() const {return mIndicesBegin == mIndicesEnd;}
ColIndex size() const {
- return static_cast<ColIndex>(::std::distance(mIndicesBegin, mIndicesEnd));
+ return static_cast<ColIndex>(std::distance(mIndicesBegin, mIndicesEnd));
}
};
- ::std::vector<Row> mRows;
+ std::vector<Row> mRows;
/// Memory is allocated a block at a time. This avoids the need for copying
- /// that a ::std::vector normally does on reallocation. Believe it or not,
+ /// that a std::vector normally does on reallocation. Believe it or not,
/// copying sparse matrix memory due to reallocation was accounting for 5%
/// of the running time before this change.
struct Block {
Block(): mPreviousBlock(0), mHasNoRows(true) {}
Block(Block&& block):
- mColIndices(::std::move(block.mColIndices)),
- mScalars(::std::move(block.mScalars)),
+ mColIndices(std::move(block.mColIndices)),
+ mScalars(std::move(block.mScalars)),
mPreviousBlock(block.mPreviousBlock),
mHasNoRows(block.mHasNoRows)
{
@@ -410,15 +410,15 @@ private:
}
void swap(Block& block) {
- ::std::swap(mColIndices, block.mColIndices);
- ::std::swap(mScalars, block.mScalars);
- ::std::swap(mPreviousBlock, block.mPreviousBlock);
- ::std::swap(mHasNoRows, block.mHasNoRows);
+ std::swap(mColIndices, block.mColIndices);
+ std::swap(mScalars, block.mScalars);
+ std::swap(mPreviousBlock, block.mPreviousBlock);
+ std::swap(mHasNoRows, block.mHasNoRows);
}
Block& operator=(Block&& block) {
this->~Block();
- new (this) Block(::std::move(block));
+ new (this) Block(std::move(block));
return *this;
}
@@ -441,7 +441,7 @@ private:
template<class T>
void SparseMatrix::appendRow(
- ::std::vector<T> const& v,
+ std::vector<T> const& v,
const ColIndex leadCol
) {
#ifdef MATHICGB_DEBUG
@@ -452,7 +452,7 @@ void SparseMatrix::appendRow(
const auto count = static_cast<ColIndex>(v.size());
for (ColIndex col = leadCol; col < count; ++col) {
- MATHICGB_ASSERT(v[col] < ::std::numeric_limits<Scalar>::max());
+ MATHICGB_ASSERT(v[col] < std::numeric_limits<Scalar>::max());
if (v[col] != 0)
appendEntry(col, static_cast<Scalar>(v[col]));
}
@@ -464,7 +464,7 @@ inline void swap(SparseMatrix& a, SparseMatrix& b) {
a.swap(b);
}
-::std::ostream& operator<<(::std::ostream& out, const SparseMatrix& matrix);
+std::ostream& operator<<(std::ostream& out, const SparseMatrix& matrix);
MATHICGB_NAMESPACE_END
#endif
diff --git a/src/mathicgb/io-util.cpp b/src/mathicgb/io-util.cpp
index cb3d77e..053bd49 100755
--- a/src/mathicgb/io-util.cpp
+++ b/src/mathicgb/io-util.cpp
@@ -22,114 +22,114 @@
MATHICGB_NAMESPACE_BEGIN
-::std::unique_ptr<Poly> polyParseFromString(const PolyRing *R, const ::std::string &s)
+std::unique_ptr<Poly> polyParseFromString(const PolyRing *R, const std::string &s)
{
- ::std::unique_ptr<Poly> f(new Poly(*R));
- ::std::istringstream in(s);
+ std::unique_ptr<Poly> f(new Poly(*R));
+ std::istringstream in(s);
f->parse(in);
return f;
}
-::std::string toString(const Poly *g)
+std::string toString(const Poly *g)
{
- ::std::ostringstream o;
+ std::ostringstream o;
g->display(o);
return o.str();
}
-::std::unique_ptr<Basis> basisParseFromString(::std::string str)
+std::unique_ptr<Basis> basisParseFromString(std::string str)
{
- ::std::istringstream inStream(str);
+ std::istringstream inStream(str);
Scanner in(inStream);
auto p = MathicIO().readRing(true, in);
auto& ring = *p.first.release(); // todo: fix leak
return make_unique<Basis>(MathicIO().readBasis(ring, false, in));
}
-::std::unique_ptr<PolyRing> ringFromString(::std::string ringinfo)
+std::unique_ptr<PolyRing> ringFromString(std::string ringinfo)
{
- ::std::stringstream ifil(ringinfo);
- return ::std::unique_ptr<PolyRing>(PolyRing::read(ifil).first);
+ std::stringstream ifil(ringinfo);
+ return std::unique_ptr<PolyRing>(PolyRing::read(ifil).first);
}
-Monomial stringToMonomial(const PolyRing *R, ::std::string mon)
+Monomial stringToMonomial(const PolyRing *R, std::string mon)
{
Monomial result = R->allocMonomial();
- ::std::stringstream ifil(mon);
+ std::stringstream ifil(mon);
R->monomialParse(ifil, result);
return result;
}
-::std::string monomialToString(const PolyRing *R, const Monomial& mon)
+std::string monomialToString(const PolyRing *R, const Monomial& mon)
{
- ::std::ostringstream o;
+ std::ostringstream o;
R->monomialDisplay(o,mon);
return o.str();
}
-monomial monomialParseFromString(const PolyRing *R, ::std::string mon)
+monomial monomialParseFromString(const PolyRing *R, std::string mon)
{
// This is poor code, to only be used for testing!
monomial result = R->allocMonomial();
- ::std::stringstream ifil(mon);
+ std::stringstream ifil(mon);
R->monomialParse(ifil, result);
return result;
}
-::std::string monomialDisplay(const PolyRing *R, const_monomial mon)
+std::string monomialDisplay(const PolyRing *R, const_monomial mon)
{
- ::std::ostringstream o;
+ std::ostringstream o;
R->monomialDisplay(o,mon);
return o.str();
}
////////////////////////////////////////////////////////////////
-::std::string toString(SigPolyBasis *I)
+std::string toString(SigPolyBasis *I)
{
- ::std::ostringstream o;
+ std::ostringstream o;
for (size_t i=0; i<I->size(); i++)
{
o << " ";
I->poly(i).display(o, false);
- o << ::std::endl;
+ o << std::endl;
}
return o.str();
}
-::std::string toString(SigPolyBasis *I, int)
+std::string toString(SigPolyBasis *I, int)
{
- ::std::ostringstream o;
+ std::ostringstream o;
I->display(o);
return o.str();
}
-::std::string toString(MonomialTableArray* H)
+std::string toString(MonomialTableArray* H)
{
- ::std::ostringstream o;
+ std::ostringstream o;
H->display(o, 1);
return o.str();
}
-::std::string toString(Basis *I)
+std::string toString(Basis *I)
{
- ::std::ostringstream o;
+ std::ostringstream o;
for (size_t i=0; i<I->size(); i++)
{
o << " ";
I->getPoly(i)->display(o,false);
- o << ::std::endl;
+ o << std::endl;
}
return o.str();
}
-void output(::std::ostream &o, const PolyBasis &I)
+void output(std::ostream &o, const PolyBasis &I)
{
for (size_t i = 0; i < I.size(); i++)
{
if (!I.retired(i))
{
I.poly(i).display(o, false);
- o << ::std::endl;
+ o << std::endl;
}
}
}
diff --git a/src/mathicgb/io-util.hpp b/src/mathicgb/io-util.hpp
index 7d62859..7410331 100755
--- a/src/mathicgb/io-util.hpp
+++ b/src/mathicgb/io-util.hpp
@@ -13,26 +13,26 @@ class MonomialTableArray;
class PolyBasis;
class Basis;
-::std::unique_ptr<PolyRing> ringFromString(::std::string ringinfo);
-monomial monomialFromString(const PolyRing *R, ::std::string mon);
-monomial monomialParseFromString(const PolyRing *R, ::std::string mon);
-::std::string monomialToString(const PolyRing *R, const_monomial mon);
-::std::string monomialDisplay(const PolyRing *R, const_monomial mon);
-
-Monomial stringToMonomial(const PolyRing *R, ::std::string mon);
-::std::string monomialToString(const PolyRing *R, const Monomial& mon);
-
-::std::string toString(SigPolyBasis *);
-::std::string toString(MonomialTableArray *);
-::std::string toString(SigPolyBasis *, int unused); // also displays signature
-::std::string toString(Basis *);
-::std::string toString(const Poly *);
-
-::std::unique_ptr<Basis> basisParseFromString(::std::string str);
-::std::unique_ptr<Poly> polyParseFromString
- (const PolyRing *R, const ::std::string &s);
-
-void output(::std::ostream &o, const PolyBasis &I);
+std::unique_ptr<PolyRing> ringFromString(std::string ringinfo);
+monomial monomialFromString(const PolyRing *R, std::string mon);
+monomial monomialParseFromString(const PolyRing *R, std::string mon);
+std::string monomialToString(const PolyRing *R, const_monomial mon);
+std::string monomialDisplay(const PolyRing *R, const_monomial mon);
+
+Monomial stringToMonomial(const PolyRing *R, std::string mon);
+std::string monomialToString(const PolyRing *R, const Monomial& mon);
+
+std::string toString(SigPolyBasis *);
+std::string toString(MonomialTableArray *);
+std::string toString(SigPolyBasis *, int unused); // also displays signature
+std::string toString(Basis *);
+std::string toString(const Poly *);
+
+std::unique_ptr<Basis> basisParseFromString(std::string str);
+std::unique_ptr<Poly> polyParseFromString
+ (const PolyRing *R, const std::string &s);
+
+void output(std::ostream &o, const PolyBasis &I);
void output(FILE* file, const PolyBasis &I);
MATHICGB_NAMESPACE_END
diff --git a/src/mathicgb/mtbb.hpp b/src/mathicgb/mtbb.hpp
index 93cdb59..1d28006 100755
--- a/src/mathicgb/mtbb.hpp
+++ b/src/mathicgb/mtbb.hpp
@@ -3,13 +3,12 @@
#ifndef MATHICGB_M_TBB_GUARD
#define MATHICGB_M_TBB_GUARD
-#define MATHICGB_NO_TBB
#ifndef MATHICGB_NO_TBB
#include <tbb/tbb.h>
MATHICGB_NAMESPACE_BEGIN
-namespace tbb {
+namespace mtbb {
using ::tbb::task_scheduler_init;
using ::tbb::mutex;
using ::tbb::parallel_do_feeder;
@@ -32,7 +31,7 @@ MATHICGB_NAMESPACE_END
MATHICGB_NAMESPACE_BEGIN
-namespace tbb {
+namespace mtbb {
class task_scheduler_init {
public:
task_scheduler_init(int) {}
@@ -130,8 +129,8 @@ namespace tbb {
}
private:
- ::std::function<T()> mCreater;
- ::std::unique_ptr<T> mObj;
+ std::function<T()> mCreater;
+ std::unique_ptr<T> mObj;
};
template<class Value>
@@ -171,24 +170,24 @@ namespace tbb {
template<class T>
class parallel_do_feeder {
public:
- parallel_do_feeder(::std::vector<T>& tasks): mTasks(tasks) {}
+ parallel_do_feeder(std::vector<T>& tasks): mTasks(tasks) {}
template<class TT>
- void add(TT&& t) {mTasks.push_back(::std::forward<TT>(t));}
+ void add(TT&& t) {mTasks.push_back(std::forward<TT>(t));}
private:
- ::std::vector<T>& mTasks;
+ std::vector<T>& mTasks;
};
template<class InputIterator, class Body>
void parallel_do(InputIterator begin, InputIterator end, Body body) {
- typedef typename ::std::remove_reference<decltype(*begin)>::type Task;
- ::std::vector<Task> tasks;
+ typedef typename std::remove_reference<decltype(*begin)>::type Task;
+ std::vector<Task> tasks;
parallel_do_feeder<Task> feeder(tasks);
for (; begin != end; ++begin) {
tasks.push_back(*begin);
while (!tasks.empty()) {
- auto task = ::std::move(tasks.back());
+ auto task = std::move(tasks.back());
tasks.pop_back();
body(task, feeder);
}
@@ -197,14 +196,14 @@ namespace tbb {
template<class It, class Pred>
void parallel_sort(It begin, It end, Pred&& pred) {
- ::std::sort(begin, end, pred);
+ std::sort(begin, end, pred);
}
class tick_count {
private:
- // This really should be ::std::chrono::steady_clock, but GCC 4.5.3 doesn't
+ // This really should be std::chrono::steady_clock, but GCC 4.5.3 doesn't
// have that.
- typedef ::std::chrono::system_clock clock;
+ typedef std::chrono::system_clock clock;
public:
tick_count(): mTime() {}
@@ -226,9 +225,9 @@ namespace tbb {
};
interval_t operator-(const tick_count t) const {
- typedef ::std::chrono::duration<double> SecondDuration;
+ typedef std::chrono::duration<double> SecondDuration;
const auto duration =
- ::std::chrono::duration_cast<SecondDuration>(mTime - t.mTime);
+ std::chrono::duration_cast<SecondDuration>(mTime - t.mTime);
return duration.count();
}
diff --git a/src/mathicgb/stdinc.h b/src/mathicgb/stdinc.h
index f9afba8..91812ff 100755
--- a/src/mathicgb/stdinc.h
+++ b/src/mathicgb/stdinc.h
@@ -47,7 +47,7 @@
/// does not alias any other pointer that is used in the current scope.
#define MATHICGB_RESTRICT __restrict
-#pragma warning (disable: 4996) // ::std::copy on pointers is flagged as dangerous
+#pragma warning (disable: 4996) // std::copy on pointers is flagged as dangerous
#pragma warning (disable: 4290) // VC++ ignores throw () specification.
#pragma warning (disable: 4127) // Warns about using "while (true)".
#pragma warning (disable: 4100) // Warns about unused parameters.
@@ -61,7 +61,7 @@
#pragma warning (disable: 4355)
// Tells Windows.h/Windef.h not to define macroes called min and max since that
-// clashes with ::std::numeric_limits::max and ::std::max and probably lots of
+// clashes with std::numeric_limits::max and std::max and probably lots of
// other things too.
#define NOMINMAX
@@ -176,9 +176,9 @@ See http://herbsutter.com/gotw/_102/ for a reason to have a
make_unique function. It's pretty easy to do, too:
template<typename T, typename ...Args>
-::std::unique_ptr<T> make_unique( Args&& ...args )
+std::unique_ptr<T> make_unique( Args&& ...args )
{
- return ::std::unique_ptr<T>( new T( ::std::forward<Args>(args)... ) );
+ return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
}
Unfortunately, MSVC does not have variadic templates, so this turns
@@ -191,92 +191,92 @@ parameters.
MATHICGB_NAMESPACE_BEGIN
template<class T>
-::std::unique_ptr<T> make_unique() {
- return ::std::unique_ptr<T>(new T());
+std::unique_ptr<T> make_unique() {
+ return std::unique_ptr<T>(new T());
}
template<class T, class A1>
-::std::unique_ptr<T> make_unique(A1&& a1) {
- return ::std::unique_ptr<T>(new T(::std::forward<A1>(a1)));
+std::unique_ptr<T> make_unique(A1&& a1) {
+ return std::unique_ptr<T>(new T(std::forward<A1>(a1)));
}
template<class T, class A1, class A2>
-::std::unique_ptr<T> make_unique(A1&& a1, A2&& a2) {
- return ::std::unique_ptr<T>(new T(::std::forward<A1>(a1), ::std::forward<A2>(a2)));
+std::unique_ptr<T> make_unique(A1&& a1, A2&& a2) {
+ return std::unique_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2)));
}
template<class T, class A1, class A2, class A3>
-::std::unique_ptr<T> make_unique(A1&& a1, A2&& a2, A3&& a3) {
- return ::std::unique_ptr<T>
- (new T(::std::forward<A1>(a1), ::std::forward<A2>(a2), ::std::forward<A3>(a3)));
+std::unique_ptr<T> make_unique(A1&& a1, A2&& a2, A3&& a3) {
+ return std::unique_ptr<T>
+ (new T(std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3)));
}
template<class T, class A1, class A2, class A3, class A4>
- ::std::unique_ptr<T> make_unique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) {
- return ::std::unique_ptr<T>
- (new T(::std::forward<A1>(a1), ::std::forward<A2>(a2),
- ::std::forward<A3>(a3), ::std::forward<A4>(a4)));
+ std::unique_ptr<T> make_unique(A1&& a1, A2&& a2, A3&& a3, A4&& a4) {
+ return std::unique_ptr<T>
+ (new T(std::forward<A1>(a1), std::forward<A2>(a2),
+ std::forward<A3>(a3), std::forward<A4>(a4)));
}
template<class T, class A1, class A2, class A3, class A4, class A5>
- ::std::unique_ptr<T> make_unique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) {
- return ::std::unique_ptr<T>
- (new T(::std::forward<A1>(a1), ::std::forward<A2>(a2),
- ::std::forward<A3>(a3), ::std::forward<A4>(a4),
- ::std::forward<A5>(a5)));
+ std::unique_ptr<T> make_unique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5) {
+ return std::unique_ptr<T>
+ (new T(std::forward<A1>(a1), std::forward<A2>(a2),
+ std::forward<A3>(a3), std::forward<A4>(a4),
+ std::forward<A5>(a5)));
}
template<class T, class A1, class A2, class A3, class A4, class A5, class A6>
- ::std::unique_ptr<T> make_unique
+ std::unique_ptr<T> make_unique
(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6) {
- return ::std::unique_ptr<T>
- (new T(::std::forward<A1>(a1), ::std::forward<A2>(a2),
- ::std::forward<A3>(a3), ::std::forward<A4>(a4),
- ::std::forward<A5>(a5), ::std::forward<A6>(a6)));
+ return std::unique_ptr<T>
+ (new T(std::forward<A1>(a1), std::forward<A2>(a2),
+ std::forward<A3>(a3), std::forward<A4>(a4),
+ std::forward<A5>(a5), std::forward<A6>(a6)));
}
template<class T, class A1, class A2, class A3, class A4, class A5, class A6,
class A7>
- ::std::unique_ptr<T> make_unique
+ std::unique_ptr<T> make_unique
(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, A7&& a7) {
- return ::std::unique_ptr<T>
- (new T(::std::forward<A1>(a1), ::std::forward<A2>(a2),
- ::std::forward<A3>(a3), ::std::forward<A4>(a4),
- ::std::forward<A5>(a5), ::std::forward<A6>(a6),
- ::std::forward<A7>(a7)));
+ return std::unique_ptr<T>
+ (new T(std::forward<A1>(a1), std::forward<A2>(a2),
+ std::forward<A3>(a3), std::forward<A4>(a4),
+ std::forward<A5>(a5), std::forward<A6>(a6),
+ std::forward<A7>(a7)));
}
template<class T, class A1, class A2, class A3, class A4, class A5, class A6,
class A7, class A8>
- ::std::unique_ptr<T> make_unique
+ std::unique_ptr<T> make_unique
(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, A7&& a7,
A8&& a8) {
- return ::std::unique_ptr<T>
- (new T(::std::forward<A1>(a1), ::std::forward<A2>(a2),
- ::std::forward<A3>(a3), ::std::forward<A4>(a4),
- ::std::forward<A5>(a5), ::std::forward<A6>(a6),
- ::std::forward<A7>(a7), ::std::forward<A8>(a8)));
+ return std::unique_ptr<T>
+ (new T(std::forward<A1>(a1), std::forward<A2>(a2),
+ std::forward<A3>(a3), std::forward<A4>(a4),
+ std::forward<A5>(a5), std::forward<A6>(a6),
+ std::forward<A7>(a7), std::forward<A8>(a8)));
}
template<class T, class A1, class A2, class A3, class A4, class A5, class A6,
class A7, class A8, class A9>
- ::std::unique_ptr<T> make_unique
+ std::unique_ptr<T> make_unique
(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, A7&& a7,
A8&& a8, A9&& a9) {
- return ::std::unique_ptr<T>
- (new T(::std::forward<A1>(a1), ::std::forward<A2>(a2),
- ::std::forward<A3>(a3), ::std::forward<A4>(a4),
- ::std::forward<A5>(a5), ::std::forward<A6>(a6),
- ::std::forward<A7>(a7), ::std::forward<A8>(a8),
- ::std::forward<A9>(a9)));
+ return std::unique_ptr<T>
+ (new T(std::forward<A1>(a1), std::forward<A2>(a2),
+ std::forward<A3>(a3), std::forward<A4>(a4),
+ std::forward<A5>(a5), std::forward<A6>(a6),
+ std::forward<A7>(a7), std::forward<A8>(a8),
+ std::forward<A9>(a9)));
}
template<class T, class A1, class A2, class A3, class A4, class A5, class A6,
class A7, class A8, class A9, class A10>
- ::std::unique_ptr<T> make_unique
+ std::unique_ptr<T> make_unique
(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, A7&& a7,
A8&& a8, A9&& a9, A10&& a10) {
- return ::std::unique_ptr<T>
- (new T(::std::forward<A1>(a1), ::std::forward<A2>(a2),
- ::std::forward<A3>(a3), ::std::forward<A4>(a4),
- ::std::forward<A5>(a5), ::std::forward<A6>(a6),
- ::std::forward<A7>(a7), ::std::forward<A8>(a8),
- ::std::forward<A9>(a9), ::std::forward<A9>(a10)));
+ return std::unique_ptr<T>
+ (new T(std::forward<A1>(a1), std::forward<A2>(a2),
+ std::forward<A3>(a3), std::forward<A4>(a4),
+ std::forward<A5>(a5), std::forward<A6>(a6),
+ std::forward<A7>(a7), std::forward<A8>(a8),
+ std::forward<A9>(a9), std::forward<A9>(a10)));
}
template<class T>
-::std::unique_ptr<T[]> make_unique_array(size_t count) {
- return ::std::unique_ptr<T[]>(new T[count]);
+std::unique_ptr<T[]> make_unique_array(size_t count) {
+ return std::unique_ptr<T[]>(new T[count]);
}
// TODO: These types should be defined in some way that actually
diff --git a/src/test/F4MatrixBuilder.cpp b/src/test/F4MatrixBuilder.cpp
index 549f7e4..ebe7771 100755
--- a/src/test/F4MatrixBuilder.cpp
+++ b/src/test/F4MatrixBuilder.cpp
@@ -28,11 +28,11 @@ namespace {
mBasis(*mRing, DivisorLookup::makeFactory(*mRing, 1)->create(true, true)) {
}
- const Poly& addBasisElement(const ::std::string& str) {
- ::std::unique_ptr<Poly> p(new Poly(*mRing));
- ::std::istringstream in(str);
+ const Poly& addBasisElement(const std::string& str) {
+ std::unique_ptr<Poly> p(new Poly(*mRing));
+ std::istringstream in(str);
p->parse(in);
- mBasis.insert(::std::move(p));
+ mBasis.insert(std::move(p));
return mBasis.poly(mBasis.size() - 1);
}
@@ -45,16 +45,16 @@ namespace {
const PolyRing& ring() const {return *mRing;}
private:
- ::std::unique_ptr<PolyRing> mRing;
+ std::unique_ptr<PolyRing> mRing;
Basis mIdeal;
PolyBasis mBasis;
- ::std::unique_ptr<F4MatrixBuilder> mBuilder;
+ std::unique_ptr<F4MatrixBuilder> mBuilder;
};
}
TEST(F4MatrixBuilder, Empty) {
for (int threadCount = 1; threadCount < 4; ++threadCount) {
- mgb::tbb::task_scheduler_init scheduler(threadCount);
+ mgb::mtbb::task_scheduler_init scheduler(threadCount);
BuilderMaker maker;
F4MatrixBuilder& builder = maker.create();
@@ -71,7 +71,7 @@ TEST(F4MatrixBuilder, Empty) {
TEST(F4MatrixBuilder, SPair) {
for (int threadCount = 1; threadCount < 4; ++threadCount) {
- mgb::tbb::task_scheduler_init scheduler(threadCount);
+ mgb::mtbb::task_scheduler_init scheduler(threadCount);
BuilderMaker maker;
const Poly& p1 = maker.addBasisElement("a4c2-d");
const Poly& p2 = maker.addBasisElement("a4b+d");
@@ -93,7 +93,7 @@ TEST(F4MatrixBuilder, SPair) {
"0: 0#1 | 0: 0#1\n"
" | \n"
"0: 0#1 | 0: 1#3\n";
- ::std::string qmStr = qm.toString();
+ std::string qmStr = qm.toString();
ASSERT_TRUE(str1 == qmStr || str2 == qmStr) <<
"\n** str1: " << str1 << "\n** qm: " << qmStr;
}
@@ -101,7 +101,7 @@ TEST(F4MatrixBuilder, SPair) {
TEST(F4MatrixBuilder, OneByOne) {
for (int threadCount = 1; threadCount < 4; ++threadCount) {
- mgb::tbb::task_scheduler_init scheduler(threadCount);
+ mgb::mtbb::task_scheduler_init scheduler(threadCount);
BuilderMaker maker;
const Poly& p = maker.addBasisElement("a");
F4MatrixBuilder& builder = maker.create();
@@ -129,14 +129,14 @@ TEST(F4MatrixBuilder, DirectReducers) {
Poly p1(builder.ring());
{
- ::std::istringstream in("a3<0>+b2+c+d");
+ std::istringstream in("a3<0>+b2+c+d");
p1.parse(in);
builder.addPolynomialToMatrix(p1.getLeadMonomial(), p1);
}
Poly p2(builder.ring());
{
- ::std::istringstream in("a3<0>+2b2+3c+4d");
+ std::istringstream in("a3<0>+2b2+3c+4d");
p2.parse(in);
builder.addPolynomialToMatrix(p2.getLeadMonomial(), p2);
}
diff --git a/src/test/F4MatrixReducer.cpp b/src/test/F4MatrixReducer.cpp
index abf27ea..a5bd60c 100755
--- a/src/test/F4MatrixReducer.cpp
+++ b/src/test/F4MatrixReducer.cpp
@@ -19,7 +19,7 @@ TEST(F4MatrixReducer, Reduce) {
m.ring = ring.get();
Poly p(*ring);
- ::std::istringstream in("a4+a3+a2+a1+b5+b4+b3+b2+b1");
+ std::istringstream in("a4+a3+a2+a1+b5+b4+b3+b2+b1");
p.parse(in);
size_t count = 0;
for (Poly::iterator it = p.begin(); it != p.end(); ++it) {
diff --git a/src/test/MonoMonoid.cpp b/src/test/MonoMonoid.cpp
index 6b18cd2..d6fbde6 100755
--- a/src/test/MonoMonoid.cpp
+++ b/src/test/MonoMonoid.cpp
@@ -641,8 +641,11 @@ TYPED_TEST(Monoid, Order) {
-6, 9, 4,
-6, 9, 4
};
- std::vector<Exponent> dupGradings
- (std::begin(dupGradingsArray), std::end(dupGradingsArray));
+ std::vector<Exponent> dupGradings(
+ dupGradingsArray,
+ dupGradingsArray + sizeof(dupGradingsArray)/sizeof(*dupGradingsArray)
+ );
+
// b: 2 9
// c: 3 4
// a: 5 -7
@@ -662,8 +665,10 @@ TYPED_TEST(Monoid, Order) {
0, 1, 0,
1, 0, 0
};
- std::vector<Exponent> lexGradings
- (std::begin(lexGradingsArray), std::end(lexGradingsArray));
+ std::vector<Exponent> lexGradings(
+ lexGradingsArray,
+ lexGradingsArray + sizeof(lexGradingsArray)/sizeof(*lexGradingsArray)
+ );
const auto sortedLex =
"1 a a2 a3 b ab a2b b2 ab2 b3 c ac bc abc c2 ac2 bc2 c3";
check(
diff --git a/src/test/QuadMatrixBuilder.cpp b/src/test/QuadMatrixBuilder.cpp
index 735a489..fdc2aac 100755
--- a/src/test/QuadMatrixBuilder.cpp
+++ b/src/test/QuadMatrixBuilder.cpp
@@ -13,8 +13,8 @@
using namespace mgb;
namespace {
- ::std::string monToStr(const PolyRing& ring, ConstMonomial a) {
- ::std::ostringstream out;
+ std::string monToStr(const PolyRing& ring, ConstMonomial a) {
+ std::ostringstream out;
ring.monomialDisplay(out, a, false, true);
return out.str();
}
@@ -24,7 +24,7 @@ namespace {
const PolyRing& ring = b.ring();
{
Poly p(b.ring());
- ::std::istringstream in(left);
+ std::istringstream in(left);
p.parseDoNotOrder(in);
size_t colCount = 0;
for (Poly::iterator it = p.begin(); it != p.end(); ++it) {
@@ -40,7 +40,7 @@ namespace {
}
{
Poly p(b.ring());
- ::std::istringstream in(right);
+ std::istringstream in(right);
p.parseDoNotOrder(in);
size_t colCount = 0;
for (Poly::iterator it = p.begin(); it != p.end(); ++it) {
@@ -77,7 +77,7 @@ TEST(QuadMatrixBuilder, Empty) {
}
TEST(QuadMatrixBuilder, Construction) {
- ::std::unique_ptr<PolyRing> ring(ringFromString("32003 6 1\n1 1 1 1 1 1"));
+ std::unique_ptr<PolyRing> ring(ringFromString("32003 6 1\n1 1 1 1 1 1"));
QuadMatrixBuilder::Map map(*ring);
QuadMatrixBuilder::MonomialsType monoLeft;
QuadMatrixBuilder::MonomialsType monoRight;
@@ -120,7 +120,7 @@ TEST(QuadMatrixBuilder, Construction) {
}
TEST(QuadMatrixBuilder, ColumnQuery) {
- ::std::unique_ptr<PolyRing> ring(ringFromString("32003 6 1\n1 1 1 1 1 1"));
+ std::unique_ptr<PolyRing> ring(ringFromString("32003 6 1\n1 1 1 1 1 1"));
QuadMatrixBuilder::Map map(*ring);
QuadMatrixBuilder::MonomialsType monoLeft;
QuadMatrixBuilder::MonomialsType monoRight;
@@ -129,7 +129,7 @@ TEST(QuadMatrixBuilder, ColumnQuery) {
Poly p(b.ring());
// coefficient 1X=left, 2X=right, 30=not there, % 10 = column index
- ::std::istringstream in
+ std::istringstream in
("10a<1>+11<0>+20b<0>+21c<0>+22bc<0>+30ab<0>+30e<0>+10a<1>");
p.parseDoNotOrder(in);
for (Poly::iterator it = p.begin(); it != p.end(); ++it) {
@@ -150,7 +150,7 @@ TEST(QuadMatrixBuilder, ColumnQuery) {
TEST(QuadMatrixBuilder, SortColumns) {
// construct builder and reverse lex order
- ::std::unique_ptr<PolyRing> ring(ringFromString("32003 6 1\n1 1 1 1 1 1"));
+ std::unique_ptr<PolyRing> ring(ringFromString("32003 6 1\n1 1 1 1 1 1"));
Basis basis(*ring);
// one row top, no rows bottom, no columns
@@ -217,7 +217,7 @@ TEST(QuadMatrixBuilder, SortColumns) {
}
TEST(QuadMatrixBuilder, BuildAndClear) {
- ::std::unique_ptr<PolyRing> ring(ringFromString("32003 6 1\n1 1 1 1 1 1"));
+ std::unique_ptr<PolyRing> ring(ringFromString("32003 6 1\n1 1 1 1 1 1"));
QuadMatrixBuilder::Map map(*ring);
QuadMatrixBuilder::MonomialsType monoLeft;
QuadMatrixBuilder::MonomialsType monoRight;
diff --git a/src/test/SparseMatrix.cpp b/src/test/SparseMatrix.cpp
index d07eb54..23e3ef1 100755
--- a/src/test/SparseMatrix.cpp
+++ b/src/test/SparseMatrix.cpp
@@ -13,9 +13,9 @@
using namespace mgb;
namespace {
- ::std::unique_ptr<Poly> parsePoly(const PolyRing& ring, ::std::string str) {
+ std::unique_ptr<Poly> parsePoly(const PolyRing& ring, std::string str) {
auto p = make_unique<Poly>(ring);
- ::std::istringstream in(str);
+ std::istringstream in(str);
p->parse(in);
return p;
}
@@ -66,7 +66,7 @@ TEST(SparseMatrix, Simple) {
TEST(SparseMatrix, toRow) {
auto ring = ringFromString("32003 6 1\n1 1 1 1 1 1");
auto polyForMonomials = parsePoly(*ring, "a5+a4+a3+a2+a1+a0");
- ::std::vector<monomial> monomials;
+ std::vector<monomial> monomials;
for (auto it = polyForMonomials->begin(); it != polyForMonomials->end(); ++it)
monomials.push_back(it.getMonomial());
diff --git a/src/test/gb-test.cpp b/src/test/gb-test.cpp
index 8285b4b..cd5ce93 100755
--- a/src/test/gb-test.cpp
+++ b/src/test/gb-test.cpp
@@ -302,7 +302,7 @@ spairQueue reducerType divLookup monTable buchberger postponeKoszul useBaseDivis
MATHICGB_ASSERT(Reducer::makeReducerNullOnUnknown(red, ring).get() != 0);
- mgb::tbb::task_scheduler_init scheduler(threadCount);
+ mgb::mtbb::task_scheduler_init scheduler(threadCount);
if (buchberger) {
const auto reducer = Reducer::makeReducer
(Reducer::reducerType(reducerType), ring);
diff --git a/src/test/mathicgb.cpp b/src/test/mathicgb.cpp
index f90948d..bad52fd 100755
--- a/src/test/mathicgb.cpp
+++ b/src/test/mathicgb.cpp
@@ -1,598 +1,598 @@
-// MathicGB copyright 2012 all rights reserved. MathicGB comes with ABSOLUTELY
-// NO WARRANTY and is licensed as GPL v2.0 or later - see LICENSE.txt.
-#include "mathicgb/stdinc.h"
-
-#include "mathicgb.h"
-#include <gtest/gtest.h>
-
-using namespace mgb;
-
-namespace {
- template<class Stream>
- void makeBasis(Stream& s) {
- s.idealBegin();
- s.appendPolynomialBegin(); // x^2 - y
- s.appendTermBegin();
- s.appendExponent(0,2);
- s.appendTermDone(1);
- s.appendTermBegin();
- s.appendExponent(1,1);
- s.appendTermDone(s.modulus() - 1);
- s.appendPolynomialDone();
- s.appendPolynomialBegin(2); // x^3-z
- s.appendTermBegin();
- s.appendExponent(0,3);
- s.appendTermDone(1);
- s.appendTermBegin();
- s.appendExponent(2,1);
- s.appendTermDone(s.modulus() - 1);
- s.appendPolynomialDone();
- s.idealDone();
- }
-
- template<class Stream>
- void makeGroebnerBasis(Stream& s) {
- s.idealBegin(3);
- s.appendPolynomialBegin(2); // x^2 - y
- s.appendTermBegin();
- s.appendExponent(0, 2);
- s.appendExponent(1, 0);
- s.appendExponent(2, 0);
- s.appendTermDone(1);
- s.appendTermBegin();
- s.appendExponent(0, 0);
- s.appendExponent(1, 1);
- s.appendExponent(2, 0);
- s.appendTermDone(s.modulus() - 1);
- s.appendPolynomialDone();
- s.appendPolynomialBegin(2); // xy - z
- s.appendTermBegin();
- s.appendExponent(0, 1);
- s.appendExponent(1, 1);
- s.appendExponent(2, 0);
- s.appendTermDone(1);
- s.appendTermBegin();
- s.appendExponent(0, 0);
- s.appendExponent(1, 0);
- s.appendExponent(2, 1);
- s.appendTermDone(s.modulus() - 1);
- s.appendPolynomialDone();
- s.appendPolynomialBegin(2); // y^2 - xz
- s.appendTermBegin();
- s.appendExponent(0, 0);
- s.appendExponent(1, 2);
- s.appendExponent(2, 0);
- s.appendTermDone(1);
- s.appendTermBegin();
- s.appendExponent(0, 1);
- s.appendExponent(1, 0);
- s.appendExponent(2, 1);
- s.appendTermDone(s.modulus() - 1);
- s.appendPolynomialDone();
- s.idealDone();
- }
-
- template<class Stream>
- void makeCyclic5Basis(Stream& s) {
- s.idealBegin(5); // polyCount
- s.appendPolynomialBegin(5);
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(1, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(2, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(3, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendPolynomialDone();
- s.appendPolynomialBegin(5);
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(3, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendPolynomialDone();
- s.appendPolynomialBegin(5);
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendPolynomialDone();
- s.appendPolynomialBegin(5);
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendPolynomialDone();
- s.appendPolynomialBegin(2);
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendExponent(4, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendTermDone(100); // coefficient
- s.appendPolynomialDone();
- s.idealDone();
- }
-
- template<class Stream>
- void makeSimpleIdeal(Stream& s) { // variables a,b,c,d. a2-bc, ab-cd.
- s.idealBegin();
- s.appendPolynomialBegin(); // a^2-b*c
- s.appendTermBegin();
- s.appendExponent(0,2);
- s.appendTermDone(1);
- s.appendTermBegin();
- s.appendExponent(1,1);
- s.appendExponent(2,1);
- s.appendTermDone(s.modulus() - 1);
- s.appendPolynomialDone();
- s.appendPolynomialBegin(2); // a*b-c*d
- s.appendTermBegin();
- s.appendExponent(0,1);
- s.appendExponent(1,1);
- s.appendTermDone(1);
- s.appendTermBegin();
- s.appendExponent(2,1);
- s.appendExponent(3,1);
- s.appendTermDone(s.modulus() - 1);
- s.appendPolynomialDone();
- s.idealDone();
- }
-
- template<class Stream>
- void makeSimpleIdealGroebnerBasis(Stream& s) { // variables a,b,c,d. a2-bc, ab-cd.
- // Groebner basis is {a^2-b*c,a*b-c*d,a*c*d-b^2*c,b^3*c-c^2*d^2}
- // (order: eliminate 1 variable: [1 0 0 0; 1 1 1 1]).
- s.idealBegin(4); // polyCount
- s.appendPolynomialBegin(2);
- s.appendTermBegin();
- s.appendExponent(0, 2); // index, exponent
- s.appendExponent(1, 0); // index, exponent
- s.appendExponent(2, 0); // index, exponent
- s.appendExponent(3, 0); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 0); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 0); // index, exponent
- s.appendTermDone(100); // coefficient
- s.appendPolynomialDone();
- s.appendPolynomialBegin(2);
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 1); // index, exponent
- s.appendExponent(2, 0); // index, exponent
- s.appendExponent(3, 0); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 0); // index, exponent
- s.appendExponent(1, 0); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendTermDone(100); // coefficient
- s.appendPolynomialDone();
- s.appendPolynomialBegin(2);
- s.appendTermBegin();
- s.appendExponent(0, 1); // index, exponent
- s.appendExponent(1, 0); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 1); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 0); // index, exponent
- s.appendExponent(1, 2); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 0); // index, exponent
- s.appendTermDone(100); // coefficient
- s.appendPolynomialDone();
- s.appendPolynomialBegin(2);
- s.appendTermBegin();
- s.appendExponent(0, 0); // index, exponent
- s.appendExponent(1, 3); // index, exponent
- s.appendExponent(2, 1); // index, exponent
- s.appendExponent(3, 0); // index, exponent
- s.appendTermDone(1); // coefficient
- s.appendTermBegin();
- s.appendExponent(0, 0); // index, exponent
- s.appendExponent(1, 0); // index, exponent
- s.appendExponent(2, 2); // index, exponent
- s.appendExponent(3, 2); // index, exponent
- s.appendTermDone(100); // coefficient
- s.appendPolynomialDone();
- s.idealDone();
- }
-}
-
-TEST(MathicGBLib, NullIdealStream) {
- {
- mgb::NullIdealStream stream(2, 3);
- ASSERT_EQ(2, stream.modulus());
- ASSERT_EQ(3, stream.varCount());
- makeBasis(stream);
- }
-
- {
- mgb::NullIdealStream stream(101, 0);
- ASSERT_EQ(101, stream.modulus());
- ASSERT_EQ(0, stream.varCount());
- }
-}
-
-TEST(MathicGBLib, IdealStreamLog) {
- {
- const char* const idealStr =
- "s.idealBegin();\n"
- "s.appendPolynomialBegin();\n"
- "s.appendTermBegin();\n"
- "s.appendExponent(0, 2); // index, exponent\n"
- "s.appendTermDone(1); // coefficient\n"
- "s.appendTermBegin();\n"
- "s.appendExponent(1, 1); // index, exponent\n"
- "s.appendTermDone(6); // coefficient\n"
- "s.appendPolynomialDone();\n"
- "s.appendPolynomialBegin(2);\n"
- "s.appendTermBegin();\n"
- "s.appendExponent(0, 3); // index, exponent\n"
- "s.appendTermDone(1); // coefficient\n"
- "s.appendTermBegin();\n"
- "s.appendExponent(2, 1); // index, exponent\n"
- "s.appendTermDone(6); // coefficient\n"
- "s.appendPolynomialDone();\n"
- "s.idealDone();\n";
-
- std::ostringstream out1;
- mgb::IdealStreamLog<> stream1(out1, 7, 3);
-
- mgb::IdealStreamChecker<decltype(stream1)> checker(stream1);
-
- std::ostringstream out2;
- mgb::IdealStreamLog<decltype(checker)> stream2(out2, checker);
-
- std::ostringstream out3;
- mgb::IdealStreamLog<decltype(stream2)> stream3(out3, stream2);
-
- ASSERT_EQ(7, stream1.modulus());
- ASSERT_EQ(3, stream1.varCount());
- ASSERT_EQ(7, checker.modulus());
- ASSERT_EQ(3, checker.varCount());
- ASSERT_EQ(7, stream2.modulus());
- ASSERT_EQ(3, stream2.varCount());
- ASSERT_EQ(7, stream3.modulus());
- ASSERT_EQ(3, stream3.varCount());
-
- makeBasis(stream3);
- const auto str1 = std::string(
- "IdealStreamLog s(stream, 7, 3);\n"
- ) + idealStr;
- 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"
- ) + idealStr;
- ASSERT_EQ(str2, out2.str()) << "Displayed expected:\n" << out2.str();
- ASSERT_EQ(str2, out3.str()) << "Displayed expected:\n" << out3.str();
- }
-
- // The ideal <> in no variables
- {
- std::ostringstream out;
- mgb::IdealStreamLog<> stream(out, 101, 0);
- ASSERT_EQ(101, stream.modulus());
- ASSERT_EQ(0, stream.varCount());
- stream.idealBegin(0);
- stream.idealDone();
- }
-
- // The ideal <1, 0> in no variables
- {
- std::ostringstream out;
- mgb::IdealStreamLog<> stream(out, 101, 0);
- ASSERT_EQ(101, stream.modulus());
- ASSERT_EQ(0, stream.varCount());
- stream.idealBegin(2);
- stream.appendPolynomialBegin(0); // 1
- stream.appendTermBegin();
- stream.appendTermDone(1);
- stream.appendPolynomialDone();
- stream.appendPolynomialBegin(0); // 0
- stream.appendPolynomialDone();
- stream.idealDone();
- }
-}
-
-TEST(MathicGBLib, ZeroIdealGB) {
- mgb::GroebnerConfiguration configuration(2, 0);
- mgb::GroebnerInputIdealStream input(configuration);
- std::ostringstream out;
- mgb::IdealStreamLog<> logStream(out, 2, 0);
-
- input.idealBegin(0);
- input.idealDone();
- mgb::computeGroebnerBasis(input, logStream);
-
- const auto msg =
- "IdealStreamLog s(stream, 2, 0);\n"
- "s.idealBegin(0); // polyCount\n"
- "s.idealDone();\n";
- EXPECT_EQ(msg, out.str());
-}
-
-TEST(MathicGBLib, OneIdealGB) {
- mgb::GroebnerConfiguration configuration(2, 0);
- mgb::GroebnerInputIdealStream input(configuration);
- std::ostringstream out;
- mgb::IdealStreamLog<> logStream(out, 2, 0);
-
- input.idealBegin(1);
- input.appendPolynomialBegin(1);
- input.appendTermBegin();
- input.appendTermDone(1);
- input.appendPolynomialDone();
- input.idealDone();
- mgb::computeGroebnerBasis(input, logStream);
-
- const auto msg =
- "IdealStreamLog s(stream, 2, 0);\n"
- "s.idealBegin(1); // polyCount\n"
- "s.appendPolynomialBegin(1);\n"
- "s.appendTermBegin();\n"
- "s.appendTermDone(1); // coefficient\n"
- "s.appendPolynomialDone();\n"
- "s.idealDone();\n";
- EXPECT_EQ(msg, out.str());
-}
-
-TEST(MathicGBLib, EasyGB) {
- mgb::GroebnerConfiguration configuration(101, 3);
- mgb::GroebnerInputIdealStream input(configuration);
- std::ostringstream computedStr;
- mgb::IdealStreamLog<> computed(computedStr, 101, 3);
- mgb::IdealStreamChecker<decltype(computed)> checked(computed);
-
- makeBasis(input);
- mgb::computeGroebnerBasis(input, checked);
-
- std::ostringstream correctStr;
- mgb::IdealStreamLog<> correct(correctStr, 101, 3);
- mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
- makeGroebnerBasis(correctChecked);
-
- EXPECT_EQ(correctStr.str(), computedStr.str())
- << "\nDisplayed expected:\n" << correctStr.str()
- << "\nDisplayed computed:\n" << computedStr.str();
-}
-
-TEST(MathicGBLib, EasyReGB) {
- mgb::GroebnerConfiguration configuration(101, 3);
- mgb::GroebnerInputIdealStream input(configuration);
- std::ostringstream computedStr;
- mgb::IdealStreamLog<> computed(computedStr, 101, 3);
- mgb::IdealStreamChecker<decltype(computed)> checked(computed);
-
- makeGroebnerBasis(input);
- mgb::computeGroebnerBasis(input, checked);
-
- std::ostringstream correctStr;
- mgb::IdealStreamLog<> correct(correctStr, 101, 3);
- mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
- makeGroebnerBasis(correctChecked);
-
- EXPECT_EQ(correctStr.str(), computedStr.str())
- << "\nDisplayed expected:\n" << correctStr.str()
- << "\nDisplayed computed:\n" << computedStr.str();
-}
-
-TEST(MathicGBLib, Cyclic5) {
- for (int i = 0; i < 2; ++i) {
- mgb::GroebnerConfiguration configuration(101, 5);
- const auto reducer = i == 0 ?
- mgb::GroebnerConfiguration::ClassicReducer :
- mgb::GroebnerConfiguration::MatrixReducer;
- configuration.setReducer(reducer);
- mgb::GroebnerInputIdealStream input(configuration);
- makeCyclic5Basis(input);
-
- mgb::NullIdealStream computed(input.modulus(), input.varCount());
-
- mgb::computeGroebnerBasis(input, computed);
- }
-}
-
-namespace {
- class TestCallback : public mgb::GroebnerConfiguration::Callback {
- public:
- TestCallback(int count, Action action): mCount(count), mAction(action) {}
-
- virtual Action call() {
- --mCount;
- return mCount == 0 ? mAction : ContinueAction;
- }
-
- private:
- int mCount;
- const Action mAction;
- };
-}
-
-TEST(MathicGBLib, EarlyExit) {
- typedef mgb::GroebnerConfiguration::Callback::Action Action;
- auto check = [](bool useClassic, int count, Action action) {
- mgb::GroebnerConfiguration configuration(101, 5);
- const auto reducer = useClassic ?
- mgb::GroebnerConfiguration::ClassicReducer :
- mgb::GroebnerConfiguration::MatrixReducer;
- configuration.setReducer(reducer);
- TestCallback callback(count, action);
- configuration.setCallback(&callback);
- mgb::GroebnerInputIdealStream input(configuration);
- makeCyclic5Basis(input);
-
- std::ostringstream strOut;
- mgb::IdealStreamLog<> out(strOut, 101, 5);
- mgb::computeGroebnerBasis(input, out);
- return strOut.str().size();
- };
-
- for (int useClassic = 0; useClassic < 2; ++useClassic) {
- size_t none = check(useClassic, 5, Action::StopWithNoOutputAction);
- size_t minSize = check(useClassic, 1, Action::StopWithPartialOutputAction);
- size_t midSize = check(useClassic, 4, Action::StopWithPartialOutputAction);
- size_t maxSize = check(useClassic, 1, Action::ContinueAction);
- ASSERT_LT(none, 35); // the stream writes a header even for no output
- ASSERT_LT(none, minSize);
- ASSERT_LT(minSize, midSize);
- ASSERT_LT(midSize, maxSize);
- }
-}
-
-TEST(MathicGBLib, SimpleEliminationGB) {
- typedef mgb::GroebnerConfiguration::Exponent Exponent;
- Exponent v[] = {1,0,0,0, 1,1,1,1};
- std::vector<Exponent> gradings(std::begin(v), std::end(v));
-
- for (int i = 0; i < 2; ++i) {
- mgb::GroebnerConfiguration configuration(101, 4);
- const auto reducer = i == 0 ?
- mgb::GroebnerConfiguration::ClassicReducer :
- mgb::GroebnerConfiguration::MatrixReducer;
- configuration.setReducer(reducer);
- configuration.setMonomialOrder(
- mgb::GroebnerConfiguration::BaseOrder::ReverseLexicographicBaseOrder,
- gradings
- );
-
- mgb::GroebnerInputIdealStream input(configuration);
- std::ostringstream computedStr;
- mgb::IdealStreamLog<> computed(computedStr, 101, 4);
- mgb::IdealStreamChecker<decltype(computed)> checked(computed);
-
- makeSimpleIdeal(input);
- mgb::computeGroebnerBasis(input, checked);
-
- std::ostringstream correctStr;
- mgb::IdealStreamLog<> correct(correctStr, 101, 4);
- mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
- makeSimpleIdealGroebnerBasis(correctChecked);
-
- EXPECT_EQ(correctStr.str(), computedStr.str())
- << "\nDisplayed expected:\n" << correctStr.str()
- << "\nDisplayed computed:\n" << computedStr.str();
-#if 0
- mgb::GroebnerInputIdealStream input(configuration);
- makeSimpleIdeal(input);
- mgb::NullIdealStream computed(input.modulus(), input.varCount());
- mgb::computeGroebnerBasis(input, computed);
-#endif
- }
-}
-
-TEST(MathicGBLib, GlobalOrderOrNot) {
- mgb::GroebnerConfiguration conf(101, 4);
- const auto lex =
- mgb::GroebnerConfiguration::BaseOrder::LexicographicBaseOrder;
- const auto revLex =
- mgb::GroebnerConfiguration::BaseOrder::ReverseLexicographicBaseOrder;
-
- typedef mgb::GroebnerConfiguration::Exponent Exponent;
- std::vector<Exponent> mat;
-
- mat.clear();
- ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
- ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
-
- Exponent mat2[] = {1,2,3,0};
- mat.assign(std::begin(mat2), std::end(mat2));
- ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
- ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
-
- Exponent mat3[] = {1,0,0,0, -3,0,1,2};
- mat.assign(std::begin(mat3), std::end(mat3));
- ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
- ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
-
- Exponent mat4[] = {1,1,0,0, 3,0,1,2};
- mat.assign(std::begin(mat4), std::end(mat4));
- ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
- ASSERT_TRUE(conf.setMonomialOrder(revLex, mat));
-
- Exponent mat5[] = {1,0,0,0, 3,1,1,-2};
- mat.assign(std::begin(mat5), std::end(mat5));
- ASSERT_FALSE(conf.setMonomialOrder(lex, mat));
- ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
-}
+// MathicGB copyright 2012 all rights reserved. MathicGB comes with ABSOLUTELY
+// NO WARRANTY and is licensed as GPL v2.0 or later - see LICENSE.txt.
+#include "mathicgb/stdinc.h"
+
+#include "mathicgb.h"
+#include <gtest/gtest.h>
+
+using namespace mgb;
+
+namespace {
+ template<class Stream>
+ void makeBasis(Stream& s) {
+ s.idealBegin();
+ s.appendPolynomialBegin(); // x^2 - y
+ s.appendTermBegin();
+ s.appendExponent(0,2);
+ s.appendTermDone(1);
+ s.appendTermBegin();
+ s.appendExponent(1,1);
+ s.appendTermDone(s.modulus() - 1);
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(2); // x^3-z
+ s.appendTermBegin();
+ s.appendExponent(0,3);
+ s.appendTermDone(1);
+ s.appendTermBegin();
+ s.appendExponent(2,1);
+ s.appendTermDone(s.modulus() - 1);
+ s.appendPolynomialDone();
+ s.idealDone();
+ }
+
+ template<class Stream>
+ void makeGroebnerBasis(Stream& s) {
+ s.idealBegin(3);
+ s.appendPolynomialBegin(2); // x^2 - y
+ s.appendTermBegin();
+ s.appendExponent(0, 2);
+ s.appendExponent(1, 0);
+ s.appendExponent(2, 0);
+ s.appendTermDone(1);
+ s.appendTermBegin();
+ s.appendExponent(0, 0);
+ s.appendExponent(1, 1);
+ s.appendExponent(2, 0);
+ s.appendTermDone(s.modulus() - 1);
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(2); // xy - z
+ s.appendTermBegin();
+ s.appendExponent(0, 1);
+ s.appendExponent(1, 1);
+ s.appendExponent(2, 0);
+ s.appendTermDone(1);
+ s.appendTermBegin();
+ s.appendExponent(0, 0);
+ s.appendExponent(1, 0);
+ s.appendExponent(2, 1);
+ s.appendTermDone(s.modulus() - 1);
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(2); // y^2 - xz
+ s.appendTermBegin();
+ s.appendExponent(0, 0);
+ s.appendExponent(1, 2);
+ s.appendExponent(2, 0);
+ s.appendTermDone(1);
+ s.appendTermBegin();
+ s.appendExponent(0, 1);
+ s.appendExponent(1, 0);
+ s.appendExponent(2, 1);
+ s.appendTermDone(s.modulus() - 1);
+ s.appendPolynomialDone();
+ s.idealDone();
+ }
+
+ template<class Stream>
+ void makeCyclic5Basis(Stream& s) {
+ s.idealBegin(5); // polyCount
+ s.appendPolynomialBegin(5);
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(1, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(2, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(3, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(5);
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(3, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(5);
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(5);
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(2);
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendExponent(4, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendTermDone(100); // coefficient
+ s.appendPolynomialDone();
+ s.idealDone();
+ }
+
+ template<class Stream>
+ void makeSimpleIdeal(Stream& s) { // variables a,b,c,d. a2-bc, ab-cd.
+ s.idealBegin();
+ s.appendPolynomialBegin(); // a^2-b*c
+ s.appendTermBegin();
+ s.appendExponent(0,2);
+ s.appendTermDone(1);
+ s.appendTermBegin();
+ s.appendExponent(1,1);
+ s.appendExponent(2,1);
+ s.appendTermDone(s.modulus() - 1);
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(2); // a*b-c*d
+ s.appendTermBegin();
+ s.appendExponent(0,1);
+ s.appendExponent(1,1);
+ s.appendTermDone(1);
+ s.appendTermBegin();
+ s.appendExponent(2,1);
+ s.appendExponent(3,1);
+ s.appendTermDone(s.modulus() - 1);
+ s.appendPolynomialDone();
+ s.idealDone();
+ }
+
+ template<class Stream>
+ void makeSimpleIdealGroebnerBasis(Stream& s) { // variables a,b,c,d. a2-bc, ab-cd.
+ // Groebner basis is {a^2-b*c,a*b-c*d,a*c*d-b^2*c,b^3*c-c^2*d^2}
+ // (order: eliminate 1 variable: [1 0 0 0; 1 1 1 1]).
+ s.idealBegin(4); // polyCount
+ s.appendPolynomialBegin(2);
+ s.appendTermBegin();
+ s.appendExponent(0, 2); // index, exponent
+ s.appendExponent(1, 0); // index, exponent
+ s.appendExponent(2, 0); // index, exponent
+ s.appendExponent(3, 0); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 0); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 0); // index, exponent
+ s.appendTermDone(100); // coefficient
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(2);
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 1); // index, exponent
+ s.appendExponent(2, 0); // index, exponent
+ s.appendExponent(3, 0); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 0); // index, exponent
+ s.appendExponent(1, 0); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendTermDone(100); // coefficient
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(2);
+ s.appendTermBegin();
+ s.appendExponent(0, 1); // index, exponent
+ s.appendExponent(1, 0); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 1); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 0); // index, exponent
+ s.appendExponent(1, 2); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 0); // index, exponent
+ s.appendTermDone(100); // coefficient
+ s.appendPolynomialDone();
+ s.appendPolynomialBegin(2);
+ s.appendTermBegin();
+ s.appendExponent(0, 0); // index, exponent
+ s.appendExponent(1, 3); // index, exponent
+ s.appendExponent(2, 1); // index, exponent
+ s.appendExponent(3, 0); // index, exponent
+ s.appendTermDone(1); // coefficient
+ s.appendTermBegin();
+ s.appendExponent(0, 0); // index, exponent
+ s.appendExponent(1, 0); // index, exponent
+ s.appendExponent(2, 2); // index, exponent
+ s.appendExponent(3, 2); // index, exponent
+ s.appendTermDone(100); // coefficient
+ s.appendPolynomialDone();
+ s.idealDone();
+ }
+}
+
+TEST(MathicGBLib, NullIdealStream) {
+ {
+ mgb::NullIdealStream stream(2, 3);
+ ASSERT_EQ(2, stream.modulus());
+ ASSERT_EQ(3, stream.varCount());
+ makeBasis(stream);
+ }
+
+ {
+ mgb::NullIdealStream stream(101, 0);
+ ASSERT_EQ(101, stream.modulus());
+ ASSERT_EQ(0, stream.varCount());
+ }
+}
+
+TEST(MathicGBLib, IdealStreamLog) {
+ {
+ const char* const idealStr =
+ "s.idealBegin();\n"
+ "s.appendPolynomialBegin();\n"
+ "s.appendTermBegin();\n"
+ "s.appendExponent(0, 2); // index, exponent\n"
+ "s.appendTermDone(1); // coefficient\n"
+ "s.appendTermBegin();\n"
+ "s.appendExponent(1, 1); // index, exponent\n"
+ "s.appendTermDone(6); // coefficient\n"
+ "s.appendPolynomialDone();\n"
+ "s.appendPolynomialBegin(2);\n"
+ "s.appendTermBegin();\n"
+ "s.appendExponent(0, 3); // index, exponent\n"
+ "s.appendTermDone(1); // coefficient\n"
+ "s.appendTermBegin();\n"
+ "s.appendExponent(2, 1); // index, exponent\n"
+ "s.appendTermDone(6); // coefficient\n"
+ "s.appendPolynomialDone();\n"
+ "s.idealDone();\n";
+
+ std::ostringstream out1;
+ mgb::IdealStreamLog<> stream1(out1, 7, 3);
+
+ mgb::IdealStreamChecker<decltype(stream1)> checker(stream1);
+
+ std::ostringstream out2;
+ mgb::IdealStreamLog<decltype(checker)> stream2(out2, checker);
+
+ std::ostringstream out3;
+ mgb::IdealStreamLog<decltype(stream2)> stream3(out3, stream2);
+
+ ASSERT_EQ(7, stream1.modulus());
+ ASSERT_EQ(3, stream1.varCount());
+ ASSERT_EQ(7, checker.modulus());
+ ASSERT_EQ(3, checker.varCount());
+ ASSERT_EQ(7, stream2.modulus());
+ ASSERT_EQ(3, stream2.varCount());
+ ASSERT_EQ(7, stream3.modulus());
+ ASSERT_EQ(3, stream3.varCount());
+
+ makeBasis(stream3);
+ const auto str1 = std::string(
+ "IdealStreamLog s(stream, 7, 3);\n"
+ ) + idealStr;
+ 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"
+ ) + idealStr;
+ ASSERT_EQ(str2, out2.str()) << "Displayed expected:\n" << out2.str();
+ ASSERT_EQ(str2, out3.str()) << "Displayed expected:\n" << out3.str();
+ }
+
+ // The ideal <> in no variables
+ {
+ std::ostringstream out;
+ mgb::IdealStreamLog<> stream(out, 101, 0);
+ ASSERT_EQ(101, stream.modulus());
+ ASSERT_EQ(0, stream.varCount());
+ stream.idealBegin(0);
+ stream.idealDone();
+ }
+
+ // The ideal <1, 0> in no variables
+ {
+ std::ostringstream out;
+ mgb::IdealStreamLog<> stream(out, 101, 0);
+ ASSERT_EQ(101, stream.modulus());
+ ASSERT_EQ(0, stream.varCount());
+ stream.idealBegin(2);
+ stream.appendPolynomialBegin(0); // 1
+ stream.appendTermBegin();
+ stream.appendTermDone(1);
+ stream.appendPolynomialDone();
+ stream.appendPolynomialBegin(0); // 0
+ stream.appendPolynomialDone();
+ stream.idealDone();
+ }
+}
+
+TEST(MathicGBLib, ZeroIdealGB) {
+ mgb::GroebnerConfiguration configuration(2, 0);
+ mgb::GroebnerInputIdealStream input(configuration);
+ std::ostringstream out;
+ mgb::IdealStreamLog<> logStream(out, 2, 0);
+
+ input.idealBegin(0);
+ input.idealDone();
+ mgb::computeGroebnerBasis(input, logStream);
+
+ const auto msg =
+ "IdealStreamLog s(stream, 2, 0);\n"
+ "s.idealBegin(0); // polyCount\n"
+ "s.idealDone();\n";
+ EXPECT_EQ(msg, out.str());
+}
+
+TEST(MathicGBLib, OneIdealGB) {
+ mgb::GroebnerConfiguration configuration(2, 0);
+ mgb::GroebnerInputIdealStream input(configuration);
+ std::ostringstream out;
+ mgb::IdealStreamLog<> logStream(out, 2, 0);
+
+ input.idealBegin(1);
+ input.appendPolynomialBegin(1);
+ input.appendTermBegin();
+ input.appendTermDone(1);
+ input.appendPolynomialDone();
+ input.idealDone();
+ mgb::computeGroebnerBasis(input, logStream);
+
+ const auto msg =
+ "IdealStreamLog s(stream, 2, 0);\n"
+ "s.idealBegin(1); // polyCount\n"
+ "s.appendPolynomialBegin(1);\n"
+ "s.appendTermBegin();\n"
+ "s.appendTermDone(1); // coefficient\n"
+ "s.appendPolynomialDone();\n"
+ "s.idealDone();\n";
+ EXPECT_EQ(msg, out.str());
+}
+
+TEST(MathicGBLib, EasyGB) {
+ mgb::GroebnerConfiguration configuration(101, 3);
+ mgb::GroebnerInputIdealStream input(configuration);
+ std::ostringstream computedStr;
+ mgb::IdealStreamLog<> computed(computedStr, 101, 3);
+ mgb::IdealStreamChecker<decltype(computed)> checked(computed);
+
+ makeBasis(input);
+ mgb::computeGroebnerBasis(input, checked);
+
+ std::ostringstream correctStr;
+ mgb::IdealStreamLog<> correct(correctStr, 101, 3);
+ mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
+ makeGroebnerBasis(correctChecked);
+
+ EXPECT_EQ(correctStr.str(), computedStr.str())
+ << "\nDisplayed expected:\n" << correctStr.str()
+ << "\nDisplayed computed:\n" << computedStr.str();
+}
+
+TEST(MathicGBLib, EasyReGB) {
+ mgb::GroebnerConfiguration configuration(101, 3);
+ mgb::GroebnerInputIdealStream input(configuration);
+ std::ostringstream computedStr;
+ mgb::IdealStreamLog<> computed(computedStr, 101, 3);
+ mgb::IdealStreamChecker<decltype(computed)> checked(computed);
+
+ makeGroebnerBasis(input);
+ mgb::computeGroebnerBasis(input, checked);
+
+ std::ostringstream correctStr;
+ mgb::IdealStreamLog<> correct(correctStr, 101, 3);
+ mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
+ makeGroebnerBasis(correctChecked);
+
+ EXPECT_EQ(correctStr.str(), computedStr.str())
+ << "\nDisplayed expected:\n" << correctStr.str()
+ << "\nDisplayed computed:\n" << computedStr.str();
+}
+
+TEST(MathicGBLib, Cyclic5) {
+ for (int i = 0; i < 2; ++i) {
+ mgb::GroebnerConfiguration configuration(101, 5);
+ const auto reducer = i == 0 ?
+ mgb::GroebnerConfiguration::ClassicReducer :
+ mgb::GroebnerConfiguration::MatrixReducer;
+ configuration.setReducer(reducer);
+ mgb::GroebnerInputIdealStream input(configuration);
+ makeCyclic5Basis(input);
+
+ mgb::NullIdealStream computed(input.modulus(), input.varCount());
+
+ mgb::computeGroebnerBasis(input, computed);
+ }
+}
+
+namespace {
+ class TestCallback : public mgb::GroebnerConfiguration::Callback {
+ public:
+ TestCallback(int count, Action action): mCount(count), mAction(action) {}
+
+ virtual Action call() {
+ --mCount;
+ return mCount == 0 ? mAction : ContinueAction;
+ }
+
+ private:
+ int mCount;
+ const Action mAction;
+ };
+}
+
+TEST(MathicGBLib, EarlyExit) {
+ typedef mgb::GroebnerConfiguration::Callback::Action Action;
+ auto check = [](bool useClassic, int count, Action action) {
+ mgb::GroebnerConfiguration configuration(101, 5);
+ const auto reducer = useClassic ?
+ mgb::GroebnerConfiguration::ClassicReducer :
+ mgb::GroebnerConfiguration::MatrixReducer;
+ configuration.setReducer(reducer);
+ TestCallback callback(count, action);
+ configuration.setCallback(&callback);
+ mgb::GroebnerInputIdealStream input(configuration);
+ makeCyclic5Basis(input);
+
+ std::ostringstream strOut;
+ mgb::IdealStreamLog<> out(strOut, 101, 5);
+ mgb::computeGroebnerBasis(input, out);
+ return strOut.str().size();
+ };
+
+ for (int useClassic = 0; useClassic < 2; ++useClassic) {
+ size_t none = check(useClassic, 5, Action::StopWithNoOutputAction);
+ size_t minSize = check(useClassic, 1, Action::StopWithPartialOutputAction);
+ size_t midSize = check(useClassic, 4, Action::StopWithPartialOutputAction);
+ size_t maxSize = check(useClassic, 1, Action::ContinueAction);
+ ASSERT_LT(none, 35); // the stream writes a header even for no output
+ ASSERT_LT(none, minSize);
+ ASSERT_LT(minSize, midSize);
+ ASSERT_LT(midSize, maxSize);
+ }
+}
+
+TEST(MathicGBLib, SimpleEliminationGB) {
+ typedef mgb::GroebnerConfiguration::Exponent Exponent;
+ Exponent v[] = {1,0,0,0, 1,1,1,1};
+ std::vector<Exponent> gradings(v, v + sizeof(v)/sizeof(*v));
+
+ for (int i = 0; i < 2; ++i) {
+ mgb::GroebnerConfiguration configuration(101, 4);
+ const auto reducer = i == 0 ?
+ mgb::GroebnerConfiguration::ClassicReducer :
+ mgb::GroebnerConfiguration::MatrixReducer;
+ configuration.setReducer(reducer);
+ configuration.setMonomialOrder(
+ mgb::GroebnerConfiguration::BaseOrder::ReverseLexicographicBaseOrder,
+ gradings
+ );
+
+ mgb::GroebnerInputIdealStream input(configuration);
+ std::ostringstream computedStr;
+ mgb::IdealStreamLog<> computed(computedStr, 101, 4);
+ mgb::IdealStreamChecker<decltype(computed)> checked(computed);
+
+ makeSimpleIdeal(input);
+ mgb::computeGroebnerBasis(input, checked);
+
+ std::ostringstream correctStr;
+ mgb::IdealStreamLog<> correct(correctStr, 101, 4);
+ mgb::IdealStreamChecker<decltype(correct)> correctChecked(correct);
+ makeSimpleIdealGroebnerBasis(correctChecked);
+
+ EXPECT_EQ(correctStr.str(), computedStr.str())
+ << "\nDisplayed expected:\n" << correctStr.str()
+ << "\nDisplayed computed:\n" << computedStr.str();
+#if 0
+ mgb::GroebnerInputIdealStream input(configuration);
+ makeSimpleIdeal(input);
+ mgb::NullIdealStream computed(input.modulus(), input.varCount());
+ mgb::computeGroebnerBasis(input, computed);
+#endif
+ }
+}
+
+TEST(MathicGBLib, GlobalOrderOrNot) {
+ mgb::GroebnerConfiguration conf(101, 4);
+ const auto lex =
+ mgb::GroebnerConfiguration::BaseOrder::LexicographicBaseOrder;
+ const auto revLex =
+ mgb::GroebnerConfiguration::BaseOrder::ReverseLexicographicBaseOrder;
+
+ typedef mgb::GroebnerConfiguration::Exponent Exponent;
+ std::vector<Exponent> mat;
+
+ mat.clear();
+ ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
+ ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
+
+ Exponent mat2[] = {1,2,3,0};
+ mat.assign(mat2, mat2 + sizeof(mat2)/sizeof(*mat2));
+ ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
+ ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
+
+ Exponent mat3[] = {1,0,0,0, -3,0,1,2};
+ mat.assign(mat3, mat3 + sizeof(mat3)/sizeof(*mat3));
+ ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
+ ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
+
+ Exponent mat4[] = {1,1,0,0, 3,0,1,2};
+ mat.assign(mat4, mat4 + sizeof(mat4)/sizeof(*mat4));
+ ASSERT_TRUE(conf.setMonomialOrder(lex, mat));
+ ASSERT_TRUE(conf.setMonomialOrder(revLex, mat));
+
+ Exponent mat5[] = {1,0,0,0, 3,1,1,-2};
+ mat.assign(mat5, mat5 + sizeof(mat5)/sizeof(*mat5));
+ ASSERT_FALSE(conf.setMonomialOrder(lex, mat));
+ ASSERT_FALSE(conf.setMonomialOrder(revLex, mat));
+}
--
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