[mathicgb] 117/393: The matrix action now takes several input files and processes each of them separately. There is not an -inputFile option any more.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:44 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 c81a09b5d4620c716f1555213c8f03c8bc3e63ec
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Tue Nov 20 16:41:10 2012 +0100
The matrix action now takes several input files and processes each of them separately. There is not an -inputFile option any more.
---
src/cli/CommonParams.cpp | 42 ++++++++++-------
src/cli/CommonParams.hpp | 25 +++++++----
src/cli/GBAction.cpp | 5 ++-
src/cli/MatrixAction.cpp | 115 ++++++++++++++++++++++++-----------------------
src/cli/SigGBAction.cpp | 12 ++---
5 files changed, 113 insertions(+), 86 deletions(-)
diff --git a/src/cli/CommonParams.cpp b/src/cli/CommonParams.cpp
index fecbaec..3b02ed9 100644
--- a/src/cli/CommonParams.cpp
+++ b/src/cli/CommonParams.cpp
@@ -1,11 +1,7 @@
#include "mathicgb/stdinc.h"
#include "CommonParams.hpp"
-CommonParams::CommonParams():
- mInputFile("inputFile",
- "The file to read input from.",
- ""),
-
+CommonParams::CommonParams(size_t minDirectParams, size_t maxDirectParams):
mTracingLevel("tracingLevel",
"How much information to print out about what the program does. No "
"information is shown if the value is zero. Higher values "
@@ -14,7 +10,10 @@ CommonParams::CommonParams():
mThreadCount("threadCount",
"Specifies how many threads to use at a time.",
- 1)
+ 1),
+
+ mMinDirectParams(minDirectParams),
+ mMaxDirectParams(maxDirectParams)
{
}
@@ -22,16 +21,16 @@ void CommonParams::directOptions(
std::vector<std::string> tokens,
mathic::CliParser& parser
) {
- if (tokens.size() == 1)
- mInputFile.processArgument(tokens.back());
- if (tokens.size() > 1)
- mathic::reportError("Too many direct options.");
+ if (tokens.size() < mMinDirectParams)
+ mathic::reportError("Too few direct options");
+ if (tokens.size() > mMaxDirectParams)
+ mathic::reportError("Too many direct options");
+ mDirectParameters = std::move(tokens);
}
void CommonParams::pushBackParameters(
std::vector<mathic::CliParameter*>& parameters
) {
- parameters.push_back(&mInputFile);
parameters.push_back(&mTracingLevel);
parameters.push_back(&mThreadCount);
}
@@ -55,16 +54,27 @@ void CommonParams::registerFileNameExtension(std::string extension) {
mExtensions.push_back(std::move(extension));
}
-std::string CommonParams::inputFileNameStem() {
- const auto& str = mInputFile.value();
- const auto toStrip = inputFileNameExtension();
+size_t CommonParams::inputFileCount() const {
+ return mDirectParameters.size();
+}
+
+std::string CommonParams::inputFileName(size_t i) {
+ MATHICGB_ASSERT(i < inputFileCount());
+ return mDirectParameters[i];
+}
+
+std::string CommonParams::inputFileNameStem(size_t i) {
+ MATHICGB_ASSERT(i < inputFileCount());
+ const auto& str = mDirectParameters[i];
+ const auto toStrip = inputFileNameExtension(i);
MATHICGB_ASSERT
(toStrip.size() < str.size() || (toStrip.empty() && str.empty()));
return str.substr(0, str.size() - toStrip.size());
}
-std::string CommonParams::inputFileNameExtension() {
- const auto& str = mInputFile.value();
+std::string CommonParams::inputFileNameExtension(size_t i) {
+ MATHICGB_ASSERT(i < inputFileCount());
+ const auto& str = mDirectParameters[i];
const auto end = mExtensions.end();
for (auto it = mExtensions.begin(); it != end; ++it) {
if (
diff --git a/src/cli/CommonParams.hpp b/src/cli/CommonParams.hpp
index b54ab63..ea8450d 100644
--- a/src/cli/CommonParams.hpp
+++ b/src/cli/CommonParams.hpp
@@ -7,7 +7,7 @@
class CommonParams {
public:
- CommonParams();
+ CommonParams(size_t minDirectParams, size_t maxDirectParams);
void directOptions
(std::vector<std::string> tokens, mathic::CliParser& parser);
@@ -22,20 +22,29 @@ public:
/// for a file name instead of part of the file name.
void registerFileNameExtension(std::string extensions);
- /// Returns the stem of the input file name, with any registered extensions
- /// stripped off.
- std::string inputFileNameStem();
+ /// Returns the number of direct parameters/input files.
+ size_t inputFileCount() const;
- /// Returns the registered extension of the input file name, if any.
- std::string inputFileNameExtension();
+ /// Returns the file name at offset i, if any.
+ std::string inputFileName(size_t i);
- mathic::StringParameter mInputFile;
+ /// Returns the stem of the input file name at offset i, with any registered
+ /// extensions stripped off.
+ std::string inputFileNameStem(size_t i);
+
+ /// Returns the registered extension of the input file name at offset i,
+ /// if any.
+ std::string inputFileNameExtension(size_t i);
+
+private:
mathic::IntegerParameter mTracingLevel;
mathic::IntegerParameter mThreadCount;
-private:
std::vector<std::string> mExtensions; // to recognize file type
std::unique_ptr<tbb::task_scheduler_init> mTbbInit; // to set thread count
+ std::size_t mMinDirectParams;
+ std::size_t mMaxDirectParams;
+ std::vector<std::string> mDirectParameters;
};
#endif
diff --git a/src/cli/GBAction.cpp b/src/cli/GBAction.cpp
index 4b7f4e8..220c7b9 100644
--- a/src/cli/GBAction.cpp
+++ b/src/cli/GBAction.cpp
@@ -37,8 +37,9 @@ GBAction::GBAction():
"files named X-1.mat, X-2.mat and so on where X is the project name. Only "
"matrices with at least as many entries as the parameter are stored. "
"A value of 0 indicates not to store any matrices.",
- 0)
+ 0),
+ mParams(1, 1)
{
std::ostringstream orderOut;
FreeModuleOrder::displayOrderTypes(orderOut);
@@ -55,7 +56,7 @@ void GBAction::directOptions(
void GBAction::performAction() {
mParams.perform();
mGBParams.perform();
- const std::string projectName = mParams.inputFileNameStem();
+ const std::string projectName = mParams.inputFileNameStem(0);
// read input
std::unique_ptr<Ideal> ideal;
diff --git a/src/cli/MatrixAction.cpp b/src/cli/MatrixAction.cpp
index 6b79cbd..2d86a44 100644
--- a/src/cli/MatrixAction.cpp
+++ b/src/cli/MatrixAction.cpp
@@ -7,6 +7,7 @@
#include "mathicgb/SparseMatrix.hpp"
#include "mathicgb/CFile.hpp"
#include <mathic.h>
+#include <limits>
#include <fstream>
#include <iostream>
@@ -28,7 +29,8 @@ namespace {
}
}
-MatrixAction::MatrixAction() {
+MatrixAction::MatrixAction():
+ mParams(1, std::numeric_limits<size_t>::max()) {
mParams.registerFileNameExtension(QuadMatrixExtension);
mParams.registerFileNameExtension(LowerRightMatrixExtension);
mParams.registerFileNameExtension(ReducedLowerRightMatrixExtension);
@@ -44,65 +46,68 @@ void MatrixAction::directOptions(
void MatrixAction::performAction() {
mParams.perform();
- const auto fileNameStem = mParams.inputFileNameStem();
- const auto extension = mParams.inputFileNameExtension();
- const auto quadFileName = fileNameStem + QuadMatrixExtension;
- const auto lowerRightFileName = fileNameStem + LowerRightMatrixExtension;
- const auto reducedLowerRightFileName =
- fileNameStem + ReducedLowerRightMatrixExtension;
- std::string inputFileName;
+ for (size_t i = 0; i < mParams.inputFileCount(); ++i) {
+ const auto fileNameStem = mParams.inputFileNameStem(i);
+ const auto extension = mParams.inputFileNameExtension(i);
+ const auto quadFileName = fileNameStem + QuadMatrixExtension;
+ const auto lowerRightFileName = fileNameStem + LowerRightMatrixExtension;
+ const auto reducedLowerRightFileName =
+ fileNameStem + ReducedLowerRightMatrixExtension;
+ std::string inputFileName;
- SparseMatrix lowerRightMatrix;
- SparseMatrix::Scalar modulus;
- if (
- extension == QuadMatrixExtension ||
- extension == "." ||
- extension == ""
- ) {
- inputFileName = quadFileName;
- CFile file(quadFileName, "rb");
- QuadMatrix matrix;
- modulus = matrix.read(file.handle());
- fclose(file.handle());
- // @todo: F4MatrixReducer should not take a PolyRing parameter.
- PolyRing ring(modulus, 0, 0);
- F4MatrixReducer reducer(ring);
- // @todo: only reduce down to D, do not reduce D itself
- lowerRightMatrix = reducer.reduce(matrix);
+ SparseMatrix lowerRightMatrix;
+ SparseMatrix::Scalar modulus;
+ if (
+ extension == QuadMatrixExtension ||
+ extension == "." ||
+ extension == ""
+ ) {
+ inputFileName = quadFileName;
+ CFile file(quadFileName, "rb");
+ QuadMatrix matrix;
+ modulus = matrix.read(file.handle());
+ fclose(file.handle());
+ // @todo: F4MatrixReducer should not take a PolyRing parameter.
+ PolyRing ring(modulus, 0, 0);
+ F4MatrixReducer reducer(ring);
+ // @todo: only reduce down to D, do not reduce D itself
+ lowerRightMatrix = reducer.reduce(matrix);
- if (!fileExists(lowerRightFileName)) {
- CFile file(lowerRightFileName, "wb");
- lowerRightMatrix.write(modulus, file.handle());
+ if (!fileExists(lowerRightFileName)) {
+ CFile file(lowerRightFileName, "wb");
+ lowerRightMatrix.write(modulus, file.handle());
+ }
+ } else if (extension == LowerRightMatrixExtension) {
+ inputFileName = lowerRightFileName;
+ CFile file(lowerRightFileName, "rb");
+ modulus = lowerRightMatrix.read(file.handle());
+ } else {
+ mathic::reportError
+ ("Unknown input file extension of " + mParams.inputFileName(i));
}
- } else if (extension == LowerRightMatrixExtension) {
- inputFileName = lowerRightFileName;
- CFile file(lowerRightFileName, "rb");
- modulus = lowerRightMatrix.read(file.handle());
- } else {
- mathic::reportError
- ("Unknown input file extension of " + mParams.mInputFile.value());
- }
- {
- // @todo: expose D -> reduced D code and call it here
- //PolyRing ring(modulus, 0, 0);
- //F4MatrixReducer reducer(ring);
- }
- lowerRightMatrix.sortRowsByIncreasingPivots();
+ {
+ // @todo: expose D -> reduced D code and call it here
+ //PolyRing ring(modulus, 0, 0);
+ //F4MatrixReducer reducer(ring);
+ }
+ lowerRightMatrix.sortRowsByIncreasingPivots();
- if (!fileExists(reducedLowerRightFileName)) {
- CFile file(reducedLowerRightFileName.c_str(), "wb");
- lowerRightMatrix.write(modulus, file.handle());
- } else {
- SparseMatrix referenceMatrix;
- CFile file(reducedLowerRightFileName.c_str(), "rb");
- referenceMatrix.read(file.handle());
- if (lowerRightMatrix != referenceMatrix) {
- std::cerr << "Reducing " << inputFileName
- << " does not yield the matrix " << reducedLowerRightFileName << ".\n";
- } else if (tracingLevel > 0) {
- std::cerr << "Match for " << inputFileName
- << " -> " << ReducedLowerRightMatrixExtension << ".\n";
+ if (!fileExists(reducedLowerRightFileName)) {
+ CFile file(reducedLowerRightFileName.c_str(), "wb");
+ lowerRightMatrix.write(modulus, file.handle());
+ } else {
+ SparseMatrix referenceMatrix;
+ CFile file(reducedLowerRightFileName.c_str(), "rb");
+ referenceMatrix.read(file.handle());
+ if (lowerRightMatrix != referenceMatrix) {
+ std::cerr << "Reducing " << inputFileName
+ << " does not yield the matrix "
+ << reducedLowerRightFileName << ".\n";
+ } else if (tracingLevel > 0) {
+ std::cerr << "Match for " << inputFileName
+ << " -> " << ReducedLowerRightMatrixExtension << ".\n";
+ }
}
}
}
diff --git a/src/cli/SigGBAction.cpp b/src/cli/SigGBAction.cpp
index 6bb2bb0..b62c4eb 100644
--- a/src/cli/SigGBAction.cpp
+++ b/src/cli/SigGBAction.cpp
@@ -27,7 +27,9 @@ SigGBAction::SigGBAction():
mModuleOrder("moduleOrder",
"The free module term order.\n",
- 4)
+ 4),
+
+ mParams(1, 1)
{
std::ostringstream orderOut;
FreeModuleOrder::displayOrderTypes(orderOut);
@@ -48,7 +50,7 @@ void SigGBAction::performAction() {
// read input file
std::unique_ptr<Ideal> ideal;
{
- std::string const inputIdealFile = mParams.inputFileNameStem() + ".ideal";
+ const std::string inputIdealFile = mParams.inputFileNameStem(0) + ".ideal";
std::ifstream inputFile(inputIdealFile.c_str());
if (inputFile.fail())
mic::reportError("Could not read input file \"" + inputIdealFile + '\n');
@@ -75,21 +77,21 @@ void SigGBAction::performAction() {
alg.displayStats(std::cout);
alg.displayPaperStats(std::cout);
{
- std::ofstream statsOut((mParams.inputFileNameStem() + ".stats").c_str());
+ std::ofstream statsOut((mParams.inputFileNameStem(0) + ".stats").c_str());
alg.displayStats(statsOut);
alg.displayPaperStats(statsOut);
}
// print basis
{
- std::ofstream ogb((mParams.inputFileNameStem() + ".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() + ".syz").c_str());
+ std::ofstream syzygyOut((mParams.inputFileNameStem(0) + ".syz").c_str());
syzygyOut << "-- syz: ----\n";
alg.getSyzTable()->display(syzygyOut, 1);
syzygyOut << std::endl;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git
More information about the debian-science-commits
mailing list