multipers 2.3.3b6__cp312-cp312-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of multipers might be problematic. Click here for more details.
- multipers/.dylibs/libc++.1.0.dylib +0 -0
- multipers/.dylibs/libtbb.12.16.dylib +0 -0
- multipers/__init__.py +33 -0
- multipers/_signed_measure_meta.py +453 -0
- multipers/_slicer_meta.py +211 -0
- multipers/array_api/__init__.py +45 -0
- multipers/array_api/numpy.py +41 -0
- multipers/array_api/torch.py +58 -0
- multipers/data/MOL2.py +458 -0
- multipers/data/UCR.py +18 -0
- multipers/data/__init__.py +1 -0
- multipers/data/graphs.py +466 -0
- multipers/data/immuno_regions.py +27 -0
- multipers/data/minimal_presentation_to_st_bf.py +0 -0
- multipers/data/pytorch2simplextree.py +91 -0
- multipers/data/shape3d.py +101 -0
- multipers/data/synthetic.py +113 -0
- multipers/distances.py +202 -0
- multipers/filtration_conversions.pxd +229 -0
- multipers/filtration_conversions.pxd.tp +84 -0
- multipers/filtrations/__init__.py +18 -0
- multipers/filtrations/density.py +574 -0
- multipers/filtrations/filtrations.py +361 -0
- multipers/filtrations.pxd +224 -0
- multipers/function_rips.cpython-312-darwin.so +0 -0
- multipers/function_rips.pyx +105 -0
- multipers/grids.cpython-312-darwin.so +0 -0
- multipers/grids.pyx +433 -0
- multipers/gudhi/Persistence_slices_interface.h +132 -0
- multipers/gudhi/Simplex_tree_interface.h +239 -0
- multipers/gudhi/Simplex_tree_multi_interface.h +551 -0
- multipers/gudhi/cubical_to_boundary.h +59 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
- multipers/gudhi/gudhi/Debug_utils.h +45 -0
- multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
- multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
- multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
- multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
- multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
- multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
- multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
- multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
- multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
- multipers/gudhi/gudhi/Matrix.h +2107 -0
- multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
- multipers/gudhi/gudhi/Multi_persistence/Box.h +174 -0
- multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
- multipers/gudhi/gudhi/Off_reader.h +173 -0
- multipers/gudhi/gudhi/One_critical_filtration.h +1441 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
- multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
- multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
- multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
- multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
- multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
- multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
- multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
- multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
- multipers/gudhi/gudhi/Persistent_cohomology.h +745 -0
- multipers/gudhi/gudhi/Points_off_io.h +171 -0
- multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
- multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
- multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
- multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -0
- multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
- multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
- multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
- multipers/gudhi/gudhi/distance_functions.h +62 -0
- multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
- multipers/gudhi/gudhi/persistence_interval.h +253 -0
- multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
- multipers/gudhi/gudhi/reader_utils.h +367 -0
- multipers/gudhi/mma_interface_coh.h +256 -0
- multipers/gudhi/mma_interface_h0.h +223 -0
- multipers/gudhi/mma_interface_matrix.h +293 -0
- multipers/gudhi/naive_merge_tree.h +536 -0
- multipers/gudhi/scc_io.h +310 -0
- multipers/gudhi/truc.h +1403 -0
- multipers/io.cpython-312-darwin.so +0 -0
- multipers/io.pyx +644 -0
- multipers/ml/__init__.py +0 -0
- multipers/ml/accuracies.py +90 -0
- multipers/ml/invariants_with_persistable.py +79 -0
- multipers/ml/kernels.py +176 -0
- multipers/ml/mma.py +713 -0
- multipers/ml/one.py +472 -0
- multipers/ml/point_clouds.py +352 -0
- multipers/ml/signed_measures.py +1589 -0
- multipers/ml/sliced_wasserstein.py +461 -0
- multipers/ml/tools.py +113 -0
- multipers/mma_structures.cpython-312-darwin.so +0 -0
- multipers/mma_structures.pxd +128 -0
- multipers/mma_structures.pyx +2786 -0
- multipers/mma_structures.pyx.tp +1094 -0
- multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
- multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
- multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
- multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
- multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
- multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
- multipers/multiparameter_edge_collapse.py +41 -0
- multipers/multiparameter_module_approximation/approximation.h +2330 -0
- multipers/multiparameter_module_approximation/combinatory.h +129 -0
- multipers/multiparameter_module_approximation/debug.h +107 -0
- multipers/multiparameter_module_approximation/euler_curves.h +0 -0
- multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
- multipers/multiparameter_module_approximation/heap_column.h +238 -0
- multipers/multiparameter_module_approximation/images.h +79 -0
- multipers/multiparameter_module_approximation/list_column.h +174 -0
- multipers/multiparameter_module_approximation/list_column_2.h +232 -0
- multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
- multipers/multiparameter_module_approximation/set_column.h +135 -0
- multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
- multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
- multipers/multiparameter_module_approximation/utilities.h +403 -0
- multipers/multiparameter_module_approximation/vector_column.h +223 -0
- multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
- multipers/multiparameter_module_approximation/vineyards.h +464 -0
- multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
- multipers/multiparameter_module_approximation.cpython-312-darwin.so +0 -0
- multipers/multiparameter_module_approximation.pyx +235 -0
- multipers/pickle.py +90 -0
- multipers/plots.py +456 -0
- multipers/point_measure.cpython-312-darwin.so +0 -0
- multipers/point_measure.pyx +395 -0
- multipers/simplex_tree_multi.cpython-312-darwin.so +0 -0
- multipers/simplex_tree_multi.pxd +134 -0
- multipers/simplex_tree_multi.pyx +10840 -0
- multipers/simplex_tree_multi.pyx.tp +2009 -0
- multipers/slicer.cpython-312-darwin.so +0 -0
- multipers/slicer.pxd +3034 -0
- multipers/slicer.pxd.tp +234 -0
- multipers/slicer.pyx +20481 -0
- multipers/slicer.pyx.tp +1088 -0
- multipers/tensor/tensor.h +672 -0
- multipers/tensor.pxd +13 -0
- multipers/test.pyx +44 -0
- multipers/tests/__init__.py +62 -0
- multipers/torch/__init__.py +1 -0
- multipers/torch/diff_grids.py +240 -0
- multipers/torch/rips_density.py +310 -0
- multipers-2.3.3b6.dist-info/METADATA +128 -0
- multipers-2.3.3b6.dist-info/RECORD +183 -0
- multipers-2.3.3b6.dist-info/WHEEL +6 -0
- multipers-2.3.3b6.dist-info/licenses/LICENSE +21 -0
- multipers-2.3.3b6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,769 @@
|
|
|
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
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file Base_matrix.h
|
|
13
|
+
* @author Hannah Schreiber
|
|
14
|
+
* @brief Contains the @ref Gudhi::persistence_matrix::Base_matrix class.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef PM_BASE_MATRIX_H
|
|
18
|
+
#define PM_BASE_MATRIX_H
|
|
19
|
+
|
|
20
|
+
#include <iostream> //print() only
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include <utility> //std::swap, std::move & std::exchange
|
|
23
|
+
|
|
24
|
+
namespace Gudhi {
|
|
25
|
+
namespace persistence_matrix {
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @class Base_matrix Base_matrix.h gudhi/Persistence_matrix/Base_matrix.h
|
|
29
|
+
* @ingroup persistence_matrix
|
|
30
|
+
*
|
|
31
|
+
* @brief A @ref basematrix "basic matrix" structure allowing to easily manipulate and access entire columns and rows,
|
|
32
|
+
* but not individual entries.
|
|
33
|
+
*
|
|
34
|
+
* @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced.
|
|
35
|
+
*/
|
|
36
|
+
template <class Master_matrix>
|
|
37
|
+
class Base_matrix : public Master_matrix::template Base_swap_option<Base_matrix<Master_matrix> >,
|
|
38
|
+
protected Master_matrix::Matrix_row_access_option
|
|
39
|
+
{
|
|
40
|
+
public:
|
|
41
|
+
using Index = typename Master_matrix::Index; /**< Container index type. */
|
|
42
|
+
using Dimension = typename Master_matrix::Dimension; /**< Dimension value type. */
|
|
43
|
+
/**
|
|
44
|
+
* @brief Field operators class. Necessary only if @ref PersistenceMatrixOptions::is_z2 is false.
|
|
45
|
+
*/
|
|
46
|
+
using Field_operators = typename Master_matrix::Field_operators;
|
|
47
|
+
using Field_element = typename Master_matrix::Element; /**< Type of a field element. */
|
|
48
|
+
using Column = typename Master_matrix::Column; /**< Column type. */
|
|
49
|
+
using Boundary = typename Master_matrix::Boundary; /**< Type of the column container. */
|
|
50
|
+
using Row = typename Master_matrix::Row; /**< Row type,
|
|
51
|
+
only necessary with row access option. */
|
|
52
|
+
using Entry_constructor = typename Master_matrix::Entry_constructor; /**< Factory of @ref Entry classes. */
|
|
53
|
+
using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to
|
|
54
|
+
necessary external classes. */
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @brief Constructs an empty matrix.
|
|
58
|
+
*
|
|
59
|
+
* @param colSettings Pointer to an existing setting structure for the columns. The structure should contain all
|
|
60
|
+
* the necessary external classes specifically necessary for the choosen column type, such as custom allocators.
|
|
61
|
+
*/
|
|
62
|
+
Base_matrix(Column_settings* colSettings);
|
|
63
|
+
/**
|
|
64
|
+
* @brief Constructs a matrix from the given ordered columns. The columns are inserted in the given order.
|
|
65
|
+
*
|
|
66
|
+
* @tparam Container Range type for @ref Matrix::Entry_representative ranges.
|
|
67
|
+
* Assumed to have a begin(), end() and size() method.
|
|
68
|
+
* @param columns A vector of @ref Matrix::Entry_representative ranges to construct the columns from.
|
|
69
|
+
* The content of the ranges are assumed to be sorted by increasing ID value.
|
|
70
|
+
* @param colSettings Pointer to an existing setting structure for the columns. The structure should contain all
|
|
71
|
+
* the necessary external classes specifically necessary for the choosen column type, such as custom allocators.
|
|
72
|
+
*/
|
|
73
|
+
template <class Container = Boundary>
|
|
74
|
+
Base_matrix(const std::vector<Container>& columns,
|
|
75
|
+
Column_settings* colSettings);
|
|
76
|
+
/**
|
|
77
|
+
* @brief Constructs a new empty matrix and reserves space for the given number of columns.
|
|
78
|
+
*
|
|
79
|
+
* @param numberOfColumns Number of columns to reserve space for.
|
|
80
|
+
* @param colSettings Pointer to an existing setting structure for the columns. The structure should contain all
|
|
81
|
+
* the necessary external classes specifically necessary for the choosen column type, such as custom allocators.
|
|
82
|
+
*/
|
|
83
|
+
Base_matrix(unsigned int numberOfColumns, Column_settings* colSettings);
|
|
84
|
+
/**
|
|
85
|
+
* @brief Copy constructor. If @p colSettings is not a null pointer, its value is kept
|
|
86
|
+
* instead of the one in the copied matrix.
|
|
87
|
+
*
|
|
88
|
+
* @param matrixToCopy Matrix to copy.
|
|
89
|
+
* @param colSettings Either a pointer to an existing setting structure for the columns or a null pointer.
|
|
90
|
+
* The structure should contain all the necessary external classes specifically necessary for the choosen column type,
|
|
91
|
+
* such as custom allocators. If null pointer, the pointer stored in @p matrixToCopy is used instead.
|
|
92
|
+
*/
|
|
93
|
+
Base_matrix(const Base_matrix& matrixToCopy,
|
|
94
|
+
Column_settings* colSettings = nullptr);
|
|
95
|
+
/**
|
|
96
|
+
* @brief Move constructor.
|
|
97
|
+
*
|
|
98
|
+
* @param other Matrix to move.
|
|
99
|
+
*/
|
|
100
|
+
Base_matrix(Base_matrix&& other) noexcept;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @brief Inserts a new ordered column at the end of the matrix by copying the given range of
|
|
104
|
+
* @ref Matrix::Entry_representative. The content of the range is assumed to be sorted by increasing ID value.
|
|
105
|
+
*
|
|
106
|
+
* @tparam Container Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() method.
|
|
107
|
+
* @param column Range of @ref Matrix::Entry_representative from which the column has to be constructed. Assumed to be
|
|
108
|
+
* ordered by increasing ID value.
|
|
109
|
+
*/
|
|
110
|
+
template <class Container = Boundary>
|
|
111
|
+
void insert_column(const Container& column);
|
|
112
|
+
/**
|
|
113
|
+
* @brief Inserts a new ordered column at the given index by copying the given range of
|
|
114
|
+
* @ref Matrix::Entry_representative.
|
|
115
|
+
* There should not be any other column inserted at that index which was not explicitly removed before.
|
|
116
|
+
* The content of the range is assumed to be sorted by increasing ID value.
|
|
117
|
+
* Not available when row access is enabled.
|
|
118
|
+
*
|
|
119
|
+
* @tparam Container Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() method.
|
|
120
|
+
* @param column Range of @ref Matrix::Entry_representative from which the column has to be constructed. Assumed to be
|
|
121
|
+
* ordered by increasing ID value.
|
|
122
|
+
* @param columnIndex @ref MatIdx index to which the column has to be inserted.
|
|
123
|
+
*/
|
|
124
|
+
template <class Container = Boundary>
|
|
125
|
+
void insert_column(const Container& column, Index columnIndex);
|
|
126
|
+
/**
|
|
127
|
+
* @brief Same as @ref insert_column, only for interface purposes. The given dimension is ignored and not stored.
|
|
128
|
+
*
|
|
129
|
+
* @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size()
|
|
130
|
+
* method.
|
|
131
|
+
* @param boundary Range of @ref Matrix::Entry_representative from which the column has to be constructed. Assumed to
|
|
132
|
+
* be ordered by increasing ID value.
|
|
133
|
+
* @param dim Ignored.
|
|
134
|
+
*/
|
|
135
|
+
template <class Boundary_range>
|
|
136
|
+
void insert_boundary(const Boundary_range& boundary, Dimension dim = -1);
|
|
137
|
+
/**
|
|
138
|
+
* @brief Returns the column at the given @ref MatIdx index.
|
|
139
|
+
* The type of the column depends on the choosen options, see @ref PersistenceMatrixOptions::column_type.
|
|
140
|
+
*
|
|
141
|
+
* Note that before returning the column, all column entries can eventually be reordered, if lazy swaps occurred.
|
|
142
|
+
* It is therefore recommended to avoid calling @ref get_column between column or row swaps, otherwise the benefits
|
|
143
|
+
* of the the laziness is lost.
|
|
144
|
+
*
|
|
145
|
+
* @param columnIndex @ref MatIdx index of the column to return.
|
|
146
|
+
* @return Reference to the column.
|
|
147
|
+
*/
|
|
148
|
+
Column& get_column(Index columnIndex);
|
|
149
|
+
/**
|
|
150
|
+
* @brief Only available if @ref PersistenceMatrixOptions::has_row_access is true.
|
|
151
|
+
* Returns the row at the given @ref rowindex "row index" of the matrix.
|
|
152
|
+
* The type of the row depends on the choosen options, see @ref PersistenceMatrixOptions::has_intrusive_rows.
|
|
153
|
+
*
|
|
154
|
+
* Note that before returning the row, all column entries can eventually be reordered, if lazy swaps occurred.
|
|
155
|
+
* It is therefore recommended to avoid calling @ref get_row between column or row swaps, otherwise the benefits
|
|
156
|
+
* of the the laziness is lost.
|
|
157
|
+
*
|
|
158
|
+
* @param rowIndex @ref rowindex "Row index" of the row to return.
|
|
159
|
+
* @return Reference to the row.
|
|
160
|
+
*/
|
|
161
|
+
Row& get_row(Index rowIndex);
|
|
162
|
+
/**
|
|
163
|
+
* @brief Only available if @ref PersistenceMatrixOptions::has_map_column_container is true. Otherwise, see
|
|
164
|
+
* @ref remove_last. Erases the given column from the matrix. If the given column index corresponded to the last
|
|
165
|
+
* used column index, the "new last column index" will be `columnIndex - 1`, even if a column was never explicitly
|
|
166
|
+
* inserted at this index (possible when
|
|
167
|
+
* @ref insert_column(const Container& column, Index columnIndex) "insert_column(column, columnIndex)" was used).
|
|
168
|
+
* If the column didn't existed, it will simply be considered as an empty column.
|
|
169
|
+
*
|
|
170
|
+
* If @ref PersistenceMatrixOptions::has_row_access is also true, the deleted column entries are also automatically
|
|
171
|
+
* removed from their respective rows.
|
|
172
|
+
*
|
|
173
|
+
* @param columnIndex @ref MatIdx index of the column to remove.
|
|
174
|
+
*/
|
|
175
|
+
void remove_column(Index columnIndex);
|
|
176
|
+
/**
|
|
177
|
+
* @brief Removes the last column from the matrix. The last column is at index \f$ max(ins1, ins2, rem - 1) \f$,
|
|
178
|
+
* where:
|
|
179
|
+
* - \f$ ins1 \f$ is the index of the last column inserted by
|
|
180
|
+
* @ref insert_column(const Container& column) "insert_column(column)",
|
|
181
|
+
* - \f$ ins2 \f$ is largest index used with
|
|
182
|
+
* @ref insert_column(const Container& column, Index columnIndex) "insert_column(column, columnIndex)",
|
|
183
|
+
* - \f$ rem \f$ is the last index just before the last call of @ref remove_column or @ref remove_last.
|
|
184
|
+
*
|
|
185
|
+
* If \f$ max(ins1, ins2, rem - 1) = rem - 1 \f$ but no column was explicitly inserted at that index (possible
|
|
186
|
+
* by the use of
|
|
187
|
+
* @ref insert_column(const Container& column, Index columnIndex) "insert_column(column, columnIndex)"),
|
|
188
|
+
* the column is assumed to be an empty column.
|
|
189
|
+
*
|
|
190
|
+
* See also @ref remove_column.
|
|
191
|
+
*/
|
|
192
|
+
void remove_last();
|
|
193
|
+
/**
|
|
194
|
+
* @brief If @ref PersistenceMatrixOptions::has_row_access and @ref PersistenceMatrixOptions::has_removable_rows
|
|
195
|
+
* are true: assumes that the row is empty and removes it. If @ref PersistenceMatrixOptions::has_map_column_container
|
|
196
|
+
* and @ref PersistenceMatrixOptions::has_column_and_row_swaps are true: cleans up maps used for the lazy row swaps.
|
|
197
|
+
* Otherwise, does nothing.
|
|
198
|
+
*
|
|
199
|
+
* @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row entries are not
|
|
200
|
+
* removed from their columns. And in the case of intrusive rows, this will generate a segmentation fault when
|
|
201
|
+
* the column entries are destroyed later. The row access is just meant as a "read only" access to the rows and the
|
|
202
|
+
* @ref erase_empty_row method just as a way to specify that a row is empty and can therefore be removed from
|
|
203
|
+
* dictionaries. This allows to avoid testing the emptiness of a row at each column entry removal, what can be
|
|
204
|
+
* quite frequent.
|
|
205
|
+
*
|
|
206
|
+
* @param rowIndex @ref rowindex "Row index" of the empty row.
|
|
207
|
+
*/
|
|
208
|
+
void erase_empty_row(Index rowIndex);
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @brief Returns the current number of columns in the matrix.
|
|
212
|
+
*
|
|
213
|
+
* @return The number of columns.
|
|
214
|
+
*/
|
|
215
|
+
Index get_number_of_columns() const;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @brief Adds column represented by @p sourceColumn onto the column at @p targetColumnIndex in the matrix.
|
|
219
|
+
*
|
|
220
|
+
* @tparam Entry_range_or_column_index Either a range of @ref Entry with a begin() and end() method,
|
|
221
|
+
* or any integer type.
|
|
222
|
+
* @param sourceColumn Either an entry range or the @ref MatIdx index of the column to add.
|
|
223
|
+
* @param targetColumnIndex @ref MatIdx index of the target column.
|
|
224
|
+
*/
|
|
225
|
+
template <class Entry_range_or_column_index>
|
|
226
|
+
void add_to(const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex);
|
|
227
|
+
/**
|
|
228
|
+
* @brief Multiplies the target column with the coefficient and then adds the source column to it.
|
|
229
|
+
* That is: `targetColumn = (targetColumn * coefficient) + sourceColumn`.
|
|
230
|
+
*
|
|
231
|
+
* @tparam Entry_range_or_column_index Either a range of @ref Entry with a begin() and end() method,
|
|
232
|
+
* or any integer type.
|
|
233
|
+
* @param sourceColumn Either an entry range or the @ref MatIdx index of the column to add.
|
|
234
|
+
* @param coefficient Value to multiply.
|
|
235
|
+
* @param targetColumnIndex @ref MatIdx index of the target column.
|
|
236
|
+
*/
|
|
237
|
+
template <class Entry_range_or_column_index>
|
|
238
|
+
void multiply_target_and_add_to(const Entry_range_or_column_index& sourceColumn,
|
|
239
|
+
const Field_element& coefficient,
|
|
240
|
+
Index targetColumnIndex);
|
|
241
|
+
/**
|
|
242
|
+
* @brief Multiplies the source column with the coefficient before adding it to the target column.
|
|
243
|
+
* That is: `targetColumn += (coefficient * sourceColumn)`. The source column will **not** be modified.
|
|
244
|
+
*
|
|
245
|
+
* @tparam Entry_range_or_column_index Either a range of @ref Entry with a begin() and end() method,
|
|
246
|
+
* or any integer type.
|
|
247
|
+
* @param coefficient Value to multiply.
|
|
248
|
+
* @param sourceColumn Either an entry range or the @ref MatIdx index of the column to add.
|
|
249
|
+
* @param targetColumnIndex @ref MatIdx index of the target column.
|
|
250
|
+
*/
|
|
251
|
+
template <class Entry_range_or_column_index>
|
|
252
|
+
void multiply_source_and_add_to(const Field_element& coefficient,
|
|
253
|
+
const Entry_range_or_column_index& sourceColumn,
|
|
254
|
+
Index targetColumnIndex);
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @brief Zeroes the entry at the given coordinates.
|
|
258
|
+
*
|
|
259
|
+
* @param columnIndex @ref MatIdx index of the column of the entry.
|
|
260
|
+
* @param rowIndex @ref rowindex "Row index" of the row of the entry.
|
|
261
|
+
*/
|
|
262
|
+
void zero_entry(Index columnIndex, Index rowIndex);
|
|
263
|
+
/**
|
|
264
|
+
* @brief Zeroes the column at the given index.
|
|
265
|
+
*
|
|
266
|
+
* @param columnIndex @ref MatIdx index of the column to zero.
|
|
267
|
+
*/
|
|
268
|
+
void zero_column(Index columnIndex);
|
|
269
|
+
/**
|
|
270
|
+
* @brief Indicates if the entry at given coordinates has value zero.
|
|
271
|
+
*
|
|
272
|
+
* @param columnIndex @ref MatIdx index of the column of the entry.
|
|
273
|
+
* @param rowIndex @ref rowindex "Row index" of the row of the entry.
|
|
274
|
+
* @return true If the entry has value zero.
|
|
275
|
+
* @return false Otherwise.
|
|
276
|
+
*/
|
|
277
|
+
bool is_zero_entry(Index columnIndex, Index rowIndex) const;
|
|
278
|
+
/**
|
|
279
|
+
* @brief Indicates if the column at given index has value zero.
|
|
280
|
+
*
|
|
281
|
+
* @param columnIndex @ref MatIdx index of the column.
|
|
282
|
+
* @return true If the column has value zero.
|
|
283
|
+
* @return false Otherwise.
|
|
284
|
+
*/
|
|
285
|
+
bool is_zero_column(Index columnIndex);
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @brief Resets the matrix to an empty matrix.
|
|
289
|
+
*
|
|
290
|
+
* @param colSettings Pointer to an existing setting structure for the columns. The structure should contain all
|
|
291
|
+
* the necessary external classes specifically necessary for the choosen column type, such as custom allocators.
|
|
292
|
+
*/
|
|
293
|
+
void reset(Column_settings* colSettings) {
|
|
294
|
+
matrix_.clear();
|
|
295
|
+
nextInsertIndex_ = 0;
|
|
296
|
+
colSettings_ = colSettings;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @brief Assign operator.
|
|
301
|
+
*/
|
|
302
|
+
Base_matrix& operator=(const Base_matrix& other);
|
|
303
|
+
/**
|
|
304
|
+
* @brief Swap operator.
|
|
305
|
+
*/
|
|
306
|
+
friend void swap(Base_matrix& matrix1, Base_matrix& matrix2) {
|
|
307
|
+
swap(static_cast<typename Master_matrix::template Base_swap_option<Base_matrix<Master_matrix> >&>(matrix1),
|
|
308
|
+
static_cast<typename Master_matrix::template Base_swap_option<Base_matrix<Master_matrix> >&>(matrix2));
|
|
309
|
+
matrix1.matrix_.swap(matrix2.matrix_);
|
|
310
|
+
std::swap(matrix1.nextInsertIndex_, matrix2.nextInsertIndex_);
|
|
311
|
+
std::swap(matrix1.colSettings_, matrix2.colSettings_);
|
|
312
|
+
|
|
313
|
+
if constexpr (Master_matrix::Option_list::has_row_access) {
|
|
314
|
+
swap(static_cast<typename Master_matrix::Matrix_row_access_option&>(matrix1),
|
|
315
|
+
static_cast<typename Master_matrix::Matrix_row_access_option&>(matrix2));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
void print(Index startCol = 0, Index endCol = -1, Index startRow = 0, Index endRow = -1); // for debug
|
|
320
|
+
|
|
321
|
+
private:
|
|
322
|
+
using Swap_opt = typename Master_matrix::template Base_swap_option<Base_matrix<Master_matrix> >;
|
|
323
|
+
using RA_opt = typename Master_matrix::Matrix_row_access_option;
|
|
324
|
+
using Column_container = typename Master_matrix::Column_container;
|
|
325
|
+
using Entry_representative =
|
|
326
|
+
typename std::conditional<Master_matrix::Option_list::is_z2,
|
|
327
|
+
Index,
|
|
328
|
+
std::pair<Index, Field_element>
|
|
329
|
+
>::type;
|
|
330
|
+
|
|
331
|
+
friend Swap_opt; // direct access to matrix_ to avoid row reorder.
|
|
332
|
+
|
|
333
|
+
Column_container matrix_; /**< Column container. */
|
|
334
|
+
Index nextInsertIndex_; /**< Next unused column index. */
|
|
335
|
+
Column_settings* colSettings_; /**< Entry factory. */
|
|
336
|
+
|
|
337
|
+
template <class Container = Boundary>
|
|
338
|
+
void _insert(const Container& column, Index columnIndex, Dimension dim);
|
|
339
|
+
void _orderRowsIfNecessary();
|
|
340
|
+
const Column& _get_column(Index columnIndex) const;
|
|
341
|
+
Column& _get_column(Index columnIndex);
|
|
342
|
+
Index _get_real_row_index(Index rowIndex) const;
|
|
343
|
+
template <class Container>
|
|
344
|
+
void _container_insert(const Container& column, Index pos, Dimension dim);
|
|
345
|
+
void _container_insert(const Column& column, [[maybe_unused]] Index pos = 0);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
template <class Master_matrix>
|
|
349
|
+
inline Base_matrix<Master_matrix>::Base_matrix(Column_settings* colSettings)
|
|
350
|
+
: Swap_opt(), RA_opt(), nextInsertIndex_(0), colSettings_(colSettings)
|
|
351
|
+
{}
|
|
352
|
+
|
|
353
|
+
template <class Master_matrix>
|
|
354
|
+
template <class Container>
|
|
355
|
+
inline Base_matrix<Master_matrix>::Base_matrix(const std::vector<Container>& columns,
|
|
356
|
+
Column_settings* colSettings)
|
|
357
|
+
: Swap_opt(columns.size()),
|
|
358
|
+
// not ideal if max row index is much smaller than max column index, does that happen often?
|
|
359
|
+
RA_opt(columns.size()),
|
|
360
|
+
matrix_(!Master_matrix::Option_list::has_map_column_container && Master_matrix::Option_list::has_row_access
|
|
361
|
+
? 0
|
|
362
|
+
: columns.size()),
|
|
363
|
+
nextInsertIndex_(columns.size()),
|
|
364
|
+
colSettings_(colSettings)
|
|
365
|
+
{
|
|
366
|
+
if constexpr (!Master_matrix::Option_list::has_map_column_container && Master_matrix::Option_list::has_row_access)
|
|
367
|
+
matrix_.reserve(columns.size());
|
|
368
|
+
|
|
369
|
+
for (Index i = 0; i < columns.size(); i++) {
|
|
370
|
+
_container_insert(columns[i], i, columns[i].size() == 0 ? 0 : columns[i].size() - 1);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
template <class Master_matrix>
|
|
375
|
+
inline Base_matrix<Master_matrix>::Base_matrix(unsigned int numberOfColumns,
|
|
376
|
+
Column_settings* colSettings)
|
|
377
|
+
: Swap_opt(numberOfColumns),
|
|
378
|
+
RA_opt(numberOfColumns),
|
|
379
|
+
matrix_(!Master_matrix::Option_list::has_map_column_container && Master_matrix::Option_list::has_row_access
|
|
380
|
+
? 0
|
|
381
|
+
: numberOfColumns),
|
|
382
|
+
nextInsertIndex_(0),
|
|
383
|
+
colSettings_(colSettings)
|
|
384
|
+
{
|
|
385
|
+
if constexpr (!Master_matrix::Option_list::has_map_column_container && Master_matrix::Option_list::has_row_access)
|
|
386
|
+
matrix_.reserve(numberOfColumns);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
template <class Master_matrix>
|
|
390
|
+
inline Base_matrix<Master_matrix>::Base_matrix(const Base_matrix& matrixToCopy,
|
|
391
|
+
Column_settings* colSettings)
|
|
392
|
+
: Swap_opt(static_cast<const Swap_opt&>(matrixToCopy)),
|
|
393
|
+
RA_opt(static_cast<const RA_opt&>(matrixToCopy)),
|
|
394
|
+
nextInsertIndex_(matrixToCopy.nextInsertIndex_),
|
|
395
|
+
colSettings_(colSettings == nullptr ? matrixToCopy.colSettings_ : colSettings)
|
|
396
|
+
{
|
|
397
|
+
matrix_.reserve(matrixToCopy.matrix_.size());
|
|
398
|
+
for (const auto& cont : matrixToCopy.matrix_){
|
|
399
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container){
|
|
400
|
+
_container_insert(cont.second, cont.first);
|
|
401
|
+
} else {
|
|
402
|
+
_container_insert(cont);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
template <class Master_matrix>
|
|
408
|
+
inline Base_matrix<Master_matrix>::Base_matrix(Base_matrix&& other) noexcept
|
|
409
|
+
: Swap_opt(std::move(static_cast<Swap_opt&>(other))),
|
|
410
|
+
RA_opt(std::move(static_cast<RA_opt&>(other))),
|
|
411
|
+
matrix_(std::move(other.matrix_)),
|
|
412
|
+
nextInsertIndex_(std::exchange(other.nextInsertIndex_, 0)),
|
|
413
|
+
colSettings_(std::exchange(other.colSettings_, nullptr))
|
|
414
|
+
{}
|
|
415
|
+
|
|
416
|
+
template <class Master_matrix>
|
|
417
|
+
template <class Container>
|
|
418
|
+
inline void Base_matrix<Master_matrix>::insert_column(const Container& column)
|
|
419
|
+
{
|
|
420
|
+
//TODO: dim not actually stored right now, so either get rid of it or store it again
|
|
421
|
+
_insert(column, nextInsertIndex_, column.size() == 0 ? 0 : column.size() - 1);
|
|
422
|
+
++nextInsertIndex_;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
template <class Master_matrix>
|
|
426
|
+
template <class Container>
|
|
427
|
+
inline void Base_matrix<Master_matrix>::insert_column(const Container& column, Index columnIndex)
|
|
428
|
+
{
|
|
429
|
+
static_assert(!Master_matrix::Option_list::has_row_access,
|
|
430
|
+
"Columns have to be inserted at the end of the matrix when row access is enabled.");
|
|
431
|
+
|
|
432
|
+
if (columnIndex >= nextInsertIndex_) nextInsertIndex_ = columnIndex + 1;
|
|
433
|
+
//TODO: dim not actually stored right now, so either get rid of it or store it again
|
|
434
|
+
_insert(column, columnIndex, column.size() == 0 ? 0 : column.size() - 1);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
template <class Master_matrix>
|
|
438
|
+
template <class Boundary_range>
|
|
439
|
+
inline void Base_matrix<Master_matrix>::insert_boundary(const Boundary_range& boundary, Dimension dim)
|
|
440
|
+
{
|
|
441
|
+
if (dim == -1) dim = boundary.size() == 0 ? 0 : boundary.size() - 1;
|
|
442
|
+
//TODO: dim not actually stored right now, so either get rid of it or store it again
|
|
443
|
+
_insert(boundary, nextInsertIndex_++, dim);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
template <class Master_matrix>
|
|
447
|
+
inline typename Base_matrix<Master_matrix>::Column& Base_matrix<Master_matrix>::get_column(Index columnIndex)
|
|
448
|
+
{
|
|
449
|
+
_orderRowsIfNecessary();
|
|
450
|
+
return _get_column(columnIndex);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
template <class Master_matrix>
|
|
454
|
+
inline typename Base_matrix<Master_matrix>::Row& Base_matrix<Master_matrix>::get_row(Index rowIndex)
|
|
455
|
+
{
|
|
456
|
+
static_assert(Master_matrix::Option_list::has_row_access, "Row access has to be enabled for this method.");
|
|
457
|
+
|
|
458
|
+
_orderRowsIfNecessary();
|
|
459
|
+
return RA_opt::get_row(rowIndex);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
template <class Master_matrix>
|
|
463
|
+
inline void Base_matrix<Master_matrix>::remove_column(Index columnIndex)
|
|
464
|
+
{
|
|
465
|
+
static_assert(Master_matrix::Option_list::has_map_column_container,
|
|
466
|
+
"'remove_column' is not implemented for the chosen options.");
|
|
467
|
+
|
|
468
|
+
// assumes that eventual "holes" left at unused indices are considered as empty columns.
|
|
469
|
+
if (columnIndex == nextInsertIndex_ - 1) --nextInsertIndex_;
|
|
470
|
+
|
|
471
|
+
matrix_.erase(columnIndex);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
template <class Master_matrix>
|
|
475
|
+
inline void Base_matrix<Master_matrix>::remove_last()
|
|
476
|
+
{
|
|
477
|
+
if (nextInsertIndex_ == 0) return; //empty matrix
|
|
478
|
+
--nextInsertIndex_; // assumes that eventual "holes" left at unused indices are considered as empty columns.
|
|
479
|
+
|
|
480
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container) {
|
|
481
|
+
matrix_.erase(nextInsertIndex_);
|
|
482
|
+
} else {
|
|
483
|
+
if constexpr (Master_matrix::Option_list::has_row_access) {
|
|
484
|
+
GUDHI_CHECK(nextInsertIndex_ == matrix_.size() - 1,
|
|
485
|
+
std::logic_error("Base_matrix::remove_last - Indexation problem."));
|
|
486
|
+
matrix_.pop_back();
|
|
487
|
+
} else {
|
|
488
|
+
matrix_[nextInsertIndex_].clear();
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
template <class Master_matrix>
|
|
494
|
+
inline void Base_matrix<Master_matrix>::erase_empty_row(Index rowIndex)
|
|
495
|
+
{
|
|
496
|
+
if constexpr (Master_matrix::Option_list::has_row_access && Master_matrix::Option_list::has_removable_rows) {
|
|
497
|
+
RA_opt::erase_empty_row(_get_real_row_index(rowIndex));
|
|
498
|
+
}
|
|
499
|
+
if constexpr ((Master_matrix::Option_list::has_column_and_row_swaps || Master_matrix::Option_list::has_vine_update) &&
|
|
500
|
+
Master_matrix::Option_list::has_map_column_container) {
|
|
501
|
+
auto it = Swap_opt::indexToRow_.find(rowIndex);
|
|
502
|
+
Swap_opt::rowToIndex_.erase(it->second);
|
|
503
|
+
Swap_opt::indexToRow_.erase(it);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
template <class Master_matrix>
|
|
508
|
+
inline typename Base_matrix<Master_matrix>::Index Base_matrix<Master_matrix>::get_number_of_columns() const
|
|
509
|
+
{
|
|
510
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container) {
|
|
511
|
+
return matrix_.size();
|
|
512
|
+
} else {
|
|
513
|
+
return nextInsertIndex_; // matrix could have been resized much bigger while insert
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
template <class Master_matrix>
|
|
518
|
+
template <class Entry_range_or_column_index>
|
|
519
|
+
inline void Base_matrix<Master_matrix>::add_to(const Entry_range_or_column_index& sourceColumn,
|
|
520
|
+
Index targetColumnIndex)
|
|
521
|
+
{
|
|
522
|
+
if constexpr (std::is_integral_v<Entry_range_or_column_index>) {
|
|
523
|
+
_get_column(targetColumnIndex) += _get_column(sourceColumn);
|
|
524
|
+
} else {
|
|
525
|
+
_get_column(targetColumnIndex) += sourceColumn;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
template <class Master_matrix>
|
|
530
|
+
template <class Entry_range_or_column_index>
|
|
531
|
+
inline void Base_matrix<Master_matrix>::multiply_target_and_add_to(const Entry_range_or_column_index& sourceColumn,
|
|
532
|
+
const Field_element& coefficient,
|
|
533
|
+
Index targetColumnIndex)
|
|
534
|
+
{
|
|
535
|
+
if constexpr (std::is_integral_v<Entry_range_or_column_index>) {
|
|
536
|
+
_get_column(targetColumnIndex).multiply_target_and_add(coefficient, _get_column(sourceColumn));
|
|
537
|
+
} else {
|
|
538
|
+
_get_column(targetColumnIndex).multiply_target_and_add(coefficient, sourceColumn);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
template <class Master_matrix>
|
|
543
|
+
template <class Entry_range_or_column_index>
|
|
544
|
+
inline void Base_matrix<Master_matrix>::multiply_source_and_add_to(const Field_element& coefficient,
|
|
545
|
+
const Entry_range_or_column_index& sourceColumn,
|
|
546
|
+
Index targetColumnIndex)
|
|
547
|
+
{
|
|
548
|
+
if constexpr (std::is_integral_v<Entry_range_or_column_index>) {
|
|
549
|
+
_get_column(targetColumnIndex).multiply_source_and_add(_get_column(sourceColumn), coefficient);
|
|
550
|
+
} else {
|
|
551
|
+
_get_column(targetColumnIndex).multiply_source_and_add(sourceColumn, coefficient);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
template <class Master_matrix>
|
|
556
|
+
inline void Base_matrix<Master_matrix>::zero_entry(Index columnIndex, Index rowIndex)
|
|
557
|
+
{
|
|
558
|
+
_get_column(columnIndex).clear(_get_real_row_index(rowIndex));
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
template <class Master_matrix>
|
|
562
|
+
inline void Base_matrix<Master_matrix>::zero_column(Index columnIndex) {
|
|
563
|
+
_get_column(columnIndex).clear();
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
template <class Master_matrix>
|
|
567
|
+
inline bool Base_matrix<Master_matrix>::is_zero_entry(Index columnIndex, Index rowIndex) const
|
|
568
|
+
{
|
|
569
|
+
return !(_get_column(columnIndex).is_non_zero(_get_real_row_index(rowIndex)));
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
template <class Master_matrix>
|
|
573
|
+
inline bool Base_matrix<Master_matrix>::is_zero_column(Index columnIndex)
|
|
574
|
+
{
|
|
575
|
+
return _get_column(columnIndex).is_empty();
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
template <class Master_matrix>
|
|
579
|
+
inline Base_matrix<Master_matrix>& Base_matrix<Master_matrix>::operator=(const Base_matrix& other)
|
|
580
|
+
{
|
|
581
|
+
Swap_opt::operator=(other);
|
|
582
|
+
RA_opt::operator=(other);
|
|
583
|
+
matrix_.clear();
|
|
584
|
+
nextInsertIndex_ = other.nextInsertIndex_;
|
|
585
|
+
colSettings_ = other.colSettings_;
|
|
586
|
+
|
|
587
|
+
matrix_.reserve(other.matrix_.size());
|
|
588
|
+
for (const auto& cont : other.matrix_){
|
|
589
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container){
|
|
590
|
+
_container_insert(cont.second, cont.first);
|
|
591
|
+
} else {
|
|
592
|
+
_container_insert(cont);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
return *this;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
template <class Master_matrix>
|
|
600
|
+
inline void Base_matrix<Master_matrix>::print(Index startCol, Index endCol, Index startRow, Index endRow)
|
|
601
|
+
{
|
|
602
|
+
_orderRowsIfNecessary();
|
|
603
|
+
if (endCol == static_cast<Index>(-1)) endCol = nextInsertIndex_;
|
|
604
|
+
if (endRow == static_cast<Index>(-1)) endRow = nextInsertIndex_;
|
|
605
|
+
std::cout << "Base_matrix:\n";
|
|
606
|
+
for (Index i = startCol; i < endCol && i < nextInsertIndex_; ++i) {
|
|
607
|
+
const Column& col = matrix_[i];
|
|
608
|
+
auto cont = col.get_content(endRow);
|
|
609
|
+
for (Index j = startRow; j < endRow; ++j) {
|
|
610
|
+
if (cont[j] == 0u)
|
|
611
|
+
std::cout << "- ";
|
|
612
|
+
else
|
|
613
|
+
std::cout << cont[j] << " ";
|
|
614
|
+
}
|
|
615
|
+
std::cout << "\n";
|
|
616
|
+
}
|
|
617
|
+
std::cout << "\n";
|
|
618
|
+
if constexpr (Master_matrix::Option_list::has_row_access) {
|
|
619
|
+
std::cout << "Row Matrix:\n";
|
|
620
|
+
for (Index i = startRow; i < endRow && i < nextInsertIndex_; ++i) {
|
|
621
|
+
const auto& row = (*RA_opt::rows_)[i];
|
|
622
|
+
auto it = row.begin();
|
|
623
|
+
std::advance(it, startCol);
|
|
624
|
+
for (; it != row.end() && startCol < endCol; ++it, ++startCol) {
|
|
625
|
+
std::cout << it->get_column_index() << " ";
|
|
626
|
+
}
|
|
627
|
+
std::cout << "(" << i << ")\n";
|
|
628
|
+
}
|
|
629
|
+
std::cout << "\n";
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
template <class Master_matrix>
|
|
634
|
+
template <class Container>
|
|
635
|
+
inline void Base_matrix<Master_matrix>::_insert(const Container& column, Index columnIndex, Dimension dim)
|
|
636
|
+
{
|
|
637
|
+
_orderRowsIfNecessary();
|
|
638
|
+
|
|
639
|
+
//resize of containers when necessary:
|
|
640
|
+
Index pivot = 0;
|
|
641
|
+
if (column.begin() != column.end()) {
|
|
642
|
+
//first, compute pivot of `column`
|
|
643
|
+
if constexpr (Master_matrix::Option_list::is_z2) {
|
|
644
|
+
pivot = *std::prev(column.end());
|
|
645
|
+
} else {
|
|
646
|
+
pivot = std::prev(column.end())->first;
|
|
647
|
+
}
|
|
648
|
+
//row container
|
|
649
|
+
if constexpr (Master_matrix::Option_list::has_row_access && !Master_matrix::Option_list::has_removable_rows)
|
|
650
|
+
if (RA_opt::rows_->size() <= pivot) RA_opt::rows_->resize(pivot + 1);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
//row swap map containers
|
|
654
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container) {
|
|
655
|
+
if constexpr (Master_matrix::Option_list::has_column_and_row_swaps || Master_matrix::Option_list::has_vine_update) {
|
|
656
|
+
for (auto id : column) {
|
|
657
|
+
Index idx;
|
|
658
|
+
if constexpr (Master_matrix::Option_list::is_z2) {
|
|
659
|
+
idx = id;
|
|
660
|
+
} else {
|
|
661
|
+
idx = id.first;
|
|
662
|
+
}
|
|
663
|
+
Swap_opt::indexToRow_[idx] = idx;
|
|
664
|
+
Swap_opt::rowToIndex_[idx] = idx;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
} else {
|
|
668
|
+
if constexpr (Master_matrix::Option_list::has_column_and_row_swaps || Master_matrix::Option_list::has_vine_update) {
|
|
669
|
+
Index size = Swap_opt::indexToRow_.size();
|
|
670
|
+
if (size <= pivot) {
|
|
671
|
+
for (Index i = size; i <= pivot; i++) {
|
|
672
|
+
Swap_opt::indexToRow_.push_back(i);
|
|
673
|
+
Swap_opt::rowToIndex_.push_back(i);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
//column container
|
|
678
|
+
if constexpr (!Master_matrix::Option_list::has_row_access) {
|
|
679
|
+
if (matrix_.size() <= columnIndex) {
|
|
680
|
+
matrix_.resize(columnIndex + 1);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
_container_insert(column, columnIndex, dim);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
template <class Master_matrix>
|
|
689
|
+
inline void Base_matrix<Master_matrix>::_orderRowsIfNecessary()
|
|
690
|
+
{
|
|
691
|
+
if constexpr (Master_matrix::Option_list::has_column_and_row_swaps || Master_matrix::Option_list::has_vine_update) {
|
|
692
|
+
if (Swap_opt::rowSwapped_) Swap_opt::_orderRows();
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
template <class Master_matrix>
|
|
697
|
+
inline const typename Base_matrix<Master_matrix>::Column& Base_matrix<Master_matrix>::_get_column(
|
|
698
|
+
Index columnIndex) const
|
|
699
|
+
{
|
|
700
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container) {
|
|
701
|
+
return matrix_.at(columnIndex);
|
|
702
|
+
} else {
|
|
703
|
+
return matrix_[columnIndex];
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
template <class Master_matrix>
|
|
708
|
+
inline typename Base_matrix<Master_matrix>::Column& Base_matrix<Master_matrix>::_get_column(Index columnIndex)
|
|
709
|
+
{
|
|
710
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container) {
|
|
711
|
+
return matrix_.at(columnIndex);
|
|
712
|
+
} else {
|
|
713
|
+
return matrix_[columnIndex];
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
template <class Master_matrix>
|
|
718
|
+
inline typename Base_matrix<Master_matrix>::Index Base_matrix<Master_matrix>::_get_real_row_index(Index rowIndex) const
|
|
719
|
+
{
|
|
720
|
+
if constexpr (Master_matrix::Option_list::has_column_and_row_swaps || Master_matrix::Option_list::has_vine_update) {
|
|
721
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container) {
|
|
722
|
+
return Swap_opt::indexToRow_.at(rowIndex);
|
|
723
|
+
} else {
|
|
724
|
+
return Swap_opt::indexToRow_[rowIndex];
|
|
725
|
+
}
|
|
726
|
+
} else {
|
|
727
|
+
return rowIndex;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
template <class Master_matrix>
|
|
732
|
+
template <class Container>
|
|
733
|
+
inline void Base_matrix<Master_matrix>::_container_insert(const Container& column, Index pos, Dimension dim){
|
|
734
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container) {
|
|
735
|
+
if constexpr (Master_matrix::Option_list::has_row_access) {
|
|
736
|
+
matrix_.try_emplace(pos, Column(pos, column, dim, RA_opt::rows_, colSettings_));
|
|
737
|
+
} else {
|
|
738
|
+
matrix_.try_emplace(pos, Column(column, dim, colSettings_));
|
|
739
|
+
}
|
|
740
|
+
} else {
|
|
741
|
+
if constexpr (Master_matrix::Option_list::has_row_access) {
|
|
742
|
+
matrix_.emplace_back(pos, column, dim, RA_opt::rows_, colSettings_);
|
|
743
|
+
} else {
|
|
744
|
+
matrix_[pos] = Column(column, dim, colSettings_);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
template <class Master_matrix>
|
|
750
|
+
inline void Base_matrix<Master_matrix>::_container_insert(const Column& column, [[maybe_unused]] Index pos){
|
|
751
|
+
if constexpr (Master_matrix::Option_list::has_map_column_container) {
|
|
752
|
+
if constexpr (Master_matrix::Option_list::has_row_access) {
|
|
753
|
+
matrix_.try_emplace(pos, Column(column, column.get_column_index(), RA_opt::rows_, colSettings_));
|
|
754
|
+
} else {
|
|
755
|
+
matrix_.try_emplace(pos, Column(column, colSettings_));
|
|
756
|
+
}
|
|
757
|
+
} else {
|
|
758
|
+
if constexpr (Master_matrix::Option_list::has_row_access) {
|
|
759
|
+
matrix_.emplace_back(column, column.get_column_index(), RA_opt::rows_, colSettings_);
|
|
760
|
+
} else {
|
|
761
|
+
matrix_.emplace_back(column, colSettings_);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
} // namespace persistence_matrix
|
|
767
|
+
} // namespace Gudhi
|
|
768
|
+
|
|
769
|
+
#endif // PM_BASE_MATRIX_H
|