From d562e20d5faa3a3b467b0006d405309d9c47581c Mon Sep 17 00:00:00 2001 From: Pierre-Jean Spaenlehauer Date: Tue, 21 Jul 2020 14:59:09 +0200 Subject: [PATCH] moving the definition of the function Compress --- src/matrices/rowmajmat.cc | 29 +++++++++++++++++++++++++++++ src/matrices/rowmajmat.h | 3 +++ src/rowech/rowech.cc | 29 ----------------------------- src/tinygb_init/tinygb_init.cc | 12 ++++-------- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/matrices/rowmajmat.cc b/src/matrices/rowmajmat.cc index 4b70d18..406cf01 100644 --- a/src/matrices/rowmajmat.cc +++ b/src/matrices/rowmajmat.cc @@ -471,4 +471,33 @@ void ReadRowMajMat(std::shared_ptr *pR, const std::string& filename) delete[] memblock_begin; } +void +Compress(std::shared_ptr D, std::shared_ptr B, std::list &pivots) { + assert(D->col_dec_ == B->col_dec_); + assert(!B->col_dec_.empty() || !B->column_size()); + + std::vector non_pivot_monomials; + + pivots.sort(); + + std::list::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 diff --git a/src/matrices/rowmajmat.h b/src/matrices/rowmajmat.h index 2c0acd5..25ba0f6 100644 --- a/src/matrices/rowmajmat.h +++ b/src/matrices/rowmajmat.h @@ -106,6 +106,9 @@ class RowMajMat { void WriteRowMajMat(const RowMajMat& M, const std::string& filename); void ReadRowMajMat(std::shared_ptr *pR, const std::string& filename); +void +Compress(std::shared_ptr D, std::shared_ptr B, std::list &pivots); + } // namespace tinygb #endif diff --git a/src/rowech/rowech.cc b/src/rowech/rowech.cc index 542593a..b4c2aac 100644 --- a/src/rowech/rowech.cc +++ b/src/rowech/rowech.cc @@ -9,35 +9,6 @@ namespace tinygb { -void -Compress(std::shared_ptr D, std::shared_ptr B, std::list &pivots) { - assert(D->col_dec_ == B->col_dec_); - assert(!B->col_dec_.empty() || !B->column_size()); - - std::vector non_pivot_monomials; - - pivots.sort(); - - std::list::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, diff --git a/src/tinygb_init/tinygb_init.cc b/src/tinygb_init/tinygb_init.cc index b90db57..8bcbdf2 100644 --- a/src/tinygb_init/tinygb_init.cc +++ b/src/tinygb_init/tinygb_init.cc @@ -31,15 +31,11 @@ std::shared_ptr Interreduce(const std::vector& 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 pivots; + + D->RowEchelon(B, pivots); - ReadRowMajMat(&D, "matD2"); - ReadRowMajMat(&B, "matB2"); + Compress(D, B, pivots); auto p_current_storage_matrix = std::make_shared(D, D->col_dec_, D->row_dec_, "interreduced_system"); -- GitLab