moving the definition of the function Compress

parent ff2283d7
......@@ -471,4 +471,33 @@ void ReadRowMajMat(std::shared_ptr<RowMajMat> *pR, const std::string& filename)
delete[] memblock_begin;
}
void
Compress(std::shared_ptr<RowMajMat> D, std::shared_ptr<RowMajMat> B, std::list<std::size_t> &pivots) {
assert(D->col_dec_ == B->col_dec_);
assert(!B->col_dec_.empty() || !B->column_size());
std::vector<Monomial> non_pivot_monomials;
pivots.sort();
std::list<std::size_t>::const_iterator it = pivots.begin();
for (std::size_t i = 0; i < B->col_dec_.size(); ++i)
if ((i != *it) || (it == pivots.end()))
non_pivot_monomials.push_back(B->col_dec_[i]);
else
it++;
if (D != nullptr)
{
for (const auto& it : pivots)
D->row_dec_.push_back(D->col_dec_[it]);
D->Compress();
D->RemoveColumns(pivots);
}
if (B != nullptr)
B->RemoveColumns(pivots);
B->col_dec_ = non_pivot_monomials;
D->col_dec_ = non_pivot_monomials;
}
} // namespace tinygb
......@@ -106,6 +106,9 @@ class RowMajMat {
void WriteRowMajMat(const RowMajMat& M, const std::string& filename);
void ReadRowMajMat(std::shared_ptr<RowMajMat> *pR, const std::string& filename);
void
Compress(std::shared_ptr<RowMajMat> D, std::shared_ptr<RowMajMat> B, std::list<std::size_t> &pivots);
} // namespace tinygb
#endif
......@@ -9,35 +9,6 @@
namespace tinygb {
void
Compress(std::shared_ptr<RowMajMat> D, std::shared_ptr<RowMajMat> B, std::list<std::size_t> &pivots) {
assert(D->col_dec_ == B->col_dec_);
assert(!B->col_dec_.empty() || !B->column_size());
std::vector<Monomial> non_pivot_monomials;
pivots.sort();
std::list<std::size_t>::const_iterator it = pivots.begin();
for (std::size_t i = 0; i < B->col_dec_.size(); ++i)
if ((i != *it) || (it == pivots.end()))
non_pivot_monomials.push_back(B->col_dec_[i]);
else
it++;
if (D != nullptr)
{
for (const auto& it : pivots)
D->row_dec_.push_back(D->col_dec_[it]);
D->Compress();
D->RemoveColumns(pivots);
}
if (B != nullptr)
B->RemoveColumns(pivots);
B->col_dec_ = non_pivot_monomials;
D->col_dec_ = non_pivot_monomials;
}
// Compute the row echelon form of D, and reduce B accordingly.
void
rowech(std::string resD_file, std::string resB_file,
......
......@@ -31,15 +31,11 @@ std::shared_ptr<const StorageMatrix> Interreduce(const std::vector<Polynomial>&
B->col_dec_ = v;
D->col_dec_ = v;
WriteRowMajMat(*D, "matD");
WriteRowMajMat(*B, "matB");
// This should probably not be called from inside the function
// It should probably be a function call to the row echelon function
std::system(("build/rowech/rowech " + WORKDIR + " matD2 matB2 matD matB").c_str());
std::list<std::size_t> pivots;
D->RowEchelon(B, pivots);
ReadRowMajMat(&D, "matD2");
ReadRowMajMat(&B, "matB2");
Compress(D, B, pivots);
auto p_current_storage_matrix = std::make_shared<const StorageMatrix>(D, D->col_dec_, D->row_dec_, "interreduced_system");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment