All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Matrix.h
Go to the documentation of this file.
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Hannah Schreiber
4 *
5 * Copyright (C) 2022-24 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
16#ifndef MASTER_MATRIX_H
17#define MASTER_MATRIX_H
18
19#include <type_traits>
20#include <vector>
21#include <unordered_map>
22#include <map>
23#include <initializer_list>
24
25#include <boost/intrusive/list.hpp>
26
27#include <gudhi/Debug_utils.h>
28
31
33
36
47
53
57
68
70namespace Gudhi {
72namespace persistence_matrix {
73
143template <class PersistenceMatrixOptions = Default_options<> >
144class Matrix {
145 public:
146 using Option_list = PersistenceMatrixOptions; //to make it accessible from the other classes
156 typename std::conditional<PersistenceMatrixOptions::is_z2,
159 >::type;
163 using Element = typename Field_operators::Element;
164 using Characteristic = typename Field_operators::Characteristic;
165
169 template <typename T>
170 static constexpr const T get_null_value() {
171 return -1;
172 }
173
178
179 //tags for boost to associate a row and a column to a same entry
180 struct Matrix_row_tag;
181 struct Matrix_column_tag;
182
183 using Base_hook_matrix_row =
184 boost::intrusive::list_base_hook<boost::intrusive::tag<Matrix_row_tag>,
185 boost::intrusive::link_mode<boost::intrusive::auto_unlink> >;
186 using Base_hook_matrix_list_column =
187 boost::intrusive::list_base_hook<boost::intrusive::tag<Matrix_column_tag>,
188 boost::intrusive::link_mode<boost::intrusive::safe_link> >;
189 using Base_hook_matrix_set_column =
190 boost::intrusive::set_base_hook<boost::intrusive::tag<Matrix_column_tag>,
191 boost::intrusive::link_mode<boost::intrusive::safe_link> >;
192
193 //Two dummies are necessary to avoid double inheritance as an entry can inherit both a row and a column hook.
194 struct Dummy_row_hook {};
195 struct Dummy_column_hook {};
196
197 using Row_hook = typename std::conditional<PersistenceMatrixOptions::has_row_access &&
199 Base_hook_matrix_row,
200 Dummy_row_hook
201 >::type;
202 using Column_hook = typename std::conditional<
204 Base_hook_matrix_list_column,
206 Base_hook_matrix_set_column,
207 Dummy_column_hook
208 >::type
209 >::type;
210
211 //Option to store the column index within the entry (additionally to the row index). Necessary only with row access.
212 using Entry_column_index_option =
213 typename std::conditional<PersistenceMatrixOptions::has_row_access,
214 Entry_column_index<Index>,
215 Dummy_entry_column_index_mixin
216 >::type;
217 //Option to store the value of the entry.
218 //Unnecessary for values in Z_2 as there are always 1 (0-valued entries are never stored).
219 using Entry_field_element_option =
220 typename std::conditional<PersistenceMatrixOptions::is_z2,
221 Dummy_entry_field_element_mixin,
222 Entry_field_element<Element>
223 >::type;
228
234 inline static New_entry_constructor<Matrix_entry> defaultEntryConstructor;
239 using Entry_constructor = Pool_entry_constructor<Matrix_entry>;
240
248 using Entry_representative = typename std::conditional<PersistenceMatrixOptions::is_z2,
249 ID_index,
250 std::pair<ID_index, Element>
251 >::type;
252
257 bool operator()(const Matrix_entry& c1, const Matrix_entry& c2) const {
258 return c1.get_column_index() < c2.get_column_index();
259 }
260 };
261
267 using Row =
268 typename std::conditional<PersistenceMatrixOptions::has_intrusive_rows,
269 boost::intrusive::list<Matrix_entry,
270 boost::intrusive::constant_time_size<false>,
271 boost::intrusive::base_hook<Base_hook_matrix_row>
272 >,
273 std::set<Matrix_entry, RowEntryComp>
274 >::type;
275
276 using Row_container =
277 typename std::conditional<PersistenceMatrixOptions::has_removable_rows,
278 std::map<ID_index, Row>,
279 std::vector<Row>
280 >::type;
281
282 //Row access at column level
283 using Row_access_option =
284 typename std::conditional<PersistenceMatrixOptions::has_row_access,
287 >::type;
288 //Row access at matrix level
289 using Matrix_row_access_option =
290 typename std::conditional<PersistenceMatrixOptions::has_row_access,
292 Row_container,
294 ID_index>,
296 >::type;
297
298 template <typename value_type>
299 using Dictionary =
301 std::unordered_map<unsigned int, value_type>,
302 std::vector<value_type>
303 >::type;
304
305 static const bool isNonBasic = PersistenceMatrixOptions::has_column_pairings ||
308
309 using Column_dimension_option =
310 typename std::conditional<isNonBasic,
313 >::type;
314 //Extra information needed for a column when the matrix is a @ref chainmatrix "chain matrix".
315 using Chain_column_option =
316 typename std::conditional<isNonBasic && !PersistenceMatrixOptions::is_of_boundary_type,
319 >::type;
320
330
336 using Column = typename std::conditional<
339 typename std::conditional<
342 typename std::conditional<
345 typename std::conditional<
348 typename std::conditional<
351 typename std::conditional<
354 typename std::conditional<
357 typename std::conditional<
361 >::type
362 >::type
363 >::type
364 >::type
365 >::type
366 >::type
367 >::type
368 >::type;
369
370 struct Column_z2_settings{
371 Column_z2_settings() : entryConstructor() {}
372 Column_z2_settings([[maybe_unused]] Characteristic characteristic) : entryConstructor() {}
373 Column_z2_settings(const Column_z2_settings& toCopy) : entryConstructor() {}
374
375 Entry_constructor entryConstructor; //will be replaced by more specific allocators depending on the column type.
376 };
377
378 struct Column_zp_settings {
379 Column_zp_settings() : operators(), entryConstructor() {}
380 //purposely triggers operators() instead of operators(characteristic) as the "dummy" values for the different
381 //operators can be different from -1.
382 Column_zp_settings(Characteristic characteristic) : operators(), entryConstructor() {
383 if (characteristic != get_null_value<Characteristic>()) operators.set_characteristic(characteristic);
384 }
385 Column_zp_settings(const Column_zp_settings& toCopy)
386 : operators(toCopy.operators.get_characteristic()), entryConstructor() {}
387
388 Field_operators operators;
389 Entry_constructor entryConstructor; //will be replaced by more specific allocators depending on the column type.
390 };
391
392 // struct Column_z2_with_rows_settings {
393 // Column_z2_with_rows_settings() : entryConstructor(), rows(nullptr) {}
394 // Column_z2_with_rows_settings([[maybe_unused]] Characteristic characteristic)
395 // : entryConstructor(), rows(nullptr) {}
396
397 // Entry_constructor entryConstructor;
398 // Row_container* rows;
399 // };
400
401 // struct Column_zp_with_rows_settings {
402 // Column_zp_with_rows_settings() : operators(), entryConstructor(), rows(nullptr) {}
403 // Column_zp_with_rows_settings(Characteristic characteristic)
404 // : operators(characteristic), entryConstructor(), rows(nullptr) {}
405
406 // Field_operators operators;
407 // Entry_constructor entryConstructor;
408 // Row_container* rows;
409 // };
410
411 //To prepare a more flexible use of the column types later (custom allocators depending on the column type etc.)
412 using Column_settings = typename std::conditional<
414 Column_z2_settings,
415 Column_zp_settings
416 >::type;
417
418 // using Column_settings = typename std::conditional<
419 // PersistenceMatrixOptions::is_z2,
420 // typename std::conditional<PersistenceMatrixOptions::has_row_access,
421 // Column_z2_with_rows_settings,
422 // Column_z2_settings
423 // >::type,
424 // typename std::conditional<PersistenceMatrixOptions::has_row_access,
425 // Column_zp_with_rows_settings,
426 // Column_zp_settings
427 // >::type
428 // >::type;
429
430 using Column_container =
432 std::unordered_map<Index, Column>,
433 std::vector<Column>
434 >::type;
435
441 using Barcode = typename std::conditional<hasFixedBarcode,
442 std::vector<Bar>,
443 typename std::conditional<PersistenceMatrixOptions::has_removable_columns,
444 std::list<Bar>,
445 std::vector<Bar>
446 >::type
447 >::type;
448 using Bar_dictionary =
449 typename std::conditional<hasFixedBarcode,
451 std::vector<Index>, //RU
452 std::unordered_map<Pos_index, Index> //boundary
453 >::type,
454 typename std::conditional<PersistenceMatrixOptions::has_removable_columns,
455 std::unordered_map<Pos_index, typename Barcode::iterator>,
456 std::vector<Index>
457 >::type
458 >::type;
459
460 //default type for boundaries to permit list initialization directly in function parameters
461 using Boundary = typename std::conditional<PersistenceMatrixOptions::is_z2,
462 std::initializer_list<ID_index>,
463 std::initializer_list<std::pair<ID_index, Element> >
464 >::type;
465
466 //i.e. is simple @ref boundarymatrix "boundary matrix". Also, only needed because of the reduction algorithm.
467 //TODO: remove the necessity and recalculate when needed or keep it like that?
468 static const bool maxDimensionIsNeeded =
471
472 using Matrix_dimension_option = typename std::conditional<
474 typename std::conditional<PersistenceMatrixOptions::has_removable_columns,
477 >::type,
479 >::type;
480
481 using Master_base_matrix =
482 typename std::conditional<PersistenceMatrixOptions::has_column_compression,
485 >::type;
489
490 template <class Base>
491 using Base_swap_option =
492 typename std::conditional<PersistenceMatrixOptions::has_vine_update ||
496 >::type;
497 using Base_pairing_option =
498 typename std::conditional<PersistenceMatrixOptions::has_column_pairings &&
503 >::type;
504
505 using RU_pairing_option =
506 typename std::conditional<PersistenceMatrixOptions::has_column_pairings &&
510 >::type;
511 using RU_vine_swap_option =
512 typename std::conditional<PersistenceMatrixOptions::has_vine_update,
515 >::type;
516 using RU_representative_cycles_option =
520 >::type;
521
522 using Chain_pairing_option =
523 typename std::conditional<PersistenceMatrixOptions::has_column_pairings &&
527 >::type;
528 using Chain_vine_swap_option = typename std::conditional<PersistenceMatrixOptions::has_vine_update,
531 >::type;
532 using Chain_representative_cycles_option =
536 >::type;
537
541 using Cycle = std::vector<ID_index>; //TODO: add coefficients
542
543 //Return types to factorize the corresponding methods
544
545 //The returned column is `const` if the matrix uses column compression
546 using Returned_column =
547 typename std::conditional<!isNonBasic && PersistenceMatrixOptions::has_column_compression,
548 const Column,
549 Column
550 >::type;
551 //The returned row is `const` if the matrix uses column compression
552 using Returned_row =
553 typename std::conditional<!isNonBasic && PersistenceMatrixOptions::has_column_compression,
554 const Row,
555 Row
556 >::type;
557 //If the matrix is a chain matrix, the insertion method returns the pivots of its unpaired columns used to reduce the
558 //inserted boundary. Otherwise, void.
559 using Insertion_return =
560 typename std::conditional<PersistenceMatrixOptions::is_of_boundary_type || !isNonBasic ||
563 void,
564 std::vector<Entry_representative>
565 >::type;
566
597 template <class Container = Boundary>
598 Matrix(const std::vector<Container>& columns, Characteristic characteristic = 11);
608 Matrix(unsigned int numberOfColumns, Characteristic characteristic = Matrix::get_null_value<Characteristic>());
629 Matrix(const std::function<bool(Pos_index,Pos_index)>& birthComparator,
630 const std::function<bool(Pos_index,Pos_index)>& deathComparator);
656 template <class Boundary_range = Boundary>
657 Matrix(const std::vector<Boundary_range>& orderedBoundaries,
658 const std::function<bool(Pos_index,Pos_index)>& birthComparator,
659 const std::function<bool(Pos_index,Pos_index)>& deathComparator,
660 Characteristic characteristic = 11);
684 Matrix(unsigned int numberOfColumns,
685 const std::function<bool(Pos_index,Pos_index)>& birthComparator,
686 const std::function<bool(Pos_index,Pos_index)>& deathComparator,
687 Characteristic characteristic = Matrix::get_null_value<Characteristic>());
693 Matrix(const Matrix& matrixToCopy);
700 Matrix(Matrix&& other) noexcept;
701
702 ~Matrix();
703
704 //TODO: compatibility with multi fields:
705 // - set_characteristic(Characteristic min, Characteristic max)
706 // - readapt reduction?
718 void set_characteristic(Characteristic characteristic);
719
720 // (TODO: if there is no row access and the column type corresponds to the internal column type of the matrix,
721 // moving the column instead of copying it should be possible. Is it worth implementing it?)
732 template <class Container>
733 void insert_column(const Container& column);
745 template <class Container>
746 void insert_column(const Container& column, Index columnIndex);
747 //TODO: for simple boundary matrices, add an index pointing to the first column inserted after the last call of
748 //get_current_barcode to enable several calls to get_current_barcode
780 template <class Boundary_range = Boundary>
781 Insertion_return insert_boundary(const Boundary_range& boundary, Dimension dim = Matrix::get_null_value<Dimension>());
802 template <class Boundary_range = Boundary>
803 Insertion_return insert_boundary(ID_index cellIndex, const Boundary_range& boundary,
804 Dimension dim = Matrix::get_null_value<Dimension>());
805
815 Returned_column& get_column(Index columnIndex);
823 const Column& get_column(Index columnIndex) const;
824 //TODO: there is no particular reason that this method is not available for identifier indexing,
825 // just has to be added to the interface...
836 const Column& get_column(Index columnIndex, bool inR);
837
838 //TODO: update column indices when reordering rows (after lazy swap) such that always MatIdx are returned.
849 Returned_row& get_row(ID_index rowIndex);
859 const Row& get_row(ID_index rowIndex) const;
860 //TODO: there is no particular reason that this method is not available for identifier indexing,
861 // just has to be added to the interface...
872 const Row& get_row(ID_index rowIndex, bool inR);
873
882 void remove_column(Index columnIndex);
883 //TODO: rename method to be less confusing.
906 void erase_empty_row(ID_index rowIndex);
907 //TODO: for chain matrices, replace IDIdx input with MatIdx input to homogenize.
926 void remove_maximal_cell(Index columnIndex);
927 //TODO: See if it would be better to use something more general than a vector for columnsToSwap, such that
928 // the user do not have to construct the vector from scratch. Like passing iterators instead. But it would be nice,
929 // to still be able to do (cell, {})...
952 void remove_maximal_cell(ID_index cellIndex, const std::vector<ID_index>& columnsToSwap);
970
992
1006 template <typename Integer_index>
1007 std::enable_if_t<std::is_integral_v<Integer_index> > add_to(Integer_index sourceColumnIndex,
1008 Integer_index targetColumnIndex);
1021 template <class Entry_range>
1022 std::enable_if_t<!std::is_integral_v<Entry_range> > add_to(const Entry_range& sourceColumn, Index targetColumnIndex);
1023
1040 template <typename Integer_index>
1041 std::enable_if_t<std::is_integral_v<Integer_index> > multiply_target_and_add_to(Integer_index sourceColumnIndex,
1042 int coefficient,
1043 Integer_index targetColumnIndex);
1058 template <class Entry_range>
1059 std::enable_if_t<!std::is_integral_v<Entry_range> > multiply_target_and_add_to(const Entry_range& sourceColumn,
1060 int coefficient,
1061 Index targetColumnIndex);
1062
1079 template <typename Integer_index>
1080 std::enable_if_t<std::is_integral_v<Integer_index> > multiply_source_and_add_to(int coefficient,
1081 Integer_index sourceColumnIndex,
1082 Integer_index targetColumnIndex);
1097 template <class Entry_range>
1098 std::enable_if_t<!std::is_integral_v<Entry_range> > multiply_source_and_add_to(int coefficient,
1099 const Entry_range& sourceColumn,
1100 Index targetColumnIndex);
1101
1114 void zero_entry(Index columnIndex, ID_index rowIndex);
1124 void zero_entry(Index columnIndex, ID_index rowIndex, bool inR);
1136 void zero_column(Index columnIndex);
1145 void zero_column(Index columnIndex, bool inR);
1158 bool is_zero_entry(Index columnIndex, ID_index rowIndex);
1169 bool is_zero_entry(Index columnIndex, ID_index rowIndex, bool inR) const;
1183 bool is_zero_column(Index columnIndex);
1195 bool is_zero_column(Index columnIndex, bool inR);
1196
1218
1232 friend void swap(Matrix& matrix1, Matrix& matrix2) {
1233 swap(matrix1.matrix_, matrix2.matrix_);
1234 std::swap(matrix1.colSettings_, matrix2.colSettings_);
1235 }
1236
1237 void print(); // for debug
1238
1239 //TODO: change the behaviour for boundary matrices.
1266
1277 void swap_columns(Index columnIndex1, Index columnIndex2);
1288 void swap_rows(Index rowIndex1, Index rowIndex2);
1289 //TODO: find better name. And benchmark also to verify if it is really worth it to have this extra version in addition
1290 //to vine_swap.
1316 Index vine_swap_with_z_eq_1_case(Index columnIndex1, Index columnIndex2);
1350 Index vine_swap(Index columnIndex1, Index columnIndex2);
1351
1352 //TODO: Rethink the interface for representative cycles
1367 const std::vector<Cycle>& get_representative_cycles();
1376
1377 private:
1378 using Underlying_matrix =
1379 typename std::conditional<
1380 isNonBasic,
1381 typename std::conditional<
1383 typename std::conditional<
1386 typename std::conditional<
1390 >::type,
1391 typename std::conditional<
1396 >::type
1397 >::type,
1398 typename std::conditional<
1401 typename std::conditional<
1405 >::type
1406 >::type
1407 >::type,
1408 Master_base_matrix
1409 >::type;
1410
1411 // Field_operators* operators_;
1412 // Entry_constructor* entryPool_;
1413 Column_settings* colSettings_; //pointer because the of swap operator on matrix_ which also stores the pointer
1414 Underlying_matrix matrix_;
1415
1416 static constexpr void _assert_options();
1417};
1418
1419template <class PersistenceMatrixOptions>
1421 : colSettings_(new Column_settings()), matrix_(colSettings_)
1422{
1423 static_assert(
1426 "When no barcode is recorded with vine swaps, comparison functions for the columns have to be provided.");
1427 _assert_options();
1428}
1429
1430template <class PersistenceMatrixOptions>
1431template <class Container>
1432inline Matrix<PersistenceMatrixOptions>::Matrix(const std::vector<Container>& columns,
1433 Characteristic characteristic)
1434 : colSettings_(new Column_settings(characteristic)),
1435 matrix_(columns, colSettings_)
1436{
1439 "When no barcode is recorded with vine swaps for chain matrices, comparison functions for the columns "
1440 "have to be provided.");
1441 _assert_options();
1442}
1443
1444template <class PersistenceMatrixOptions>
1445inline Matrix<PersistenceMatrixOptions>::Matrix(unsigned int numberOfColumns, Characteristic characteristic)
1446 : colSettings_(new Column_settings(characteristic)),
1447 matrix_(numberOfColumns, colSettings_)
1448{
1451 "When no barcode is recorded with vine swaps for chain matrices, comparison functions for the columns "
1452 "have to be provided.");
1453 _assert_options();
1454}
1455
1456template <class PersistenceMatrixOptions>
1457inline Matrix<PersistenceMatrixOptions>::Matrix(const std::function<bool(Pos_index,Pos_index)>& birthComparator,
1458 const std::function<bool(Pos_index,Pos_index)>& deathComparator)
1459 : colSettings_(new Column_settings()),
1460 matrix_(colSettings_, birthComparator, deathComparator)
1461{
1462 static_assert(
1465 "Constructor only available for chain matrices when vine swaps are enabled, but the barcode is not recorded.");
1466 _assert_options();
1467}
1468
1469template <class PersistenceMatrixOptions>
1470template <class Boundary_range>
1471inline Matrix<PersistenceMatrixOptions>::Matrix(const std::vector<Boundary_range>& orderedBoundaries,
1472 const std::function<bool(Pos_index, Pos_index)>& birthComparator,
1473 const std::function<bool(Pos_index, Pos_index)>& deathComparator,
1474 Characteristic characteristic)
1475 : colSettings_(new Column_settings(characteristic)),
1476 matrix_(orderedBoundaries, colSettings_, birthComparator, deathComparator)
1477{
1478 static_assert(
1481 "Constructor only available for chain matrices when vine swaps are enabled, but the barcode is not recorded.");
1482 _assert_options();
1483}
1484
1485template <class PersistenceMatrixOptions>
1486inline Matrix<PersistenceMatrixOptions>::Matrix(unsigned int numberOfColumns,
1487 const std::function<bool(Pos_index, Pos_index)>& birthComparator,
1488 const std::function<bool(Pos_index, Pos_index)>& deathComparator,
1489 Characteristic characteristic)
1490 : colSettings_(new Column_settings(characteristic)),
1491 matrix_(numberOfColumns, colSettings_, birthComparator, deathComparator)
1492{
1493 static_assert(
1496 "Constructor only available for chain matrices when vine swaps are enabled, but the barcode is not recorded.");
1497 _assert_options();
1498}
1499
1500template <class PersistenceMatrixOptions>
1502 : colSettings_(new Column_settings(*matrixToCopy.colSettings_)),
1503 matrix_(matrixToCopy.matrix_, colSettings_)
1504{
1505 _assert_options();
1506}
1507
1508template <class PersistenceMatrixOptions>
1510 : colSettings_(std::exchange(other.colSettings_, nullptr)),
1511 matrix_(std::move(other.matrix_))
1512{
1513 _assert_options();
1514}
1515
1516template <class PersistenceMatrixOptions>
1518{
1519 matrix_.reset(colSettings_);
1520 delete colSettings_;
1521}
1522
1523template <class PersistenceMatrixOptions>
1524inline void Matrix<PersistenceMatrixOptions>::set_characteristic(Characteristic characteristic)
1525{
1526 if constexpr (!PersistenceMatrixOptions::is_z2) {
1527 if (colSettings_->operators.get_characteristic() != get_null_value<Characteristic>()) {
1528 std::cerr << "Warning: Characteristic already initialised. Changing it could lead to incoherences in the matrix "
1529 "as the modulo was already applied to values in existing columns.";
1530 }
1531
1532 colSettings_->operators.set_characteristic(characteristic);
1533 }
1534}
1535
1536template <class PersistenceMatrixOptions>
1537template <class Container>
1538inline void Matrix<PersistenceMatrixOptions>::insert_column(const Container& column)
1539{
1540 if constexpr (!PersistenceMatrixOptions::is_z2){
1541 GUDHI_CHECK(colSettings_->operators.get_characteristic() != get_null_value<Characteristic>(),
1542 std::logic_error("Matrix::insert_column - Columns cannot be initialized if the coefficient field "
1543 "characteristic is not specified."));
1544 }
1545
1546 static_assert(
1547 !isNonBasic,
1548 "'insert_column' not available for the chosen options. The input has to be in the form of a cell boundary.");
1549 matrix_.insert_column(column);
1550}
1551
1552template <class PersistenceMatrixOptions>
1553template <class Container>
1554inline void Matrix<PersistenceMatrixOptions>::insert_column(const Container& column, Index columnIndex)
1555{
1556 if constexpr (!PersistenceMatrixOptions::is_z2){
1557 GUDHI_CHECK(colSettings_->operators.get_characteristic() != get_null_value<Characteristic>(),
1558 std::logic_error("Matrix::insert_column - Columns cannot be initialized if the coefficient field "
1559 "characteristic is not specified."));
1560 }
1561
1562 static_assert(!isNonBasic && !PersistenceMatrixOptions::has_column_compression,
1563 "'insert_column' with those parameters is not available for the chosen options.");
1565 "Columns have to be inserted at the end of the matrix when row access is enabled.");
1566 matrix_.insert_column(column, columnIndex);
1567}
1568
1569template <class PersistenceMatrixOptions>
1570template <class Boundary_range>
1571inline typename Matrix<PersistenceMatrixOptions>::Insertion_return
1573{
1574 if constexpr (!PersistenceMatrixOptions::is_z2){
1575 GUDHI_CHECK(colSettings_->operators.get_characteristic() != get_null_value<Characteristic>(),
1576 std::logic_error("Matrix::insert_boundary - Columns cannot be initialized if the coefficient field "
1577 "characteristic is not specified."));
1578 }
1579
1580 if constexpr (isNonBasic && !PersistenceMatrixOptions::is_of_boundary_type &&
1582 return matrix_.insert_boundary(boundary, dim);
1583 else
1584 matrix_.insert_boundary(boundary, dim);
1585}
1586
1587template <class PersistenceMatrixOptions>
1588template <class Boundary_range>
1589inline typename Matrix<PersistenceMatrixOptions>::Insertion_return
1591 const Boundary_range& boundary,
1592 Dimension dim)
1593{
1594 if constexpr (!PersistenceMatrixOptions::is_z2){
1595 GUDHI_CHECK(colSettings_->operators.get_characteristic() != get_null_value<Characteristic>(),
1596 std::logic_error("Matrix::insert_boundary - Columns cannot be initialized if the coefficient field "
1597 "characteristic is not specified."));
1598 }
1599
1600 static_assert(isNonBasic, "Only enabled for non-basic matrices.");
1603 return matrix_.insert_boundary(cellIndex, boundary, dim);
1604 else
1605 matrix_.insert_boundary(cellIndex, boundary, dim);
1606}
1607
1608template <class PersistenceMatrixOptions>
1609inline typename Matrix<PersistenceMatrixOptions>::Returned_column& Matrix<PersistenceMatrixOptions>::get_column(
1610 Index columnIndex)
1611{
1612 return matrix_.get_column(columnIndex);
1613}
1614
1615template <class PersistenceMatrixOptions>
1617 Index columnIndex) const
1618{
1619 return matrix_.get_column(columnIndex);
1620}
1621
1622template <class PersistenceMatrixOptions>
1624 Index columnIndex, bool inR)
1625{
1626 // TODO: I don't think there is a particular reason why the indexation is forced, should be removed.
1627 static_assert(
1631 "Only enabled for position indexed RU matrices.");
1632
1633 return matrix_.get_column(columnIndex, inR);
1634}
1635
1636template <class PersistenceMatrixOptions>
1637inline typename Matrix<PersistenceMatrixOptions>::Returned_row& Matrix<PersistenceMatrixOptions>::get_row(
1638 ID_index rowIndex)
1639{
1640 static_assert(PersistenceMatrixOptions::has_row_access, "'get_row' is not available for the chosen options.");
1641
1642 return matrix_.get_row(rowIndex);
1643}
1644
1645template <class PersistenceMatrixOptions>
1647 ID_index rowIndex) const
1648{
1649 static_assert(PersistenceMatrixOptions::has_row_access, "'get_row' is not available for the chosen options.");
1650
1651 return matrix_.get_row(rowIndex);
1652}
1653
1654template <class PersistenceMatrixOptions>
1656 ID_index rowIndex, bool inR)
1657{
1658 static_assert(PersistenceMatrixOptions::has_row_access, "'get_row' is not available for the chosen options.");
1659 // TODO: I don't think there is a particular reason why the indexation is forced, should be removed.
1660 static_assert(
1664 "Only enabled for position indexed RU matrices.");
1665
1666 return matrix_.get_row(rowIndex, inR);
1667}
1668
1669template <class PersistenceMatrixOptions>
1671{
1672 static_assert(PersistenceMatrixOptions::has_map_column_container && !isNonBasic &&
1674 "'remove_column' is not available for the chosen options.");
1675
1676 matrix_.remove_column(columnIndex);
1677}
1678
1679template <class PersistenceMatrixOptions>
1681{
1682 static_assert(
1684 "'erase_empty_row' is not available for the chosen options.");
1685
1686 matrix_.erase_empty_row(rowIndex);
1687}
1688
1689template <class PersistenceMatrixOptions>
1691{
1693 "'remove_maximal_cell(ID_index)' is not available for the chosen options.");
1694 static_assert(isNonBasic && PersistenceMatrixOptions::has_vine_update,
1695 "'remove_maximal_cell(ID_index)' is not available for the chosen options.");
1698 "'remove_maximal_cell(ID_index)' is not available for the chosen options.");
1699
1700 matrix_.remove_maximal_cell(columnIndex);
1701}
1702
1703template <class PersistenceMatrixOptions>
1705 const std::vector<ID_index>& columnsToSwap)
1706{
1708 "'remove_maximal_cell(ID_index,const std::vector<Index>&)' is not available for the chosen options.");
1709 static_assert(isNonBasic && !PersistenceMatrixOptions::is_of_boundary_type,
1710 "'remove_maximal_cell(ID_index,const std::vector<Index>&)' is not available for the chosen options.");
1712 "'remove_maximal_cell(ID_index,const std::vector<Index>&)' is not available for the chosen options.");
1713
1714 matrix_.remove_maximal_cell(cellIndex, columnsToSwap);
1715}
1716
1717template <class PersistenceMatrixOptions>
1719{
1720 static_assert(PersistenceMatrixOptions::has_removable_columns || !isNonBasic,
1721 "'remove_last' is not available for the chosen options.");
1722 static_assert(!PersistenceMatrixOptions::has_column_compression || isNonBasic,
1723 "'remove_last' is not available for the chosen options.");
1724 static_assert(!isNonBasic || PersistenceMatrixOptions::is_of_boundary_type ||
1726 "'remove_last' is not available for the chosen options.");
1727
1728 matrix_.remove_last();
1729}
1730
1731template <class PersistenceMatrixOptions>
1733 const
1734{
1735 static_assert(isNonBasic, "'get_max_dimension' is not available for the chosen options.");
1736
1737 return matrix_.get_max_dimension();
1738}
1739
1740template <class PersistenceMatrixOptions>
1742{
1743 return matrix_.get_number_of_columns();
1744}
1745
1746template <class PersistenceMatrixOptions>
1748 Index columnIndex) const
1749{
1750 static_assert(isNonBasic, "'get_column_dimension' is not available for the chosen options.");
1751
1752 return matrix_.get_column_dimension(columnIndex);
1753}
1754
1755template <class PersistenceMatrixOptions>
1756template <typename Integer_index>
1757inline std::enable_if_t<std::is_integral_v<Integer_index> > Matrix<PersistenceMatrixOptions>::add_to(
1758 Integer_index sourceColumnIndex, Integer_index targetColumnIndex)
1759{
1760 matrix_.add_to(sourceColumnIndex, targetColumnIndex);
1761}
1762
1763template <class PersistenceMatrixOptions>
1764template <class Entry_range>
1765inline std::enable_if_t<!std::is_integral_v<Entry_range> > Matrix<PersistenceMatrixOptions>::add_to(
1766 const Entry_range& sourceColumn, Index targetColumnIndex)
1767{
1768 static_assert(!isNonBasic,
1769 "For boundary or chain matrices, only additions with columns inside the matrix is allowed to maintain "
1770 "algebraic consistency.");
1771
1772 matrix_.add_to(sourceColumn, targetColumnIndex);
1773}
1774
1775template <class PersistenceMatrixOptions>
1776template <typename Integer_index>
1777inline std::enable_if_t<std::is_integral_v<Integer_index> > Matrix<PersistenceMatrixOptions>::multiply_target_and_add_to(
1778 Integer_index sourceColumnIndex, int coefficient, Integer_index targetColumnIndex)
1779{
1780 if constexpr (PersistenceMatrixOptions::is_z2) {
1781 // coef will be converted to bool, because of Element
1782 matrix_.multiply_target_and_add_to(sourceColumnIndex, coefficient % 2, targetColumnIndex);
1783 } else {
1784 matrix_.multiply_target_and_add_to(sourceColumnIndex, colSettings_->operators.get_value(coefficient), targetColumnIndex);
1785 }
1786}
1787
1788template <class PersistenceMatrixOptions>
1789template <class Entry_range>
1790inline std::enable_if_t<!std::is_integral_v<Entry_range> > Matrix<PersistenceMatrixOptions>::multiply_target_and_add_to(
1791 const Entry_range& sourceColumn, int coefficient, Index targetColumnIndex)
1792{
1793 static_assert(!isNonBasic,
1794 "For boundary or chain matrices, only additions with columns inside the matrix is allowed to maintain "
1795 "algebraic consistency.");
1796
1797 if constexpr (PersistenceMatrixOptions::is_z2) {
1798 // coef will be converted to bool, because of Element
1799 matrix_.multiply_target_and_add_to(sourceColumn, coefficient % 2, targetColumnIndex);
1800 } else {
1801 matrix_.multiply_target_and_add_to(sourceColumn, colSettings_->operators.get_value(coefficient), targetColumnIndex);
1802 }
1803}
1804
1805template <class PersistenceMatrixOptions>
1806template <typename Integer_index>
1807inline std::enable_if_t<std::is_integral_v<Integer_index> > Matrix<PersistenceMatrixOptions>::multiply_source_and_add_to(
1808 int coefficient, Integer_index sourceColumnIndex, Integer_index targetColumnIndex)
1809{
1810 if constexpr (PersistenceMatrixOptions::is_z2) {
1811 // coef will be converted to bool, because of Element
1812 matrix_.multiply_source_and_add_to(coefficient % 2, sourceColumnIndex, targetColumnIndex);
1813 } else {
1814 matrix_.multiply_source_and_add_to(colSettings_->operators.get_value(coefficient), sourceColumnIndex, targetColumnIndex);
1815 }
1816}
1817
1818template <class PersistenceMatrixOptions>
1819template <class Entry_range>
1820inline std::enable_if_t<!std::is_integral_v<Entry_range> > Matrix<PersistenceMatrixOptions>::multiply_source_and_add_to(
1821 int coefficient, const Entry_range& sourceColumn, Index targetColumnIndex)
1822{
1823 static_assert(!isNonBasic,
1824 "For boundary or chain matrices, only additions with columns inside the matrix is allowed to maintain "
1825 "algebraic consistency.");
1826
1827 if constexpr (PersistenceMatrixOptions::is_z2) {
1828 // coef will be converted to bool, because of Element
1829 matrix_.multiply_source_and_add_to(coefficient % 2, sourceColumn, targetColumnIndex);
1830 } else {
1831 matrix_.multiply_source_and_add_to(colSettings_->operators.get_value(coefficient), sourceColumn, targetColumnIndex);
1832 }
1833}
1834
1835template <class PersistenceMatrixOptions>
1837{
1839 "'zero_entry' is not available for the chosen options.");
1840
1841 return matrix_.zero_entry(columnIndex, rowIndex);
1842}
1843
1844template <class PersistenceMatrixOptions>
1845inline void Matrix<PersistenceMatrixOptions>::zero_entry(Index columnIndex, ID_index rowIndex, bool inR)
1846{
1847 // TODO: I don't think there is a particular reason why the indexation is forced, should be removed.
1848 static_assert(
1852 "Only enabled for RU matrices.");
1853
1854 return matrix_.zero_entry(columnIndex, rowIndex, inR);
1855}
1856
1857template <class PersistenceMatrixOptions>
1859{
1861 "'zero_column' is not available for the chosen options.");
1862
1863 return matrix_.zero_column(columnIndex);
1864}
1865
1866template <class PersistenceMatrixOptions>
1868{
1869 // TODO: I don't think there is a particular reason why the indexation is forced, should be removed.
1870 static_assert(
1874 "Only enabled for RU matrices.");
1875
1876 return matrix_.zero_column(columnIndex, inR);
1877}
1878
1879template <class PersistenceMatrixOptions>
1881{
1882 return matrix_.is_zero_entry(columnIndex, rowIndex);
1883}
1884
1885template <class PersistenceMatrixOptions>
1886inline bool Matrix<PersistenceMatrixOptions>::is_zero_entry(Index columnIndex, ID_index rowIndex, bool inR) const
1887{
1888 // TODO: I don't think there is a particular reason why the indexation is forced, should be removed.
1889 static_assert(
1893 "Only enabled for RU matrices.");
1894
1895 return matrix_.is_zero_entry(columnIndex, rowIndex, inR);
1896}
1897
1898template <class PersistenceMatrixOptions>
1900{
1901 return matrix_.is_zero_column(columnIndex);
1902}
1903
1904template <class PersistenceMatrixOptions>
1906{
1907 // TODO: I don't think there is a particular reason why the indexation is forced, should be removed.
1908 static_assert(
1912 "Only enabled for RU matrices.");
1913
1914 return matrix_.is_zero_column(columnIndex, inR);
1915}
1916
1917template <class PersistenceMatrixOptions>
1919 ID_index cellIndex) const
1920{
1921 static_assert(isNonBasic && (!PersistenceMatrixOptions::is_of_boundary_type ||
1924 "'get_column_with_pivot' is not available for the chosen options.");
1925
1926 return matrix_.get_column_with_pivot(cellIndex);
1927}
1928
1929template <class PersistenceMatrixOptions>
1931 Index columnIndex)
1932{
1933 static_assert(isNonBasic, "'get_pivot' is not available for the chosen options.");
1934
1935 return matrix_.get_pivot(columnIndex);
1936}
1937
1938template <class PersistenceMatrixOptions>
1940{
1941 swap(matrix_, other.matrix_);
1942 std::swap(colSettings_, other.colSettings_);
1943
1944 return *this;
1945}
1946
1947template <class PersistenceMatrixOptions>
1949{
1950 return matrix_.print();
1951}
1952
1953template <class PersistenceMatrixOptions>
1954inline const typename Matrix<PersistenceMatrixOptions>::Barcode&
1956{
1957 static_assert(PersistenceMatrixOptions::has_column_pairings, "This method was not enabled.");
1958
1959 return matrix_.get_current_barcode();
1960}
1961
1962template <class PersistenceMatrixOptions>
1963inline const typename Matrix<PersistenceMatrixOptions>::Barcode&
1965{
1966 static_assert(PersistenceMatrixOptions::has_column_pairings, "This method was not enabled.");
1967 static_assert(
1970 "'get_current_barcode' is not const for boundary matrices as the barcode is only computed when explicitly "
1971 "asked.");
1972
1973 return matrix_.get_current_barcode();
1974}
1975
1976template <class PersistenceMatrixOptions>
1977inline void Matrix<PersistenceMatrixOptions>::swap_columns(Index columnIndex1, Index columnIndex2)
1978{
1979 static_assert(
1983 "This method was not enabled.");
1984 return matrix_.swap_columns(columnIndex1, columnIndex2);
1985}
1986
1987template <class PersistenceMatrixOptions>
1989{
1990 static_assert(
1994 "This method was not enabled.");
1995 return matrix_.swap_rows(rowIndex1, rowIndex2);
1996}
1997
1998template <class PersistenceMatrixOptions>
2000{
2001 static_assert(PersistenceMatrixOptions::has_vine_update, "This method was not enabled.");
2005 "This method was not enabled.");
2006 return matrix_.vine_swap_with_z_eq_1_case(index);
2007}
2008
2009template <class PersistenceMatrixOptions>
2011 Index columnIndex1, Index columnIndex2)
2012{
2013 static_assert(PersistenceMatrixOptions::has_vine_update, "This method was not enabled.");
2017 "This method was not enabled.");
2018
2019 return matrix_.vine_swap_with_z_eq_1_case(columnIndex1, columnIndex2);
2020}
2021
2022template <class PersistenceMatrixOptions>
2024{
2025 static_assert(PersistenceMatrixOptions::has_vine_update, "This method was not enabled.");
2029 "This method was not enabled.");
2030 return matrix_.vine_swap(index);
2031}
2032
2033template <class PersistenceMatrixOptions>
2035 Index columnIndex1, Index columnIndex2)
2036{
2037 static_assert(PersistenceMatrixOptions::has_vine_update, "This method was not enabled.");
2041 "This method was not enabled.");
2042 return matrix_.vine_swap(columnIndex1, columnIndex2);
2043}
2044
2045template <class PersistenceMatrixOptions>
2047{
2048 static_assert(PersistenceMatrixOptions::can_retrieve_representative_cycles, "This method was not enabled.");
2049 matrix_.update_representative_cycles();
2050}
2051
2052template <class PersistenceMatrixOptions>
2053inline const std::vector<typename Matrix<PersistenceMatrixOptions>::Cycle>&
2055{
2056 static_assert(PersistenceMatrixOptions::can_retrieve_representative_cycles, "This method was not enabled.");
2057 return matrix_.get_representative_cycles();
2058}
2059
2060template <class PersistenceMatrixOptions>
2061inline const typename Matrix<PersistenceMatrixOptions>::Cycle&
2063{
2064 static_assert(PersistenceMatrixOptions::can_retrieve_representative_cycles, "This method was not enabled.");
2065 return matrix_.get_representative_cycle(bar);
2066}
2067
2068template <class PersistenceMatrixOptions>
2070{
2071 static_assert(
2073 "Row access is not possible for heap columns.");
2075 "Vine update currently works only for Z_2 coefficients.");
2076 // static_assert(!PersistenceMatrixOptions::can_retrieve_representative_cycles || PersistenceMatrixOptions::is_z2,
2077 // "Representative cycles can currently only be computed with Z_2 coefficients.");
2078 static_assert(
2080 "Column compression not compatible with heap columns.");
2081
2082 // // This should be warnings instead, as PersistenceMatrixOptions::has_column_compression is just ignored in those
2083 // // cases and don't produces errors as long as the corresponding methods are not called.
2084 // static_assert(!PersistenceMatrixOptions::has_column_compression || !PersistenceMatrixOptions::has_column_pairings,
2085 // "Column compression not available to compute persistence homology (it would bring no advantages; "
2086 // "use it for co-homology instead).");
2087 // static_assert(!PersistenceMatrixOptions::has_column_compression || !PersistenceMatrixOptions::has_vine_update,
2088 // "Column compression not available for vineyards.");
2089 // static_assert(!PersistenceMatrixOptions::has_column_compression ||
2090 // !PersistenceMatrixOptions::can_retrieve_representative_cycles,
2091 // "Column compression not available to retrieve representative cycles.");
2092 // // Would column removal while column compression be useful? If yes, should erase() remove a single column or the
2093 // // class of columns identical to the input?
2094 // // For a single column, I have an implementation for union-find (not the current one) which allows deleting a
2095 // // single element in constant time, but find becomes log n in worst case.
2096 // // For a column class, we either just ignore the removed class (constant time), but this results in memory
2097 // // residues, or, we have an erase method which is at least linear in the size of the class.
2098 // static_assert(
2099 // !PersistenceMatrixOptions::has_column_compression || !PersistenceMatrixOptions::has_map_column_container,
2100 // "When column compression is used, the removal of columns is not implemented yet.");
2101}
2102
2103} // namespace persistence_matrix
2104} // namespace Gudhi
2105
2106#endif // MASTER_MATRIX_H
Contains the Gudhi::persistence_matrix::Base_matrix class.
Contains the Gudhi::persistence_matrix::Base_matrix_with_column_compression class.
Contains the Gudhi::persistence_matrix::Boundary_matrix class.
Contains the Gudhi::persistence_matrix::Chain_matrix class.
Contains the Gudhi::persistence_matrix::Id_to_index_overlay class.
Contains the Gudhi::persistence_matrix::Position_to_index_overlay class.
Contains the Gudhi::persistence_matrix::RU_matrix class.
Contains the Gudhi::persistence_fields::Z2_field_operators class.
Contains the Gudhi::persistence_matrix::Base_pairing class and Gudhi::persistence_matrix::Dummy_base_...
Contains the Gudhi::persistence_matrix::Base_swap class and Gudhi::persistence_matrix::Dummy_base_swa...
Contains the Gudhi::persistence_matrix::Chain_column_extra_properties class and Gudhi::persistence_ma...
Contains the Gudhi::persistence_matrix::Chain_pairing class and Gudhi::persistence_matrix::Dummy_chai...
Contains the Gudhi::persistence_matrix::Chain_representative_cycles class and Gudhi::persistence_matr...
Contains the Gudhi::persistence_matrix::Chain_barcode_swap and Gudhi::persistence_matrix::Chain_vine_...
Class defining operators for the field.
Definition: Z2_field_operators.h:32
A base matrix (also see Base_matrix), but with column compression. That is, all identical columns in ...
Definition: Base_matrix_with_column_compression.h:46
A basic matrix structure allowing to easily manipulate and access entire columns and rows,...
Definition: Base_matrix.h:39
Class managing the barcode for Boundary_matrix if the option was enabled.
Definition: base_pairing.h:56
Class managing the column and row swaps in Base_matrix and Boundary_matrix.
Definition: base_swap.h:49
Matrix structure to store the ordered boundary matrix of a filtered complex in order to compute its ...
Definition: Boundary_matrix.h:44
Class managing the pivot and partitioning of columns in Chain_matrix.
Definition: chain_column_extra_properties.h:57
Matrix structure storing a compatible base of a filtered chain complex. See . The base is constructed...
Definition: Chain_matrix.h:50
Class managing the barcode for Chain_matrix if the option was enabled.
Definition: chain_pairing.h:48
Class managing the representative cycles for Chain_matrix if the option was enabled.
Definition: chain_rep_cycles.h:52
Class managing the vine swaps for Chain_matrix.
Definition: chain_vine_swap.h:240
Matrix entry class. Stores by default only the row index it belongs to, but can also store its column...
Definition: entry_types.h:195
Column class following the PersistenceMatrixColumn concept. Not compatible with row access.
Definition: heap_column.h:51
Overlay for non-basic matrices replacing all input and output MatIdx indices of the original methods ...
Definition: Id_to_index_overlay.h:42
Column class following the PersistenceMatrixColumn concept.
Definition: intrusive_list_column.h:49
Column class following the PersistenceMatrixColumn concept.
Definition: intrusive_set_column.h:50
Column class following the PersistenceMatrixColumn concept.
Definition: list_column.h:50
Class managing the maximal dimension of a cell represented in the inheriting matrix,...
Definition: matrix_dimension_holders.h:119
Class managing the maximal dimension of a cell represented in the inheriting matrix,...
Definition: matrix_dimension_holders.h:57
Class managing the row access for the inheriting matrix.
Definition: matrix_row_access.h:54
Data structure for matrices, and in particular thought for matrices representing filtered complexes i...
Definition: Matrix.h:144
std::vector< ID_index > Cycle
Type of a representative cycle. Vector of row indices.
Definition: Matrix.h:541
std::enable_if_t< std::is_integral_v< Integer_index > > multiply_target_and_add_to(Integer_index sourceColumnIndex, int coefficient, Integer_index targetColumnIndex)
Multiplies the target column with the coefficient and then adds the source column to it....
Definition: Matrix.h:1777
void set_characteristic(Characteristic characteristic)
Sets the characteristic of the coefficient field if PersistenceMatrixOptions::is_z2 is false,...
Definition: Matrix.h:1524
const std::vector< Cycle > & get_representative_cycles()
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: Matrix.h:2054
Dimension get_column_dimension(Index columnIndex) const
Returns the dimension of the given cell. Only available for non-basic matrices.
Definition: Matrix.h:1747
void swap_rows(Index rowIndex1, Index rowIndex2)
Only available for base matrices without column compression and simple boundary matrices (only storin...
Definition: Matrix.h:1988
Index get_column_with_pivot(ID_index cellIndex) const
Returns the MatIdx index of the column which has the given row index as pivot. Only available for RU ...
Definition: Matrix.h:1918
std::enable_if_t< std::is_integral_v< Integer_index > > multiply_source_and_add_to(int coefficient, Integer_index sourceColumnIndex, Integer_index targetColumnIndex)
Multiplies the source column with the coefficient before adding it to the target column....
Definition: Matrix.h:1807
Entry< Matrix< PersistenceMatrixOptions > > Matrix_entry
Type of a matrix entry. See Entry for a more detailed description.
Definition: Matrix.h:227
std::enable_if_t<!std::is_integral_v< Entry_range > > multiply_target_and_add_to(const Entry_range &sourceColumn, int coefficient, Index targetColumnIndex)
Multiplies the target column with the coefficient and then adds the given range of Entry to it....
Definition: Matrix.h:1790
void zero_column(Index columnIndex)
Zeroes the column at the given index. Not available for chain matrices and for base matrices with col...
Definition: Matrix.h:1858
Matrix(unsigned int numberOfColumns, Characteristic characteristic=Matrix::get_null_value< Characteristic >())
Constructs a new empty matrix and reserves space for the given number of columns.
Definition: Matrix.h:1445
Index vine_swap(Index columnIndex1, Index columnIndex2)
Only available if PersistenceMatrixOptions::has_vine_update is true and if it is either a chain matri...
Definition: Matrix.h:2034
void zero_column(Index columnIndex, bool inR)
Only available for RU matrices. Zeroes the column at the given index in if inR is true or in if inR...
Definition: Matrix.h:1867
typename std::conditional< hasFixedBarcode, std::vector< Bar >, typename std::conditional< PersistenceMatrixOptions::has_removable_columns, std::list< Bar >, std::vector< Bar > >::type >::type Barcode
Type of the computed barcode. It is either a list of Matrix::Bar or a vector of Matrix::Bar,...
Definition: Matrix.h:447
Matrix(const Matrix &matrixToCopy)
Copy constructor.
Definition: Matrix.h:1501
const Barcode & get_current_barcode()
Returns the current barcode of the matrix. Available only if PersistenceMatrixOptions::has_column_pai...
Definition: Matrix.h:1955
std::enable_if_t<!std::is_integral_v< Entry_range > > add_to(const Entry_range &sourceColumn, Index targetColumnIndex)
Adds the given range of Entry onto the column at targetColumnIndex in the matrix. Only available for ...
Definition: Matrix.h:1765
typename Field_operators::Element Element
Type of a field element.
Definition: Matrix.h:163
std::enable_if_t<!std::is_integral_v< Entry_range > > multiply_source_and_add_to(int coefficient, const Entry_range &sourceColumn, Index targetColumnIndex)
Multiplies the source column with the coefficient before adding it to the target column....
Definition: Matrix.h:1820
ID_index get_pivot(Index columnIndex)
Returns the row index of the pivot of the given column. Only available for non-basic matrices.
Definition: Matrix.h:1930
Returned_column & get_column(Index columnIndex)
Returns the column at the given MatIdx index. For RU matrices, is equivalent to get_column(columnInde...
Definition: Matrix.h:1609
typename PersistenceMatrixOptions::Dimension Dimension
Definition: Matrix.h:150
const Cycle & get_representative_cycle(const Bar &bar)
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: Matrix.h:2062
void swap_columns(Index columnIndex1, Index columnIndex2)
Only available for base matrices without column compression and simple boundary matrices (only storin...
Definition: Matrix.h:1977
bool is_zero_entry(Index columnIndex, ID_index rowIndex)
Indicates if the entry at given coordinates has value zero.
Definition: Matrix.h:1880
typename PersistenceMatrixOptions::Index Index
Definition: Matrix.h:147
void zero_entry(Index columnIndex, ID_index rowIndex, bool inR)
Only available for RU matrices. Zeroes the entry at the given coordinates in if inR is true or in i...
Definition: Matrix.h:1845
Matrix(const std::function< bool(Pos_index, Pos_index)> &birthComparator, const std::function< bool(Pos_index, Pos_index)> &deathComparator)
Constructs a new empty matrix with the given comparator functions. Only available when those comparat...
Definition: Matrix.h:1457
void insert_column(const Container &column, Index columnIndex)
Inserts a new ordered column at the given index by copying the given range of Entry_representative....
Definition: Matrix.h:1554
void zero_entry(Index columnIndex, ID_index rowIndex)
Zeroes the entry at the given coordinates. Not available for chain matrices and for base matrices wit...
Definition: Matrix.h:1836
Matrix(unsigned int numberOfColumns, const std::function< bool(Pos_index, Pos_index)> &birthComparator, const std::function< bool(Pos_index, Pos_index)> &deathComparator, Characteristic characteristic=Matrix::get_null_value< Characteristic >())
Constructs a new empty matrix and reserves space for the given number of columns. Only available when...
Definition: Matrix.h:1486
Insertion_return insert_boundary(const Boundary_range &boundary, Dimension dim=Matrix::get_null_value< Dimension >())
Inserts at the end of the matrix a new ordered column corresponding to the given boundary....
Definition: Matrix.h:1572
Returned_row & get_row(ID_index rowIndex)
Only available if PersistenceMatrixOptions::has_row_access is true. Returns the row at the given row ...
Definition: Matrix.h:1637
Pool_entry_constructor< Matrix_entry > Entry_constructor
Entry constructor/destructor used by the matrix. Uses a pool of entries to accelerate memory manageme...
Definition: Matrix.h:239
const Column & get_column(Index columnIndex, bool inR)
Only available for RU matrices without Column_indexation_types::IDENTIFIER indexing....
Definition: Matrix.h:1623
static New_entry_constructor< Matrix_entry > defaultEntryConstructor
Default entry constructor/destructor, using classic new and delete. For now, only used as default val...
Definition: Matrix.h:234
void remove_last()
Removes the last inserted column/cell from the matrix. If the matrix is non basic,...
Definition: Matrix.h:1718
Insertion_return insert_boundary(ID_index cellIndex, const Boundary_range &boundary, Dimension dim=Matrix::get_null_value< Dimension >())
Only available for non-basic matrices. It does the same as the other version, but allows the boundary...
Definition: Matrix.h:1590
bool is_zero_column(Index columnIndex)
Indicates if the column at given index has value zero.
Definition: Matrix.h:1899
const Row & get_row(ID_index rowIndex, bool inR)
Only available for RU matrices without Column_indexation_types::IDENTIFIER indexing....
Definition: Matrix.h:1655
void erase_empty_row(ID_index rowIndex)
The effect varies depending on the matrices and the options:
Definition: Matrix.h:1680
Matrix(Matrix &&other) noexcept
Move constructor. After the move, the given matrix will be empty.
Definition: Matrix.h:1509
Matrix()
Default constructor. Initializes an empty matrix.
Definition: Matrix.h:1420
const Column & get_column(Index columnIndex) const
Only available for chain matrices. Returns the column at the given MatIdx index. The type of the colu...
Definition: Matrix.h:1616
bool vine_swap(Pos_index index)
Only available if PersistenceMatrixOptions::has_vine_update is true and if it is either a boundary ma...
Definition: Matrix.h:2023
const Row & get_row(ID_index rowIndex) const
Only available for chain matrices and matrices with column compression. Returns the row at the given ...
Definition: Matrix.h:1646
void remove_column(Index columnIndex)
Only available for base matrices without column compression and if PersistenceMatrixOptions::has_map_...
Definition: Matrix.h:1670
Matrix & operator=(Matrix other)
Assign operator.
Definition: Matrix.h:1939
bool vine_swap_with_z_eq_1_case(Pos_index index)
Only available if PersistenceMatrixOptions::has_vine_update is true and if it is either a boundary ma...
Definition: Matrix.h:1999
typename PersistenceMatrixOptions::Index ID_index
Definition: Matrix.h:148
friend void swap(Matrix &matrix1, Matrix &matrix2)
Swap operator for two matrices.
Definition: Matrix.h:1232
Index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition: Matrix.h:1741
Matrix(const std::vector< Container > &columns, Characteristic characteristic=11)
Constructs a new matrix from the given ranges of Entry_representative. Each range corresponds to a co...
Definition: Matrix.h:1432
typename PersistenceMatrixOptions::Index Pos_index
Definition: Matrix.h:149
Dimension get_max_dimension() const
Returns the maximal dimension of a cell stored in the matrix. Only available for non-basic matrices a...
Definition: Matrix.h:1732
void insert_column(const Container &column)
Inserts a new ordered column at the end of the matrix by copying the given range of Entry_representat...
Definition: Matrix.h:1538
bool is_zero_entry(Index columnIndex, ID_index rowIndex, bool inR) const
Only available for RU matrices. Indicates if the entry at given coordinates has value zero in if inR...
Definition: Matrix.h:1886
typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::HEAP, Matrix_heap_column, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::LIST, Matrix_list_column, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::SET, Matrix_set_column, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::UNORDERED_SET, Matrix_unordered_set_column, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::VECTOR, Matrix_vector_column, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::INTRUSIVE_LIST, Matrix_intrusive_list_column, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::NAIVE_VECTOR, Matrix_naive_vector_column, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::SMALL_VECTOR, Matrix_small_vector_column, Matrix_intrusive_set_column >::type >::type >::type >::type >::type >::type >::type >::type Column
Type of the columns stored in the matrix. The type depends on the value of PersistenceMatrixOptions::...
Definition: Matrix.h:368
std::enable_if_t< std::is_integral_v< Integer_index > > add_to(Integer_index sourceColumnIndex, Integer_index targetColumnIndex)
Adds column at sourceColumnIndex onto the column at targetColumnIndex in the matrix....
Definition: Matrix.h:1757
typename std::conditional< PersistenceMatrixOptions::is_z2, Gudhi::persistence_fields::Z2_field_operators, typename PersistenceMatrixOptions::Field_coeff_operators >::type Field_operators
coefficients field type.
Definition: Matrix.h:159
void remove_maximal_cell(ID_index cellIndex, const std::vector< ID_index > &columnsToSwap)
Only available for chain matrices and if PersistenceMatrixOptions::has_removable_columns,...
Definition: Matrix.h:1704
const Barcode & get_current_barcode() const
Returns the current barcode of the matrix. Available only if PersistenceMatrixOptions::has_column_pai...
Definition: Matrix.h:1964
Matrix(const std::vector< Boundary_range > &orderedBoundaries, const std::function< bool(Pos_index, Pos_index)> &birthComparator, const std::function< bool(Pos_index, Pos_index)> &deathComparator, Characteristic characteristic=11)
Constructs a new matrix from the given ranges with the given comparator functions....
Definition: Matrix.h:1471
void update_representative_cycles()
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: Matrix.h:2046
Index vine_swap_with_z_eq_1_case(Index columnIndex1, Index columnIndex2)
Only available if PersistenceMatrixOptions::has_vine_update is true and if it is either a chain matri...
Definition: Matrix.h:2010
static constexpr const T get_null_value()
Returns value from a type when not set.
Definition: Matrix.h:170
typename std::conditional< PersistenceMatrixOptions::is_z2, ID_index, std::pair< ID_index, Element > >::type Entry_representative
Type used to identify an entry, for example when inserting a boundary. If PersistenceMatrixOptions::i...
Definition: Matrix.h:251
void remove_maximal_cell(Index columnIndex)
Only available for RU and chain matrices and if PersistenceMatrixOptions::has_removable_columns and P...
Definition: Matrix.h:1690
bool is_zero_column(Index columnIndex, bool inR)
Only available for RU matrices. Indicates if the column at given index has value zero in if inR is t...
Definition: Matrix.h:1905
typename std::conditional< PersistenceMatrixOptions::has_intrusive_rows, boost::intrusive::list< Matrix_entry, boost::intrusive::constant_time_size< false >, boost::intrusive::base_hook< Base_hook_matrix_row > >, std::set< Matrix_entry, RowEntryComp > >::type Row
Type of the rows stored in the matrix. Is either an intrusive list of Matrix_entry (not ordered) if P...
Definition: Matrix.h:274
Column class following the PersistenceMatrixColumn concept.
Definition: naive_vector_column.h:51
Overlay for chain matrices replacing all input and output MatIdx indices of the original methods with...
Definition: Position_to_index_overlay.h:40
Matrix structure to store the ordered boundary matrix of a filtered complex in order to compute its ...
Definition: RU_matrix.h:42
Class managing the barcode for RU_matrix if the option was enabled.
Definition: ru_pairing.h:54
Class managing the representative cycles for RU_matrix if the option was enabled.
Definition: ru_rep_cycles.h:52
Class managing the vine swaps for RU_matrix.
Definition: ru_vine_swap.h:74
Class managing the row access for the columns.
Definition: row_access.h:51
Column class following the PersistenceMatrixColumn concept.
Definition: set_column.h:50
Column class following the PersistenceMatrixColumn concept.
Definition: unordered_set_column.h:67
Column class following the PersistenceMatrixColumn concept.
Definition: vector_column.h:52
Contains the Gudhi::persistence_matrix::Column_dimension_holder class and Gudhi::persistence_matrix::...
Contains different versions of Gudhi::persistence_matrix::Entry factories.
Contains the Gudhi::persistence_matrix::Entry, Gudhi::persistence_matrix::Entry_column_index and Gudh...
Contains the Gudhi::persistence_matrix::Heap_column class. Also defines the std::hash method for Gudh...
Contains the Gudhi::persistence_matrix::Intrusive_list_column class. Also defines the std::hash metho...
Contains the Gudhi::persistence_matrix::Intrusive_set_column class. Also defines the std::hash method...
Contains the Gudhi::persistence_matrix::List_column class. Also defines the std::hash method for Gudh...
Contains the Gudhi::persistence_matrix::Matrix_max_dimension_holder Gudhi::persistence_matrix::Matrix...
Contains the Gudhi::persistence_matrix::Matrix_row_access class and Gudhi::persistence_matrix::Dummy_...
Contains the Gudhi::persistence_matrix::Naive_vector_column class. Also defines the std::hash method ...
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Contains Gudhi::persistence_matrix::Persistence_interval class.
Contains the options for the matrix template.
Contains the Gudhi::persistence_matrix::Row_access class and Gudhi::persistence_matrix::Dummy_row_acc...
Contains the Gudhi::persistence_matrix::RU_pairing class and Gudhi::persistence_matrix::Dummy_ru_pair...
Contains the Gudhi::persistence_matrix::RU_representative_cycles class and Gudhi::persistence_matrix:...
Contains the Gudhi::persistence_matrix::RU_vine_swap class, as well as the Gudhi::persistence_matrix:...
Contains the Gudhi::persistence_matrix::Set_column class. Also defines the std::hash method for Gudhi...
Class managing the dimension access of a column.
Definition: column_dimension_holder.h:51
Empty structure. Inherited instead of Base_pairing, when the computation of the barcode was not enabl...
Definition: base_pairing.h:38
Empty structure. Inherited instead of Base_swap, when the column and row swaps are not enabled.
Definition: base_swap.h:33
Empty structure. Inherited instead of Chain_pairing, when the computation of the barcode was not enab...
Definition: chain_pairing.h:34
Empty structure. Inherited instead of Chain_column_extra_properties, when the columns are not meant f...
Definition: chain_column_extra_properties.h:34
Empty structure. Inherited instead of Chain_representative_cycles, when the computation of the repres...
Definition: chain_rep_cycles.h:36
Empty structure. Inherited instead of Chain_vine_swap, when vine swaps are not enabled.
Definition: chain_vine_swap.h:56
Empty structure. Inherited instead of Column_dimension_holder, when the columns are not storing a dim...
Definition: column_dimension_holder.h:33
Empty structure. Inherited instead of Matrix_max_dimension_holder or Matrix_all_dimension_holder,...
Definition: matrix_dimension_holders.h:36
Empty structure. Inherited instead of Matrix_row_access, when the the row access is not enabled.
Definition: matrix_row_access.h:33
Empty structure. Inherited instead of Row_access, if the row access is not enabled.
Definition: row_access.h:33
Empty structure. Inherited instead of RU_pairing, when the computation of the barcode was not enabled...
Definition: ru_pairing.h:36
Empty structure. Inherited instead of RU_representative_cycles, when the computation of the represent...
Definition: ru_rep_cycles.h:36
Empty structure. Inherited instead of RU_vine_swap, when vine swaps are not enabled.
Definition: ru_vine_swap.h:40
Compares two entries by their position in the row. They are assume to be in the same row.
Definition: Matrix.h:256
Type for an interval in a persistent diagram or barcode. Stores the birth, death and dimension of the...
Definition: persistence_interval.h:40
Concept of the template parameter for the class Matrix.
Definition: PersistenceMatrixOptions.h:32
static const Column_indexation_types column_indexation_type
Specifies the desired indexation scheme to access the methods of the matrix. See matrix description a...
Definition: PersistenceMatrixOptions.h:66
static const Column_types column_type
Specifies the desired column type. All possible column types are described in Column_types.
Definition: PersistenceMatrixOptions.h:60
static const bool has_matrix_maximal_dimension_access
Only enabled for boundary and chain matrices, i.e., when at least one of the following is true: has_c...
Definition: PersistenceMatrixOptions.h:142
unspecified Dimension
Type for the dimension. Has to be an integer type. If unsigned, the maximal value of the type should ...
Definition: PersistenceMatrixOptions.h:42
static const bool has_map_column_container
If set to true, the underlying container containing the matrix columns is an std::unordered_map....
Definition: PersistenceMatrixOptions.h:101
static const bool has_column_compression
Only enabled for base matrices (i.e., none of the following is true: has_column_pairings,...
Definition: PersistenceMatrixOptions.h:83
static const bool has_row_access
If set to true, enables the method Matrix::get_row.
Definition: PersistenceMatrixOptions.h:111
static const bool can_retrieve_representative_cycles
If set to true, enables the methods Matrix::update_representative_cycles and Matrix::get_representati...
Definition: PersistenceMatrixOptions.h:161
static const bool has_removable_rows
Only enabled if has_row_access is true, ignored otherwise. If set to true, the underlying container c...
Definition: PersistenceMatrixOptions.h:124
static const bool has_column_and_row_swaps
Only enabled for base matrices or simple boundary matrices, i.e., when both has_vine_update and can_r...
Definition: PersistenceMatrixOptions.h:89
static const bool is_z2
If true, indicates that the values contained in the matrix are in and can therefore be treated like ...
Definition: PersistenceMatrixOptions.h:56
unspecified Index
Type for the different indexation types and should be able to contain the maximal number of columns o...
Definition: PersistenceMatrixOptions.h:48
static const bool has_column_pairings
If set to true, enables the method Matrix::get_current_barcode. The matrix will then either be a boun...
Definition: PersistenceMatrixOptions.h:148
unspecified Field_coeff_operators
Field operators. Has to follow the FieldOperators concept. The type will not be used if is_z2 is set ...
Definition: PersistenceMatrixOptions.h:37
static const bool has_vine_update
If set to true, enables the methods Matrix::vine_swap and Matrix::vine_swap_with_z_eq_1_case....
Definition: PersistenceMatrixOptions.h:154
static const bool is_of_boundary_type
Only used, when at least one of the following is true: has_column_pairings, has_vine_update or can_re...
Definition: PersistenceMatrixOptions.h:132
static const bool has_removable_columns
If set to true, enables the methods Matrix::remove_maximal_cell and Matrix::remove_last,...
Definition: PersistenceMatrixOptions.h:106
static const bool has_intrusive_rows
Only enabled if has_row_access is true, ignored otherwise. If set to true, the underlying container r...
Definition: PersistenceMatrixOptions.h:117
Contains the Gudhi::persistence_matrix::Unordered_set_column class. Also defines the std::hash method...
Contains the Gudhi::persistence_matrix::Vector_column class. Also defines the std::hash method for Gu...