[mathicgb] 118/393: The unreduced bottom right matrix is now written out by the matrix action (not the gb action). This allows to run only the row reduction of the bottom right matrix - it is not required to reduce the full matrix to get at this computation. Simply specify the file with the bottom right matrix as the input file.
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 22a6ef5afa38c29b09e69fec25733adfe7920f8c
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Tue Nov 20 17:21:06 2012 +0100
The unreduced bottom right matrix is now written out by the matrix action (not the gb action). This allows to run only the row reduction of the bottom right matrix - it is not required to reduce the full matrix to get at this computation. Simply specify the file with the bottom right matrix as the input file.
---
src/cli/MatrixAction.cpp | 13 +++------
src/mathicgb/F4MatrixReducer.cpp | 57 +++++++++++++++++++++++-----------------
src/mathicgb/F4MatrixReducer.hpp | 30 ++++++++++++++++-----
src/mathicgb/F4Reducer.cpp | 6 +++--
src/test/F4MatrixReducer.cpp | 3 ++-
5 files changed, 65 insertions(+), 44 deletions(-)
diff --git a/src/cli/MatrixAction.cpp b/src/cli/MatrixAction.cpp
index 2d86a44..559ea81 100644
--- a/src/cli/MatrixAction.cpp
+++ b/src/cli/MatrixAction.cpp
@@ -67,11 +67,7 @@ void MatrixAction::performAction() {
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);
+ lowerRightMatrix = F4MatrixReducer(modulus).reduceToBottomRight(matrix);
if (!fileExists(lowerRightFileName)) {
CFile file(lowerRightFileName, "wb");
@@ -86,11 +82,8 @@ void MatrixAction::performAction() {
("Unknown input file extension of " + mParams.inputFileName(i));
}
- {
- // @todo: expose D -> reduced D code and call it here
- //PolyRing ring(modulus, 0, 0);
- //F4MatrixReducer reducer(ring);
- }
+ lowerRightMatrix = F4MatrixReducer(modulus).
+ reducedRowEchelonForm(lowerRightMatrix);
lowerRightMatrix.sortRowsByIncreasingPivots();
if (!fileExists(reducedLowerRightFileName)) {
diff --git a/src/mathicgb/F4MatrixReducer.cpp b/src/mathicgb/F4MatrixReducer.cpp
index 7caffb0..d8680ed 100755
--- a/src/mathicgb/F4MatrixReducer.cpp
+++ b/src/mathicgb/F4MatrixReducer.cpp
@@ -241,23 +241,22 @@ namespace {
return std::move(reduced);
}
- void reduceToEchelonForm(
- SparseMatrix& toReduce,
- const SparseMatrix::ColIndex colCount,
+ SparseMatrix reduceToEchelonForm(
+ const SparseMatrix& toReduce,
const SparseMatrix::Scalar modulus
) {
- // making no assumptions on toReduce except no zero rows
+ const auto colCount = toReduce.computeColCount();
+ const auto rowCount = toReduce.rowCount();
- SparseMatrix::RowIndex const rowCount = toReduce.rowCount();
-
- // dense representation
+ // convert to dense representation
std::vector<DenseRow<uint64>> dense(rowCount);
-
tbb::parallel_for(tbb::blocked_range<size_t>(0, rowCount),
[&](const tbb::blocked_range<size_t>& range)
{for (auto it = range.begin(); it != range.end(); ++it)
{
const size_t row = it;
+ if (toReduce.emptyRow(row))
+ return;
dense[row].clear(colCount);
dense[row].addRow(toReduce, row);
}});
@@ -361,39 +360,49 @@ namespace {
dense[row].takeModulus(modulus);
}});
- toReduce.clear();
+ reduced.clear();
for (size_t row = 0; row < rowCount; ++row)
if (!dense[row].empty())
- dense[row].appendTo(toReduce);
+ dense[row].appendTo(reduced);
+ return std::move(reduced);
}
}
-SparseMatrix F4MatrixReducer::reduce(const QuadMatrix& matrix) {
+
+SparseMatrix F4MatrixReducer::reduceToBottomRight(const QuadMatrix& matrix) {
MATHICGB_ASSERT(matrix.debugAssertValid());
if (tracingLevel >= 3)
matrix.printSizes(std::cerr);
+ return reduce(matrix, mModulus);
+}
+
+SparseMatrix F4MatrixReducer::reducedRowEchelonForm(
+ const SparseMatrix& matrix
+) {
+ return reduceToEchelonForm(matrix, mModulus);
+}
- const auto rightColCount = matrix.computeRightColCount();
- //static_cast<SparseMatrix::ColIndex>(matrix.rightColumnMonomials.size());
- SparseMatrix newPivots(::reduce(matrix, mModulus));
- ::reduceToEchelonForm(newPivots, rightColCount, mModulus);
- return std::move(newPivots);
+SparseMatrix F4MatrixReducer::reducedRowEchelonFormBottomRight(
+ const QuadMatrix& matrix
+) {
+ return reducedRowEchelonForm(reduceToBottomRight(matrix));
}
namespace {
/// this has to be a separate function that returns the scalar since signed
/// overflow is undefine behavior so we cannot check after the cast and
- /// we also cannot set mCharac inside the constructor since it is const.
- SparseMatrix::Scalar checkModulus(const PolyRing& ring) {
+ /// we also cannot set the modulus field inside the constructor since it is
+ /// const.
+ SparseMatrix::Scalar checkModulus(const coefficient modulus) {
// this assert has to be NO_ASSUME as otherwise the branch below will get
// optimized out.
- MATHICGB_ASSERT_NO_ASSUME(ring.charac() <=
+ MATHICGB_ASSERT_NO_ASSUME(modulus <=
std::numeric_limits<SparseMatrix::Scalar>::max());
- if (ring.charac() > std::numeric_limits<SparseMatrix::Scalar>::max())
- throw std::overflow_error("Too large modulus in F4 matrix computation.");
- return static_cast<SparseMatrix::Scalar>(ring.charac());
+ 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);
}
}
-F4MatrixReducer::F4MatrixReducer(const PolyRing& ring):
- mModulus(checkModulus(ring)) {}
+F4MatrixReducer::F4MatrixReducer(const coefficient modulus):
+ mModulus(checkModulus(modulus)) {}
diff --git a/src/mathicgb/F4MatrixReducer.hpp b/src/mathicgb/F4MatrixReducer.hpp
index f282584..4fc76a5 100755
--- a/src/mathicgb/F4MatrixReducer.hpp
+++ b/src/mathicgb/F4MatrixReducer.hpp
@@ -5,16 +5,32 @@
class QuadMatrix;
class PolyRing;
-/** Class that reduces an F4 matrix represented as a QuadMatrix. The
- answer you get is the submatrix that contains new pivots. */
+/// Class that reduces an F4 matrix represented as a QuadMatrix. The
+/// answer that you get is the submatrix that contains new pivots.
+///
+/// All QuadMatrix parameters passed into methods on this class are
+/// assumed to have a permutation of the top rows and left columns so
+/// that the top left matrix is upper unitriangular. In this way the
+/// lower left part of the matrix becomes all-zero after row reduction.
class F4MatrixReducer {
public:
- F4MatrixReducer(const PolyRing& ring);
+ /// The ring used is Z/pZ where modulus is the prime p.
+ ///
+ ///
+ F4MatrixReducer(coefficient modulus);
- /// Reduces the lower right part of the row echelon form of matrix. Assumes
- /// that there is a permutation of the upper rows that makes the upper
- /// the upper left part of matrix upper unitriangular.
- SparseMatrix reduce(const QuadMatrix& matrix);
+ /// Reduces the bottom rows by the top rows and returns the bottom right
+ /// submatrix of the resulting quad matrix. The lower left submatrix
+ /// is not returned because it is always zero after row reduction.
+ SparseMatrix reduceToBottomRight(const QuadMatrix& matrix);
+
+ /// Returns the reduced row echelon form of matrix.
+ SparseMatrix reducedRowEchelonForm(const SparseMatrix& matrix);
+
+ /// Returns the lower right submatrix if the reduced row echelon
+ /// form of matrix. The lower left part is not returned because it is
+ /// always zero after row reduction.
+ SparseMatrix reducedRowEchelonFormBottomRight(const QuadMatrix& matrix);
private:
const SparseMatrix::Scalar mModulus;
diff --git a/src/mathicgb/F4Reducer.cpp b/src/mathicgb/F4Reducer.cpp
index 4fa2b3c..d2b0d09 100755
--- a/src/mathicgb/F4Reducer.cpp
+++ b/src/mathicgb/F4Reducer.cpp
@@ -93,7 +93,8 @@ void F4Reducer::classicReduceSPolySet(
MATHICGB_ASSERT(qm.bottomLeft.rowCount() > 0);
}
saveMatrix(qm);
- reduced = F4MatrixReducer(basis.ring()).reduce(qm);
+ reduced = F4MatrixReducer(basis.ring().charac()).
+ reducedRowEchelonFormBottomRight(qm);
monomials = std::move(qm.rightColumnMonomials);
const auto end = qm.leftColumnMonomials.end();
for (auto it = qm.leftColumnMonomials.begin(); it != end; ++it)
@@ -147,7 +148,8 @@ void F4Reducer::classicReducePolySet
MATHICGB_ASSERT(qm.bottomLeft.rowCount() > 0);
}
saveMatrix(qm);
- reduced = F4MatrixReducer(basis.ring()).reduce(qm);
+ reduced = F4MatrixReducer(basis.ring().charac()).
+ reducedRowEchelonFormBottomRight(qm);
monomials = std::move(qm.rightColumnMonomials);
for (auto it = qm.leftColumnMonomials.begin();
it != qm.leftColumnMonomials.end(); ++it)
diff --git a/src/test/F4MatrixReducer.cpp b/src/test/F4MatrixReducer.cpp
index 527d911..4b44f26 100755
--- a/src/test/F4MatrixReducer.cpp
+++ b/src/test/F4MatrixReducer.cpp
@@ -116,7 +116,8 @@ TEST(F4MatrixReducer, Reduce) {
ASSERT_EQ(origStr, m.toString()) << "Printed m:\n" << m;
- SparseMatrix reduced(F4MatrixReducer(*ring).reduce(m));
+ SparseMatrix reduced
+ (F4MatrixReducer(ring->charac()).reducedRowEchelonFormBottomRight(m));
const char* redStr =
"0: 0#1 2#4 3#22 4#11\n"
--
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