Skip to content

Commit

Permalink
change of heap column == and > operators
Browse files Browse the repository at this point in the history
  • Loading branch information
hschreiber committed Jun 13, 2024
1 parent c207e6e commit 8b10f70
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_
std::vector<Column_type*> repToColumn_; /**< Map from the representative index to
the representative Column. */
index nextColumnIndex_; /**< Next unused column index. */
Column_settings* colSettings_; /**< Cell factory. */
Column_settings* colSettings_; /**< Cell factory. */
/**
* @brief Column factory.
* @warning As the member is static, they can eventually be problems if the matrix is duplicated in several threads.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,42 @@ class Heap_column : public Master_matrix::Column_dimension_option, public Master

friend bool operator==(const Heap_column& c1, const Heap_column& c2) {
if (&c1 == &c2) return true;
return c1.get_content() == c2.get_content();

Heap_column cc1(c1), cc2(c2);
Cell* p1 = cc1._pop_pivot();
Cell* p2 = cc2._pop_pivot();
while (p1 != nullptr && p2 != nullptr) {
if (p1->get_row_index() != p2->get_row_index()) return false;
if constexpr (!Master_matrix::Option_list::is_z2){
if (p1->get_element() != p2->get_element()) return false;
}
p1 = cc1._pop_pivot();
p2 = cc2._pop_pivot();
}

if (p1 == nullptr && p2 == nullptr) return true;
return false;
}
friend bool operator<(const Heap_column& c1, const Heap_column& c2) {
if (&c1 == &c2) return false;

auto cont1 = c1.get_content();
auto cont2 = c2.get_content();

auto it1 = cont1.begin();
auto it2 = cont2.begin();
while (it1 != cont1.end() && it2 != cont2.end()) {
if (*it1 == 0u && *it2 != 0u) return false;
if (*it1 != 0u && *it2 == 0u) return true;
if (*it1 != *it2) return *it1 < *it2;
++it1;
++it2;
//lexicographical order but starting from last value and not first
Heap_column cc1(c1), cc2(c2);
Cell* p1 = cc1._pop_pivot();
Cell* p2 = cc2._pop_pivot();
while (p1 != nullptr && p2 != nullptr) {
if (p1->get_row_index() > p2->get_row_index()) return false;
if (p1->get_row_index() < p2->get_row_index()) return true;
if constexpr (!Master_matrix::Option_list::is_z2){
if (p1->get_element() > p2->get_element()) return false;
if (p1->get_element() < p2->get_element()) return true;
}
p1 = cc1._pop_pivot();
p2 = cc2._pop_pivot();
}
return it2 != cont2.end();

if (p2 == nullptr) return false;
return true;
}

// Disabled with row access.
Expand Down
33 changes: 27 additions & 6 deletions src/Persistence_matrix/test/pm_column_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ void column_test_common_z5_operators(std::vector<Column> &matrix){
BOOST_CHECK(matrix[1] == matrix[1]);
BOOST_CHECK(matrix[1] == matrix[3]);
BOOST_CHECK(matrix[1] < matrix[0]);
BOOST_CHECK(matrix[2] < matrix[0]);
if constexpr (Column::Master::Option_list::column_type == Column_types::HEAP){
BOOST_CHECK(matrix[0] < matrix[2]); //order different for heap columns
} else {
BOOST_CHECK(matrix[2] < matrix[0]);
}
BOOST_CHECK(!(matrix[0] < matrix[0]));

matrix[0] *= 4;
Expand All @@ -445,7 +449,11 @@ void column_test_common_z5_operators(std::vector<Column> &matrix){
BOOST_CHECK(matrix[1] == matrix[1]);
BOOST_CHECK(matrix[1] == matrix[3]);
BOOST_CHECK(matrix[1] < matrix[0]);
BOOST_CHECK(matrix[2] < matrix[0]);
if constexpr (Column::Master::Option_list::column_type == Column_types::HEAP){
BOOST_CHECK(matrix[0] < matrix[2]); //order different for heap columns
} else {
BOOST_CHECK(matrix[2] < matrix[0]);
}
BOOST_CHECK(!(matrix[0] < matrix[0]));

//this = v * this + column
Expand All @@ -472,8 +480,13 @@ void column_test_common_z5_operators(std::vector<Column> &matrix){
BOOST_CHECK(!(matrix[5] == matrix[4]));
BOOST_CHECK(!(matrix[5] < matrix[3]));
BOOST_CHECK(!(matrix[3] < matrix[5]));
BOOST_CHECK(matrix[5] < matrix[4]);
BOOST_CHECK(matrix[3] < matrix[4]);
if constexpr (Column::Master::Option_list::column_type == Column_types::HEAP){
BOOST_CHECK(matrix[4] < matrix[5]);
BOOST_CHECK(matrix[4] < matrix[3]);
} else {
BOOST_CHECK(matrix[5] < matrix[4]);
BOOST_CHECK(matrix[3] < matrix[4]);
}
}

//assumes that matrix was build with build_column_matrix and was not modified since.
Expand All @@ -491,7 +504,11 @@ void column_test_common_z2_operators(std::vector<Column> &matrix){
BOOST_CHECK(matrix[1] == matrix[1]);
BOOST_CHECK(matrix[1] == matrix[3]);
BOOST_CHECK(matrix[1] < matrix[0]);
BOOST_CHECK(matrix[2] < matrix[0]);
if constexpr (Column::Master::Option_list::column_type == Column_types::HEAP){
BOOST_CHECK(matrix[0] < matrix[2]); //order different for heap columns
} else {
BOOST_CHECK(matrix[2] < matrix[0]);
}
BOOST_CHECK(!(matrix[0] < matrix[0]));

matrix[0] *= 5;
Expand All @@ -506,7 +523,11 @@ void column_test_common_z2_operators(std::vector<Column> &matrix){
BOOST_CHECK(!(matrix[0] == matrix[2]));
BOOST_CHECK(matrix[2] == matrix[2]);
BOOST_CHECK(matrix[1] < matrix[0]);
BOOST_CHECK(matrix[2] < matrix[0]);
if constexpr (Column::Master::Option_list::column_type == Column_types::HEAP){
BOOST_CHECK(matrix[0] < matrix[2]); //order different for heap columns
} else {
BOOST_CHECK(matrix[2] < matrix[0]);
}
BOOST_CHECK(!(matrix[0] < matrix[0]));

//this = v * this + column
Expand Down

0 comments on commit 8b10f70

Please sign in to comment.