Skip to content

Commit

Permalink
replaces assert with GUDHI_CHECK
Browse files Browse the repository at this point in the history
  • Loading branch information
hschreiber committed May 30, 2024
1 parent 45376f6 commit 3773d2c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ inline void Base_matrix<Master_matrix>::remove_last()
matrix_.erase(nextInsertIndex_);
} else {
if constexpr (Master_matrix::Option_list::has_row_access) {
assert(nextInsertIndex_ == matrix_.size() - 1 && "Indexation problem.");
GUDHI_CHECK(nextInsertIndex_ == matrix_.size() - 1,
std::logic_error("Base_matrix::remove_last - Indexation problem."));
matrix_.pop_back();
} else {
matrix_[nextInsertIndex_].clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ inline typename Boundary_matrix<Master_matrix>::index Boundary_matrix<Master_mat
}
}
if constexpr (Master_matrix::Option_list::has_row_access) {
assert(nextInsertIndex_ == matrix_.size() - 1 && "Indexation problem.");
GUDHI_CHECK(nextInsertIndex_ == matrix_.size() - 1,
std::logic_error("Boundary_matrix::remove_last - Indexation problem."));
matrix_.pop_back();
} else {
matrix_[nextInsertIndex_].clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <iostream> //print() only
#include <set>
#include <stdexcept>
#include <vector>
#include <utility> //std::swap, std::move & std::exchange
#include <algorithm> //std::sort
Expand Down Expand Up @@ -1311,7 +1312,8 @@ inline void Chain_matrix<Master_matrix>::_remove_last(index lastIndex)
pivotToColumnIndex_.erase(pivot);
matrix_.erase(itToErase);
} else {
assert(lastIndex == nextIndex_ - 1 && nextIndex_ == matrix_.size() && "Indexation problem.");
GUDHI_CHECK(lastIndex == nextIndex_ - 1 && nextIndex_ == matrix_.size(),
std::logic_error("Chain_matrix::_remove_last - Indexation problem."));

Column_type& colToErase = matrix_[lastIndex];
pivot = colToErase.get_pivot();
Expand Down Expand Up @@ -1344,7 +1346,10 @@ inline void Chain_matrix<Master_matrix>::_remove_last(index lastIndex)
}

if constexpr (Master_matrix::Option_list::has_row_access) {
assert(ra_opt::get_row(pivot).size() == 0 && "Column asked to be removed do not corresponds to a maximal simplex.");
GUDHI_CHECK(
ra_opt::get_row(pivot).size() == 0,
std::invalid_argument(
"Chain_matrix::_remove_last - Column asked to be removed does not corresponds to a maximal simplex."));
if constexpr (Master_matrix::Option_list::has_removable_rows) {
ra_opt::erase_empty_row(pivot);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <utility> //std::swap & std::move
#include <cassert>
#include <functional> //std::function
#include <stdexcept> //std::invalid_argument

#include "chain_pairing.h"

Expand Down Expand Up @@ -386,8 +387,9 @@ inline typename Chain_vine_swap<Master_matrix>::index Chain_vine_swap<Master_mat
index columnIndex2)
{
if constexpr (Master_matrix::Option_list::has_column_pairings) {
assert(CP::are_adjacent(_matrix()->get_pivot(columnIndex1), _matrix()->get_pivot(columnIndex2)) &&
"Columns to be swaped need to be adjacent in the 'real' matrix.");
GUDHI_CHECK(CP::are_adjacent(_matrix()->get_pivot(columnIndex1), _matrix()->get_pivot(columnIndex2)),
std::invalid_argument(
"Chain_vine_swap::vine_swap - Columns to be swaped need to be adjacent in the 'real' matrix."));
}

const bool col1IsNeg = _is_negative_in_pair(columnIndex1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ Intrusive_set_column<Master_matrix>::get_pivot_value() const
} else {
if (chain_opt::get_pivot() == static_cast<id_index>(-1)) return 0;
auto it = column_.find(Cell(chain_opt::get_pivot()));
GUDHI_CHECK(it != column_.end(), "Pivot not found only if the column was misused.");
GUDHI_CHECK(it != column_.end(),
"Intrusive_set_column::get_pivot_value - Pivot not found only if the column was misused.");
return it->get_element();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
#ifndef PM_ID_TO_POS_TRANSLATION_H
#define PM_ID_TO_POS_TRANSLATION_H

#include <cmath>
#include <vector>
#include <cassert>
#include <utility> //std::swap, std::move & std::exchange
#include <algorithm> //std::transform
#include <stdexcept> //std::invalid_argument

namespace Gudhi {
namespace persistence_matrix {
Expand Down Expand Up @@ -748,10 +750,11 @@ inline void Id_to_index_overlay<Matrix_type, Master_matrix_type>::insert_boundar
dimension_type dim)
{
if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
assert(idToIndex_->find(faceIndex) == idToIndex_->end() && "Index for simplex already chosen!");
GUDHI_CHECK(idToIndex_->find(faceIndex) == idToIndex_->end(),
std::invalid_argument("Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
} else {
assert((idToIndex_->size() <= faceIndex || idToIndex_[faceIndex] == static_cast<index>(-1)) &&
"Index for simplex already chosen!");
GUDHI_CHECK((idToIndex_->size() <= faceIndex || idToIndex_[faceIndex] == static_cast<index>(-1)),
std::invalid_argument("Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
}
matrix_.insert_boundary(faceIndex, boundary, dim);
if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
Expand Down Expand Up @@ -807,7 +810,8 @@ inline void Id_to_index_overlay<Matrix_type, Master_matrix_type>::remove_maximal
std::swap(idToIndex_->at(indexToID[curr]), idToIndex_->at(indexToID[curr + 1]));
}
matrix_.remove_last();
assert(_id_to_index(faceID) == nextIndex_ && "Indexation problem.");
GUDHI_CHECK(_id_to_index(faceID) == nextIndex_,
std::logic_error("Id_to_index_overlay::remove_maximal_face - Indexation problem."));

if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
idToIndex_->erase(faceID);
Expand All @@ -834,19 +838,21 @@ inline void Id_to_index_overlay<Matrix_type, Master_matrix_type>::remove_maximal
template <class Matrix_type, class Master_matrix_type>
inline void Id_to_index_overlay<Matrix_type, Master_matrix_type>::remove_last()
{
if (idToIndex_->empty()) return; //empty matrix

matrix_.remove_last();

if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
--nextIndex_;
if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
auto it = idToIndex_->begin();
while (it != idToIndex_->end() && it->second != nextIndex_) ++it;
assert(it != idToIndex_->end());
while (it->second != nextIndex_) ++it; //should never reach idToIndex_->end()
idToIndex_->erase(it);
} else {
assert(idToIndex_->size() != 0);
index id = idToIndex_->size() - 1;
while (idToIndex_->operator[](id) == static_cast<index>(-1)) --id; // should always stop before reaching -1
assert(idToIndex_->operator[](id) == nextIndex_);
GUDHI_CHECK(idToIndex_->operator[](id) == nextIndex_,
std::logic_error("Id_to_index_overlay::remove_last - Indexation problem."));
idToIndex_->operator[](id) = -1;
}
}
Expand Down Expand Up @@ -1012,7 +1018,9 @@ Id_to_index_overlay<Matrix_type, Master_matrix_type>::vine_swap_with_z_eq_1_case
if (first > second) std::swap(first, second);

if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
assert(second - first == 1 && "The columns to swap are not contiguous.");
GUDHI_CHECK(second - first == 1,
std::invalid_argument(
"Id_to_index_overlay::vine_swap_with_z_eq_1_case - The columns to swap are not contiguous."));

bool change = matrix_.vine_swap_with_z_eq_1_case(first);

Expand All @@ -1036,7 +1044,8 @@ Id_to_index_overlay<Matrix_type, Master_matrix_type>::vine_swap(id_index faceID1
if (first > second) std::swap(first, second);

if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
assert(second - first == 1 && "The columns to swap are not contiguous.");
GUDHI_CHECK(second - first == 1,
std::invalid_argument("Id_to_index_overlay::vine_swap - The columns to swap are not contiguous."));

bool change = matrix_.vine_swap(first);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <type_traits> //std::conditional
#include <cassert>
#include <vector>
#include <stdexcept> //std::invalid_argument

#include "ru_pairing.h"

Expand Down Expand Up @@ -173,7 +174,8 @@ inline RU_vine_swap<Master_matrix>::RU_vine_swap(RU_vine_swap<Master_matrix>&& o
template <class Master_matrix>
inline bool RU_vine_swap<Master_matrix>::vine_swap_with_z_eq_1_case(pos_index index)
{
assert(index < _matrix()->reducedMatrixR_.get_number_of_columns() - 1 && "Index to swap out of bound.");
GUDHI_CHECK(index < _matrix()->reducedMatrixR_.get_number_of_columns() - 1,
std::invalid_argument("RU_vine_swap::vine_swap_with_z_eq_1_case - Index to swap out of bound."));

bool iIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index);
bool iiIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index + 1);
Expand All @@ -192,7 +194,8 @@ inline bool RU_vine_swap<Master_matrix>::vine_swap_with_z_eq_1_case(pos_index in
template <class Master_matrix>
inline bool RU_vine_swap<Master_matrix>::vine_swap(pos_index index)
{
assert(index < _matrix()->reducedMatrixR_.get_number_of_columns() - 1 && "Index to swap out of bound.");
GUDHI_CHECK(index < _matrix()->reducedMatrixR_.get_number_of_columns() - 1,
std::invalid_argument("RU_vine_swap::vine_swap - Index to swap out of bound."));

bool iIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index);
bool iiIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index + 1);
Expand Down
23 changes: 14 additions & 9 deletions src/Persistence_matrix/include/gudhi/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
#include <vector>
#include <unordered_map>
#include <map>
#include <assert.h>
#include <initializer_list>

#include <boost/intrusive/list.hpp>

#include <gudhi/Debug_utils.h>

#include <gudhi/persistence_matrix_options.h>

#include <gudhi/Persistence_matrix/overlay_ididx_to_matidx.h>
Expand Down Expand Up @@ -1560,8 +1561,9 @@ template <class Container_type>
inline void Matrix<PersistenceMatrixOptions>::insert_column(const Container_type& column)
{
if constexpr (!PersistenceMatrixOptions::is_z2){
assert(colSettings_->operators.get_characteristic() != 0 &&
"Columns cannot be initialized if the coefficient field characteristic is not specified.");
GUDHI_CHECK(colSettings_->operators.get_characteristic() != 0,
std::logic_error("Matrix::insert_column - Columns cannot be initialized if the coefficient field "
"characteristic is not specified."));
}

static_assert(
Expand All @@ -1575,8 +1577,9 @@ template <class Container_type>
inline void Matrix<PersistenceMatrixOptions>::insert_column(const Container_type& column, index columnIndex)
{
if constexpr (!PersistenceMatrixOptions::is_z2){
assert(colSettings_->operators.get_characteristic() != 0 &&
"Columns cannot be initialized if the coefficient field characteristic is not specified.");
GUDHI_CHECK(colSettings_->operators.get_characteristic() != 0,
std::logic_error("Matrix::insert_column - Columns cannot be initialized if the coefficient field "
"characteristic is not specified."));
}

static_assert(!isNonBasic && !PersistenceMatrixOptions::has_column_compression,
Expand All @@ -1592,8 +1595,9 @@ inline typename Matrix<PersistenceMatrixOptions>::insertion_return_type
Matrix<PersistenceMatrixOptions>::insert_boundary(const Boundary_type& boundary, dimension_type dim)
{
if constexpr (!PersistenceMatrixOptions::is_z2){
assert(colSettings_->operators.get_characteristic() != 0 &&
"Columns cannot be initialized if the coefficient field characteristic is not specified.");
GUDHI_CHECK(colSettings_->operators.get_characteristic() != 0,
std::logic_error("Matrix::insert_boundary - Columns cannot be initialized if the coefficient field "
"characteristic is not specified."));
}

if constexpr (isNonBasic && !PersistenceMatrixOptions::is_of_boundary_type &&
Expand All @@ -1611,8 +1615,9 @@ Matrix<PersistenceMatrixOptions>::insert_boundary(id_index faceIndex,
dimension_type dim)
{
if constexpr (!PersistenceMatrixOptions::is_z2){
assert(colSettings_->operators.get_characteristic() != 0 &&
"Columns cannot be initialized if the coefficient field characteristic is not specified.");
GUDHI_CHECK(colSettings_->operators.get_characteristic() != 0,
std::logic_error("Matrix::insert_boundary - Columns cannot be initialized if the coefficient field "
"characteristic is not specified."));
}

static_assert(isNonBasic, "Only enabled for non-basic matrices.");
Expand Down

0 comments on commit 3773d2c

Please sign in to comment.