[mathicgb] 63/393: Made SparseMatrix require explicit addition of new columns.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:33 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 854719261c975b54deb1d4b415398a0a1361f8a3
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Tue Oct 16 15:48:30 2012 +0200
Made SparseMatrix require explicit addition of new columns.
---
build/vs12/mathicgb.sln | 5 +++++
src/mathicgb/F4MatrixReducer.cpp | 2 +-
src/mathicgb/QuadMatrixBuilder.cpp | 6 ++++--
src/mathicgb/SparseMatrix.hpp | 29 ++++++++++++++++-------------
src/test/SparseMatrix.cpp | 16 +++++++++-------
5 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/build/vs12/mathicgb.sln b/build/vs12/mathicgb.sln
index ad9225a..4f3edce 100755
--- a/build/vs12/mathicgb.sln
+++ b/build/vs12/mathicgb.sln
@@ -21,6 +21,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "memtailor-lib", "..\..\..\m
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mathic-lib", "..\..\..\mathic\build\vs12\mathic-lib\mathic-lib.vcxproj", "{BEBD36F1-A124-4C01-8E67-3208D4472661}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D819684E-8488-4F68-A901-5108A6DDE925}"
+ ProjectSection(SolutionItems) = preProject
+ Performance1.psess = Performance1.psess
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
diff --git a/src/mathicgb/F4MatrixReducer.cpp b/src/mathicgb/F4MatrixReducer.cpp
index b74f312..2fdc299 100755
--- a/src/mathicgb/F4MatrixReducer.cpp
+++ b/src/mathicgb/F4MatrixReducer.cpp
@@ -324,7 +324,7 @@ void myReduce
DenseRow<uint64> denseRow;
#endif
- SparseMatrix tmp;
+ SparseMatrix tmp(pivotCount);
std::vector<SparseMatrix::RowIndex> rowOrder(rowCount);
diff --git a/src/mathicgb/QuadMatrixBuilder.cpp b/src/mathicgb/QuadMatrixBuilder.cpp
index 7c20002..d2abc1e 100755
--- a/src/mathicgb/QuadMatrixBuilder.cpp
+++ b/src/mathicgb/QuadMatrixBuilder.cpp
@@ -47,8 +47,10 @@ namespace {
}
toMonomial.back() = copied;
- top.ensureAtLeastThisManyColumns(colCount + 1);
- bottom.ensureAtLeastThisManyColumns(colCount + 1);
+ top.appendColumn();
+ MATHICGB_ASSERT(top.colCount() == colCount + 1);
+ bottom.appendColumn();
+ MATHICGB_ASSERT(bottom.colCount() == colCount + 1);
return QuadMatrixBuilder::LeftRightColIndex(colCount, left);
}
}
diff --git a/src/mathicgb/SparseMatrix.hpp b/src/mathicgb/SparseMatrix.hpp
index 0a13d57..bb6b980 100755
--- a/src/mathicgb/SparseMatrix.hpp
+++ b/src/mathicgb/SparseMatrix.hpp
@@ -2,6 +2,7 @@
#define MATHICGB_SPARSE_MATRIX_GUARD
#include "PolyRing.hpp"
+#include <mathic.h>
#include <vector>
#include <ostream>
#include <limits>
@@ -36,11 +37,6 @@ Currently this is not a template class so you can get by without
using the typedefs offered, for example using uint16 instead of
SparseMatrix::Scalar. Please use the typedefs to make it easier to
support a wider range of types of matrices in future.
-
-There is no need to specify the number of columns ahead of time. Any
-column index within the range of the ColIndex type can be used. The
-SparseMatrix automatically keeps track of the number of columns in the
-matrix.
*/
class SparseMatrix {
public:
@@ -91,8 +87,8 @@ class SparseMatrix {
mColCount -= trimThisMany;
}
- /** Construct a new zero by zero sparse matrix. */
- SparseMatrix(): mColCount(0) {
+ /** Construct a matrix with no rows and colCount columns. */
+ SparseMatrix(ColIndex colCount = 0): mColCount(colCount) {
mRowOffsets.push_back(0);
}
@@ -142,12 +138,10 @@ class SparseMatrix {
after calling this method until rowDone has been called. */
void appendEntry(ColIndex colIndex, Scalar scalar) {
MATHICGB_ASSERT(mColIndices.size() == mEntries.size());
- MATHICGB_ASSERT(colIndex < std::numeric_limits<ColIndex>::max());
+ MATHICGB_ASSERT(colIndex < colCount());
mColIndices.push_back(colIndex);
mEntries.push_back(scalar);
- if (colIndex + 1 > mColCount)
- mColCount = colIndex + 1;
MATHICGB_ASSERT(mColIndices.size() == mEntries.size());
}
@@ -215,9 +209,9 @@ class SparseMatrix {
}
void swap(SparseMatrix& matrix) {
- mColIndices.swap(matrix.mColIndices);
- mEntries.swap(matrix.mEntries);
- mRowOffsets.swap(matrix.mRowOffsets);
+ std::swap(mColIndices, matrix.mColIndices);
+ std::swap(mEntries, matrix.mEntries);
+ std::swap(mRowOffsets, matrix.mRowOffsets);
std::swap(mColCount, matrix.mColCount);
}
@@ -272,6 +266,15 @@ class SparseMatrix {
mColCount = count;
}
+ /** Adds one more column to the matrix and returns the index of the new
+ column. */
+ ColIndex appendColumn() {
+ if (colCount() == std::numeric_limits<ColIndex>::max())
+ mathic::reportError("Too many columns in SparseMatrix.");
+ ++mColCount;
+ return mColCount - 1;
+ }
+
void appendRowWithModulus(std::vector<uint64> const& v, Scalar modulus) {
MATHICGB_ASSERT(v.size() == colCount());
ColIndex count = colCount();
diff --git a/src/test/SparseMatrix.cpp b/src/test/SparseMatrix.cpp
index 073d3b0..0eba726 100755
--- a/src/test/SparseMatrix.cpp
+++ b/src/test/SparseMatrix.cpp
@@ -25,13 +25,14 @@ TEST(SparseMatrix, NoRows) {
}
TEST(SparseMatrix, Simple) {
- SparseMatrix mat;
+ SparseMatrix mat(2000);
+ mat.appendColumn();
mat.appendEntry(5, 101);
mat.rowDone();
ASSERT_EQ(1, mat.entryCount());
ASSERT_EQ(1, mat.rowCount());
- ASSERT_EQ(6, mat.colCount());
+ ASSERT_EQ(2001, mat.colCount());
ASSERT_EQ(5, mat.leadCol(0));
ASSERT_EQ(1, mat.entryCountInRow(0));
ASSERT_EQ("0: 5#101\n", mat.toString());
@@ -40,21 +41,22 @@ TEST(SparseMatrix, Simple) {
mat.rowDone(); // add a row with no entries
ASSERT_EQ(1, mat.entryCount());
ASSERT_EQ(2, mat.rowCount());
- ASSERT_EQ(6, mat.colCount());
+ ASSERT_EQ(2001, mat.colCount());
ASSERT_EQ(5, mat.leadCol(0));
ASSERT_EQ(0, mat.entryCountInRow(1));
ASSERT_EQ("0: 5#101\n1:\n", mat.toString());
ASSERT_TRUE(mat.emptyRow(1));
mat.appendEntry(5, 102);
- mat.appendEntry(2000, 0); // scalar zero
+ mat.appendColumn();
+ mat.appendEntry(2001, 0); // scalar zero
mat.rowDone(); // add a row with two entries
ASSERT_EQ(3, mat.entryCount());
ASSERT_EQ(3, mat.rowCount());
- ASSERT_EQ(2001, mat.colCount());
+ ASSERT_EQ(2002, mat.colCount());
ASSERT_EQ(5, mat.leadCol(2));
ASSERT_EQ(2, mat.entryCountInRow(2));
- ASSERT_EQ("0: 5#101\n1:\n2: 5#102 2000#0\n", mat.toString());
+ ASSERT_EQ("0: 5#101\n1:\n2: 5#102 2001#0\n", mat.toString());
ASSERT_FALSE(mat.emptyRow(2));
}
@@ -65,7 +67,7 @@ TEST(SparseMatrix, toRow) {
for (auto it = polyForMonomials->begin(); it != polyForMonomials->end(); ++it)
monomials.push_back(it.getMonomial());
- SparseMatrix mat;
+ SparseMatrix mat(5);
mat.clear(6);
mat.rowDone();
mat.appendEntry(0,10);
--
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