Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix > Class Template Reference

A base matrix (also see Base_matrix), but with column compression. That is, all identical columns in the matrix are compressed together as the same column. For matrices with a lot of redundant columns, this will save a lot of space. Also, any addition made onto a column will be performed at the same time on all other identical columns, which is an advantage for the cohomology algorithm for example. More...

#include <gudhi/Persistence_matrix/Base_matrix_with_column_compression.h>

Classes

class  Column
 Type for columns. Only one for each "column class" is explicitly constructed. More...
 

Public Types

using Index = typename Master_matrix::Index
 
using Dimension = typename Master_matrix::Dimension
 
using Field_operators = typename Master_matrix::Field_operators
 Field operators class. Necessary only if PersistenceMatrixOptions::is_z2 is false.
 
using Field_element = typename Master_matrix::Element
 
using Row = typename Master_matrix::Row
 
using Entry_constructor = typename Master_matrix::Entry_constructor
 
using Column_settings = typename Master_matrix::Column_settings
 

Public Member Functions

 Base_matrix_with_column_compression (Column_settings *colSettings)
 Constructs an empty matrix. More...
 
template<class Container >
 Base_matrix_with_column_compression (const std::vector< Container > &columns, Column_settings *colSettings)
 Constructs a matrix from the given ordered columns. The columns are inserted in the given order. If no identical column already existed, a copy of the column is stored. If an identical one existed, no new column is constructed and the relationship between the two is registered in an union-find structure. More...
 
 Base_matrix_with_column_compression (unsigned int numberOfColumns, Column_settings *colSettings)
 Constructs a new empty matrix and reserves space for the given number of columns. More...
 
 Base_matrix_with_column_compression (const Base_matrix_with_column_compression &matrixToCopy, Column_settings *colSettings=nullptr)
 Copy constructor. If colSettings is not a null pointer, its value is kept instead of the one in the copied matrix. More...
 
 Base_matrix_with_column_compression (Base_matrix_with_column_compression &&other) noexcept
 Move constructor. More...
 
 ~Base_matrix_with_column_compression ()
 Destructor.
 
template<class Container >
void insert_column (const Container &column)
 Inserts a new ordered column at the end of the matrix by copying the given range of Matrix::Entry_representative. The content of the range is assumed to be sorted by increasing ID value. More...
 
template<class Boundary_range >
void insert_boundary (const Boundary_range &boundary, Dimension dim=Master_matrix::template get_null_value< Dimension >())
 Same as insert_column, only for interface purposes. The given dimension is ignored and not stored. More...
 
const Columnget_column (Index columnIndex)
 Returns the column at the given MatIdx index. The type of the column depends on the chosen options, see PersistenceMatrixOptions::column_type. More...
 
const Rowget_row (Index rowIndex) const
 Only available if PersistenceMatrixOptions::has_row_access is true. Returns the row at the given row index of the compressed matrix. The type of the row depends on the chosen options, see PersistenceMatrixOptions::has_intrusive_rows. Note that the row will be from the compressed matrix, that is, the one with only unique columns. More...
 
void erase_empty_row (Index rowIndex)
 If PersistenceMatrixOptions::has_row_access and PersistenceMatrixOptions::has_removable_rows are true: assumes that the row is empty and removes it. Otherwise, does nothing. More...
 
Index get_number_of_columns () const
 Returns the current number of columns in the matrix, counting also the redundant columns. More...
 
template<class Entry_range_or_column_index >
void add_to (const Entry_range_or_column_index &sourceColumn, Index targetColumnIndex)
 Adds column represented by sourceColumn onto the column at targetColumnIndex in the matrix. More...
 
template<class Entry_range_or_column_index >
void multiply_target_and_add_to (const Entry_range_or_column_index &sourceColumn, const Field_element &coefficient, Index targetColumnIndex)
 Multiplies the target column with the coefficient and then adds the source column to it. That is: targetColumn = (targetColumn * coefficient) + sourceColumn. More...
 
template<class Entry_range_or_column_index >
void multiply_source_and_add_to (const Field_element &coefficient, const Entry_range_or_column_index &sourceColumn, Index targetColumnIndex)
 Multiplies the source column with the coefficient before adding it to the target column. That is: targetColumn += (coefficient * sourceColumn). The source column will not be modified. More...
 
bool is_zero_entry (Index columnIndex, Index rowIndex)
 Indicates if the entry at given coordinates has value zero. More...
 
bool is_zero_column (Index columnIndex)
 Indicates if the column at given index has value zero. More...
 
void reset (Column_settings *colSettings)
 Resets the matrix to an empty matrix. More...
 
Base_matrix_with_column_compressionoperator= (const Base_matrix_with_column_compression &other)
 Assign operator.
 

Friends

void swap (Base_matrix_with_column_compression &matrix1, Base_matrix_with_column_compression &matrix2)
 Swap operator.
 

Detailed Description

template<class Master_matrix>
class Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >

A base matrix (also see Base_matrix), but with column compression. That is, all identical columns in the matrix are compressed together as the same column. For matrices with a lot of redundant columns, this will save a lot of space. Also, any addition made onto a column will be performed at the same time on all other identical columns, which is an advantage for the cohomology algorithm for example.

Template Parameters
Master_matrixAn instantiation of Matrix from which all types and options are deduced.

Member Typedef Documentation

◆ Column_settings

template<class Master_matrix >
using Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Column_settings = typename Master_matrix::Column_settings

Structure giving access to the columns to necessary external classes.

◆ Dimension

template<class Master_matrix >
using Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Dimension = typename Master_matrix::Dimension

Dimension value type.

◆ Entry_constructor

template<class Master_matrix >
using Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Entry_constructor = typename Master_matrix::Entry_constructor

Factory of Entry classes.

◆ Field_element

template<class Master_matrix >
using Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Field_element = typename Master_matrix::Element

Field element value type.

◆ Index

template<class Master_matrix >
using Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Index = typename Master_matrix::Index

Container index type.

◆ Row

template<class Master_matrix >
using Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Row = typename Master_matrix::Row

Row type, only necessary with row access option.

Constructor & Destructor Documentation

◆ Base_matrix_with_column_compression() [1/5]

template<class Master_matrix >
Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Base_matrix_with_column_compression ( Column_settings colSettings)
inline

Constructs an empty matrix.

Parameters
colSettingsPointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators.

◆ Base_matrix_with_column_compression() [2/5]

template<class Master_matrix >
template<class Container >
Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Base_matrix_with_column_compression ( const std::vector< Container > &  columns,
Column_settings colSettings 
)
inline

Constructs a matrix from the given ordered columns. The columns are inserted in the given order. If no identical column already existed, a copy of the column is stored. If an identical one existed, no new column is constructed and the relationship between the two is registered in an union-find structure.

Template Parameters
ContainerRange type for Matrix::Entry_representative ranges. Assumed to have a begin(), end() and size() method.
Parameters
columnsA vector of Matrix::Entry_representative ranges to construct the columns from. The content of the ranges are assumed to be sorted by increasing ID value.
colSettingsPointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators.

◆ Base_matrix_with_column_compression() [3/5]

template<class Master_matrix >
Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Base_matrix_with_column_compression ( unsigned int  numberOfColumns,
Column_settings colSettings 
)
inline

Constructs a new empty matrix and reserves space for the given number of columns.

Parameters
numberOfColumnsNumber of columns to reserve space for.
colSettingsPointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators.

◆ Base_matrix_with_column_compression() [4/5]

template<class Master_matrix >
Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Base_matrix_with_column_compression ( const Base_matrix_with_column_compression< Master_matrix > &  matrixToCopy,
Column_settings colSettings = nullptr 
)
inline

Copy constructor. If colSettings is not a null pointer, its value is kept instead of the one in the copied matrix.

Parameters
matrixToCopyMatrix to copy.
colSettingsEither a pointer to an existing setting structure for the columns or a null pointer. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. If null pointer, the pointer stored in matrixToCopy is used instead.

◆ Base_matrix_with_column_compression() [5/5]

template<class Master_matrix >
Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::Base_matrix_with_column_compression ( Base_matrix_with_column_compression< Master_matrix > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherMatrix to move.

Member Function Documentation

◆ add_to()

template<class Master_matrix >
template<class Entry_range_or_column_index >
void Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::add_to ( const Entry_range_or_column_index &  sourceColumn,
Index  targetColumnIndex 
)
inline

Adds column represented by sourceColumn onto the column at targetColumnIndex in the matrix.

The representatives of redundant columns are summed together, which means that all column compressed together with the target column are affected by the change, not only the target.

Template Parameters
Entry_range_or_column_indexEither a range of Entry with a begin() and end() method, or any integer type.
Parameters
sourceColumnEither an entry range or the MatIdx index of the column to add.
targetColumnIndexMatIdx index of the target column.

◆ erase_empty_row()

template<class Master_matrix >
void Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::erase_empty_row ( Index  rowIndex)
inline

If PersistenceMatrixOptions::has_row_access and PersistenceMatrixOptions::has_removable_rows are true: assumes that the row is empty and removes it. Otherwise, does nothing.

Warning
The removed rows are always assumed to be empty. If it is not the case, the deleted row entries are not removed from their columns. And in the case of intrusive rows, this will generate a segmentation fault when the column entries are destroyed later. The row access is just meant as a "read only" access to the rows and the erase_empty_row method just as a way to specify that a row is empty and can therefore be removed from dictionaries. This allows to avoid testing the emptiness of a row at each column entry removal, what can be quite frequent.
Parameters
rowIndexRow index of the empty row.

◆ get_column()

template<class Master_matrix >
const Base_matrix_with_column_compression< Master_matrix >::Column & Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::get_column ( Index  columnIndex)
inline

Returns the column at the given MatIdx index. The type of the column depends on the chosen options, see PersistenceMatrixOptions::column_type.

Remark: the method it-self is not const, because of the path compression optimization of the union-find structure, when a column is looked up.

Parameters
columnIndexMatIdx index of the column to return.
Returns
Const reference to the column.

◆ get_number_of_columns()

template<class Master_matrix >
Base_matrix_with_column_compression< Master_matrix >::Index Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::get_number_of_columns
inline

Returns the current number of columns in the matrix, counting also the redundant columns.

Returns
The number of columns.

◆ get_row()

template<class Master_matrix >
const Base_matrix_with_column_compression< Master_matrix >::Row & Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::get_row ( Index  rowIndex) const
inline

Only available if PersistenceMatrixOptions::has_row_access is true. Returns the row at the given row index of the compressed matrix. The type of the row depends on the chosen options, see PersistenceMatrixOptions::has_intrusive_rows. Note that the row will be from the compressed matrix, that is, the one with only unique columns.

Parameters
rowIndexRow index of the row to return.
Returns
Const reference to the row.

◆ insert_boundary()

template<class Master_matrix >
template<class Boundary_range >
void Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::insert_boundary ( const Boundary_range &  boundary,
Dimension  dim = Master_matrix::template get_null_value<Dimension>() 
)
inline

Same as insert_column, only for interface purposes. The given dimension is ignored and not stored.

Template Parameters
Boundary_rangeRange of Matrix::Entry_representative. Assumed to have a begin(), end() and size() method.
Parameters
boundaryRange of Matrix::Entry_representative from which the column has to be constructed. Assumed to be ordered by increasing ID value.
dimIgnored.

◆ insert_column()

template<class Master_matrix >
template<class Container >
void Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::insert_column ( const Container &  column)
inline

Inserts a new ordered column at the end of the matrix by copying the given range of Matrix::Entry_representative. The content of the range is assumed to be sorted by increasing ID value.

Template Parameters
ContainerRange of Matrix::Entry_representative. Assumed to have a begin(), end() and size() method.
Parameters
columnRange of Matrix::Entry_representative from which the column has to be constructed. Assumed to be ordered by increasing ID value.

◆ is_zero_column()

template<class Master_matrix >
bool Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::is_zero_column ( Index  columnIndex)
inline

Indicates if the column at given index has value zero.

Parameters
columnIndexMatIdx index of the column.
Returns
true If the column has value zero.
false Otherwise.

◆ is_zero_entry()

template<class Master_matrix >
bool Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::is_zero_entry ( Index  columnIndex,
Index  rowIndex 
)
inline

Indicates if the entry at given coordinates has value zero.

Parameters
columnIndexMatIdx index of the column of the entry.
rowIndexRow index of the row of the entry.
Returns
true If the entry has value zero.
false Otherwise.

◆ multiply_source_and_add_to()

template<class Master_matrix >
template<class Entry_range_or_column_index >
void Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::multiply_source_and_add_to ( const Field_element coefficient,
const Entry_range_or_column_index &  sourceColumn,
Index  targetColumnIndex 
)
inline

Multiplies the source column with the coefficient before adding it to the target column. That is: targetColumn += (coefficient * sourceColumn). The source column will not be modified.

The representatives of redundant columns are summed together, which means that all column compressed together with the target column are affected by the change, not only the target.

Template Parameters
Entry_range_or_column_indexEither a range of Entry with a begin() and end() method, or any integer type.
Parameters
coefficientValue to multiply.
sourceColumnEither a Entry range or the MatIdx index of the column to add.
targetColumnIndexMatIdx index of the target column.

◆ multiply_target_and_add_to()

template<class Master_matrix >
template<class Entry_range_or_column_index >
void Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::multiply_target_and_add_to ( const Entry_range_or_column_index &  sourceColumn,
const Field_element coefficient,
Index  targetColumnIndex 
)
inline

Multiplies the target column with the coefficient and then adds the source column to it. That is: targetColumn = (targetColumn * coefficient) + sourceColumn.

The representatives of redundant columns are summed together, which means that all column compressed together with the target column are affected by the change, not only the target.

Template Parameters
Entry_range_or_column_indexEither a range of Entry with a begin() and end() method, or any integer type.
Parameters
sourceColumnEither a Entry range or the MatIdx index of the column to add.
coefficientValue to multiply.
targetColumnIndexMatIdx index of the target column.

◆ reset()

template<class Master_matrix >
void Gudhi::persistence_matrix::Base_matrix_with_column_compression< Master_matrix >::reset ( Column_settings colSettings)
inline

Resets the matrix to an empty matrix.

Parameters
colSettingsPointer to the entry factory.

The documentation for this class was generated from the following file: