[mathicgb] 132/393: Improved the logging output of reducing matrices. It now contains much more information, the information is more clearly labeled and it looks nicer.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:48 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 1d0631583e571ed55b6697a25f5cdfa97760e2fb
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Fri Dec 21 21:40:32 2012 +0100
Improved the logging output of reducing matrices. It now contains much more information, the information is more clearly labeled and it looks nicer.
---
src/mathicgb/F4MatrixReducer.cpp | 14 +++----
src/mathicgb/QuadMatrix.cpp | 85 +++++++++++++++++++++-------------------
src/mathicgb/QuadMatrix.hpp | 4 +-
src/mathicgb/SparseMatrix.cpp | 46 ++++++++++++++++++++++
src/mathicgb/SparseMatrix.hpp | 21 +++++-----
5 files changed, 109 insertions(+), 61 deletions(-)
diff --git a/src/mathicgb/F4MatrixReducer.cpp b/src/mathicgb/F4MatrixReducer.cpp
index 739cbdb..d64f6bf 100644
--- a/src/mathicgb/F4MatrixReducer.cpp
+++ b/src/mathicgb/F4MatrixReducer.cpp
@@ -253,9 +253,6 @@ namespace {
const SparseMatrix& toReduce,
const SparseMatrix::Scalar modulus
) {
- MATHICGB_LOG_TIME(F4MatrixReduce) <<
- "Reducing matrix to row echelon form\n";
-
const auto colCount = toReduce.computeColCount();
const auto rowCount = toReduce.rowCount();
@@ -590,18 +587,21 @@ SparseMatrix reduceToEchelonFormShrawanDelayedModulus(
return std::move(reduced);
}
-#define STR2(X) #X
-#define STR(X) STR2(X)
SparseMatrix F4MatrixReducer::reduceToBottomRight(const QuadMatrix& matrix) {
- std::cout << STR(MATHICGB_LOG_TIME(F4MatrixReduce)) << std::endl;
MATHICGB_ASSERT(matrix.debugAssertValid());
- MATHICGB_IF_LOG(F4MatrixReduce) {matrix.printSizes(log.stream());};
+ MATHICGB_LOG_TIME(F4MatrixReduce) <<
+ "\n***** Reducing QuadMatrix to bottom right matrix *****\n";
+ MATHICGB_IF_LOG(F4MatrixReduce) {matrix.printStatistics(log.stream());};
return reduce(matrix, mModulus);
}
SparseMatrix F4MatrixReducer::reducedRowEchelonForm(
const SparseMatrix& matrix
) {
+ MATHICGB_LOG_TIME(F4MatrixReduce) <<
+ "\n***** Reducing SparseMatrix to reduced row echelon form *****\n";
+ MATHICGB_IF_LOG(F4MatrixReduce) {matrix.printStatistics(log.stream());};
+
const bool useShrawan = false;
const bool useDelayedModulus = false;
if (useShrawan) {
diff --git a/src/mathicgb/QuadMatrix.cpp b/src/mathicgb/QuadMatrix.cpp
index 68c3a19..041e425 100755
--- a/src/mathicgb/QuadMatrix.cpp
+++ b/src/mathicgb/QuadMatrix.cpp
@@ -110,59 +110,62 @@ size_t QuadMatrix::memoryUseTrimmed() const {
bottomLeft.memoryUseTrimmed() + bottomRight.memoryUseTrimmed();
}
-void QuadMatrix::printSizes(std::ostream& out) const {
+void QuadMatrix::printStatistics(std::ostream& out) const {
typedef mathic::ColumnPrinter ColPr;
ColPr pr;
pr.addColumn(false, " ", "");
pr.addColumn(false, "", "");
pr.addColumn(false, "", "");
- const char* const line = "----------";
-
- pr[0] << '\n';
- pr[1] << ColPr::commafy(computeLeftColCount()) << " \n";
- pr[2] << ColPr::commafy(computeRightColCount()) << " \n";
-
- pr[0] << "/\n";
- pr[1] << line << "|\n";
- pr[2] << line << "\\\n";
-
- pr[0] << ColPr::commafy(topLeft.rowCount()) << " |\n";
- pr[1] << ColPr::commafy(topLeft.entryCount()) << " |\n";
- pr[2] << ColPr::commafy(topRight.entryCount()) << " |\n";
-
- pr[0] << "|\n";
- pr[1] << ColPr::bytesInUnit(topLeft.memoryUse()) << " |\n";
- pr[2] << ColPr::bytesInUnit(topRight.memoryUse()) << " |\n";
-
- pr[0] << "|\n";
- pr[1] << ColPr::percent(topLeft.memoryUse(), memoryUse()) << " |\n";
- pr[2] << ColPr::percent(topRight.memoryUse(), memoryUse()) << " |\n";
-
- pr[0] << "|\n";
- pr[1] << line << "|\n";
- pr[2] << line << "|\n";
+ pr.addColumn(false, "", "");
+ pr.addColumn(true, "", "");
- pr[0] << ColPr::commafy(bottomLeft.rowCount()) << " |\n";
- pr[1] << ColPr::commafy(bottomLeft.entryCount()) << " |\n";
- pr[2] << ColPr::commafy(bottomRight.entryCount()) << " |\n";
+ const auto totalMemory = memoryUse();
- pr[0] << "|\n";
- pr[1] << ColPr::bytesInUnit(bottomLeft.memoryUse()) << " |\n";
- pr[2] << ColPr::bytesInUnit(bottomRight.memoryUse()) << " |\n";
+ auto printDataCol = [&](
+ std::ostream& out,
+ const SparseMatrix& top,
+ const SparseMatrix& bottom,
+ const SparseMatrix::ColIndex colCount
+ ) {
+ auto printDataCell = [&](const SparseMatrix& matrix) {
+ const auto entryCount = matrix.entryCount();
+ const uint64 area =
+ static_cast<uint64>(matrix.rowCount()) * static_cast<uint64>(colCount);
+ const auto memory = matrix.memoryUse();
+
+ out << ColPr::withSIPrefix(entryCount) << " -"
+ << ColPr::percentFixed(entryCount, area) << " \n"
+ << ColPr::bytesInUnit(memory) << " -"
+ << ColPr::percentFixed(matrix.memoryUseTrimmed(), memory) << " \n"
+ << ColPr::percent(memory, totalMemory) << " \n";
+ };
+
+ out << ColPr::commafy(colCount) << " \n";
+ const char* const line = "------------------\n";
+ out << line;
+ printDataCell(top);
+ out << line;
+ printDataCell(bottom);
+ out << line;
+ };
- pr[0] << "|\n";
- pr[1] << ColPr::percent(bottomLeft.memoryUse(), memoryUse()) << " |\n";
- pr[2] << ColPr::percent(bottomRight.memoryUse(), memoryUse()) << " |\n";
+ pr[0] << "\n/\n" << ColPr::commafy(topLeft.rowCount())
+ << " |\nrows |\n|\n|\n"
+ << ColPr::commafy(bottomLeft.rowCount())
+ << " |\nrows |\n|\n\\\n";
+ printDataCol(pr[1], topLeft, bottomLeft, computeLeftColCount());
+ pr[2] << " \n|\n|\n|\n|\n|\n|\n|\n|\n|\n";
+ printDataCol(pr[3], topRight, bottomRight, computeRightColCount());
- pr[0] << "\\\n";
- pr[1] << line << "|\n";
- pr[2] << line << "/\n";
+ const char* const legend =
+ "| non-zero (density)\n| memory (used)\n| of total memory\n";
+ pr[4] << " columns\n\\\n" << legend << "|\n" << legend << "/\n";
out << '\n' << pr
- << "Total memory: " << ColPr::bytesInUnit(memoryUse()) << " ("
- << ColPr::percent(memoryUseTrimmed(), memoryUse())
- << " in use)\n";
+ << " Total memory: " << ColPr::bytesInUnit(memoryUse()) << " ("
+ << ColPr::percent(memoryUseTrimmed(), totalMemory)
+ << " used)\n\n";
}
QuadMatrix QuadMatrix::toCanonical() const {
diff --git a/src/mathicgb/QuadMatrix.hpp b/src/mathicgb/QuadMatrix.hpp
index 8d27911..fad45a7 100755
--- a/src/mathicgb/QuadMatrix.hpp
+++ b/src/mathicgb/QuadMatrix.hpp
@@ -45,9 +45,7 @@ public:
/// debugging.
void print(std::ostream& out) const;
- /// Prints the sizes of the matrix out, in terms of number of rows and
- /// columns and how many non-zero entries in each submatrix.
- void printSizes(std::ostream& out) const;
+ void printStatistics(std::ostream& out) const;
size_t memoryUse() const;
size_t memoryUseTrimmed() const;
diff --git a/src/mathicgb/SparseMatrix.cpp b/src/mathicgb/SparseMatrix.cpp
index 895247c..01fad1c 100755
--- a/src/mathicgb/SparseMatrix.cpp
+++ b/src/mathicgb/SparseMatrix.cpp
@@ -95,6 +95,37 @@ void SparseMatrix::print(std::ostream& out) const {
}
}
+void SparseMatrix::printStatistics(std::ostream& out) const {
+ typedef mathic::ColumnPrinter ColPr;
+
+ ColPr pr;
+ pr.addColumn(false, " ", "");
+ pr.addColumn(false, "", "");
+ pr.addColumn(true, "", "");
+
+ const auto memory = memoryUse();
+ const auto colCount = computeColCount();
+ const auto entryCount = this->entryCount();
+ const uint64 area =
+ static_cast<uint64>(rowCount()) * static_cast<uint64>(colCount);
+
+ pr[0] << "\n/\n" << ColPr::commafy(rowCount())
+ << " |\nrows |\n\\\n";
+
+ const char* const line = "------------------\n";
+ pr[1] << ColPr::commafy(colCount) << " \n"
+ << line
+ << ColPr::withSIPrefix(entryCount) << " -"
+ << ColPr::percentFixed(entryCount, area) << " \n"
+ << ColPr::bytesInUnit(memory) << " -"
+ << ColPr::percentFixed(memoryUseTrimmed(), memory) << " \n"
+ << line;
+
+ pr[2] << " columns\n\\\n| non-zero (density)\n| memory (used)\n/\n";
+
+ out << '\n' << pr << "\n";
+}
+
std::string SparseMatrix::toString() const {
std::ostringstream out;
print(out);
@@ -351,6 +382,21 @@ void SparseMatrix::growEntryCapacity() {
MATHICGB_ASSERT(mBlock.mColIndices.size() == mBlock.mScalars.size());
}
+float SparseMatrix::computeDensity() const {
+ const auto rowCount = static_cast<float>(this->rowCount());
+ const auto colCount = static_cast<float>(computeColCount());
+ const auto entryCount = static_cast<float>(this->entryCount());
+ return entryCount / (rowCount * colCount);
+}
+
+size_t SparseMatrix::entryCount() const {
+ size_t count = 0;
+ const Block* block = &mBlock;
+ for (; block != 0; block = block->mPreviousBlock)
+ count += block->mColIndices.size();
+ return count;
+}
+
size_t SparseMatrix::memoryUse() const {
size_t count = 0;
for (auto block = &mBlock; block != 0; block = block->mPreviousBlock)
diff --git a/src/mathicgb/SparseMatrix.hpp b/src/mathicgb/SparseMatrix.hpp
index af19b30..cc0212e 100755
--- a/src/mathicgb/SparseMatrix.hpp
+++ b/src/mathicgb/SparseMatrix.hpp
@@ -91,15 +91,14 @@ public:
ColIndex computeColCount() const;
size_t memoryQuantum() const {return mMemoryQuantum;}
+ /// Returns number of non-zero entries divide by the product of the number of
+ /// rows times the number of columns. So it is the proportion of non-zero
+ /// entries.
+ float computeDensity() const;
+
/// Returns the number of entries in the whole matrix. Is not constant time
/// so avoid calling too many times.
- size_t entryCount() const {
- size_t count = 0;
- const Block* block = &mBlock;
- for (; block != 0; block = block->mPreviousBlock)
- count += block->mColIndices.size();
- return count;
- }
+ size_t entryCount() const;
/// Returns the number of bytes of memory allocated by this object. Is not
/// constant time so avoid calling too many times.
@@ -141,11 +140,12 @@ public:
}
/// Prints the matrix in a human readable format to out.
+ /// Useful for debugging.
void print(std::ostream& out) const;
- std::string toString() const;
-
+ void printStatistics(std::ostream& out) const;
+ std::string toString() const;
/// Removes the leading trimThisMany columns. The columns are
/// removed by replacing all column indices col by col -
@@ -159,7 +159,8 @@ public:
/// free for this calculation.
void reserveFreeEntries(size_t freeCount);
- /// Preallocate space for at least count rows.
+ /// Preallocate space for at least count rows. This is separate from the
+ /// space to store the entries in those rows.
void reserveRows(size_t count) {mRows.reserve(count);}
/// Adds a new row that contains all terms that have been appended
--
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