Skip to content

Commit

Permalink
factorize unordered_set and vector columns
Browse files Browse the repository at this point in the history
  • Loading branch information
hschreiber committed Oct 4, 2023
1 parent 76fc0ba commit 97cc289
Show file tree
Hide file tree
Showing 14 changed files with 3,445 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Chain_matrix
bool is_zero_column(index columnIndex) const; //just for sanity checks as a valid chain matrix never has an empty column.

index get_column_with_pivot(index simplexIndex) const;
index get_pivot(index columnIndex) const;
index get_pivot(index columnIndex);

Chain_matrix& operator=(const Chain_matrix& other);
friend void swap(Chain_matrix& matrix1,
Expand Down Expand Up @@ -559,7 +559,7 @@ inline typename Chain_matrix<Master_matrix>::index Chain_matrix<Master_matrix>::
}

template<class Master_matrix>
inline typename Chain_matrix<Master_matrix>::index Chain_matrix<Master_matrix>::get_pivot(index columnIndex) const
inline typename Chain_matrix<Master_matrix>::index Chain_matrix<Master_matrix>::get_pivot(index columnIndex)
{
if constexpr (Master_matrix::Option_list::has_removable_columns){
return matrix_.at(columnIndex).get_pivot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Chain_vine_swap : public std::conditional<
BirthCompFuncPointer birthComp_; // for F x F & H x H
DeathCompFuncPointer deathComp_; // for G x G

bool _is_negative_in_pair(index columnIndex) const;
bool _is_negative_in_pair(index columnIndex);

index _positive_vine_swap(index columnIndex1, index columnIndex2);
index _positive_negative_vine_swap(index columnIndex1, index columnIndex2);
Expand Down Expand Up @@ -363,7 +363,7 @@ inline Chain_vine_swap<Master_matrix> &Chain_vine_swap<Master_matrix>::operator=
}

template<class Master_matrix>
inline bool Chain_vine_swap<Master_matrix>::_is_negative_in_pair(index columnIndex) const
inline bool Chain_vine_swap<Master_matrix>::_is_negative_in_pair(index columnIndex)
{
if constexpr (Master_matrix::Option_list::has_column_pairings){
return CP::is_negative_in_pair(_matrix()->get_pivot(columnIndex));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Intrusive_list_column : public Master_matrix::Row_access_option,
std::vector<Field_element_type> get_content(int columnLength = -1) const;
bool is_non_zero(index rowIndex) const;
bool is_empty() const;
std::size_t size() const;

//****************
//only for base and boundary
Expand Down Expand Up @@ -377,6 +378,9 @@ Intrusive_list_column<Master_matrix>::get_content(int columnLength) const
template<class Master_matrix>
inline bool Intrusive_list_column<Master_matrix>::is_non_zero(index rowIndex) const
{
//could be changed to dichotomic search as column is ordered by row index,
//but I am not sure if it is really worth it as there is no random access
//and the columns should not be that long anyway.
for (const Cell& cell : column_)
if (cell.get_row_index() == rowIndex) return true;

Expand All @@ -389,6 +393,11 @@ inline bool Intrusive_list_column<Master_matrix>::is_empty() const
return column_.empty();
}

template<class Master_matrix>
inline std::size_t Intrusive_list_column<Master_matrix>::size() const{
return column_.size();
}

template<class Master_matrix>
template<class Map_type>
inline void Intrusive_list_column<Master_matrix>::reorder(const Map_type &valueMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Intrusive_set_column : public Master_matrix::Row_access_option,
std::vector<Field_element_type> get_content(int columnLength = -1) const;
bool is_non_zero(index rowIndex) const;
bool is_empty() const;
std::size_t size() const;

//****************
//only for base and boundary
Expand Down Expand Up @@ -387,6 +388,11 @@ inline bool Intrusive_set_column<Master_matrix>::is_empty() const
return column_.empty();
}

template<class Master_matrix>
inline std::size_t Intrusive_set_column<Master_matrix>::size() const{
return column_.size();
}

template<class Master_matrix>
template<class Map_type>
inline void Intrusive_set_column<Master_matrix>::reorder(const Map_type &valueMap)
Expand Down Expand Up @@ -417,14 +423,15 @@ inline void Intrusive_set_column<Master_matrix>::reorder(const Map_type &valueMa
}
}
} else {
for (auto it = column_.begin(); it != column_.end(); ++it) {
for (auto it = column_.begin(); it != column_.end(); ) {
Cell *new_cell;
if constexpr (Master_matrix::Option_list::is_z2){
new_cell = cellPool_.construct(valueMap.at(it->get_row_index()));
} else {
new_cell = cellPool_.construct(it->get_element(), valueMap.at(it->get_row_index()));
}
newSet.insert(newSet.end(), *new_cell);
_delete_cell(it); //increases it
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class List_column : public Master_matrix::Row_access_option,
std::vector<Field_element_type> get_content(int columnLength = -1) const;
bool is_non_zero(index rowIndex) const;
bool is_empty() const;
std::size_t size() const;

//****************
//only for base and boundary
Expand Down Expand Up @@ -370,6 +371,9 @@ List_column<Master_matrix>::get_content(int columnLength) const
template<class Master_matrix>
inline bool List_column<Master_matrix>::is_non_zero(index rowIndex) const
{
//could be changed to dichotomic search as column is ordered by row index,
//but I am not sure if it is really worth it as there is no random access
//and the columns should not be that long anyway.
for (const Cell* cell : column_)
if (cell->get_row_index() == rowIndex) return true;

Expand All @@ -382,6 +386,11 @@ inline bool List_column<Master_matrix>::is_empty() const
return column_.empty();
}

template<class Master_matrix>
inline std::size_t List_column<Master_matrix>::size() const{
return column_.size();
}

template<class Master_matrix>
template<class Map_type>
inline void List_column<Master_matrix>::reorder(const Map_type &valueMap)
Expand Down Expand Up @@ -779,7 +788,7 @@ inline bool List_column<Master_matrix>::_add(const Cell_range &column)
{
if (column.begin() == column.end()) return false;
if (column_.empty()){ //chain should never enter here.
column_.resize(column.column_.size());
column_.resize(column.size());
auto it = column_.begin();
for (const Cell& cell : column){
if constexpr (Master_matrix::Option_list::is_z2){
Expand Down
Loading

0 comments on commit 97cc289

Please sign in to comment.