multipers 2.4.0b1__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.
- multipers/.dylibs/libboost_timer.dylib +0 -0
- multipers/.dylibs/libc++.1.0.dylib +0 -0
- multipers/.dylibs/libtbb.12.17.dylib +0 -0
- multipers/__init__.py +33 -0
- multipers/_signed_measure_meta.py +426 -0
- multipers/_slicer_meta.py +231 -0
- multipers/array_api/__init__.py +62 -0
- multipers/array_api/numpy.py +124 -0
- multipers/array_api/torch.py +133 -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 +736 -0
- multipers/filtration_conversions.pxd.tp +226 -0
- multipers/filtrations/__init__.py +21 -0
- multipers/filtrations/density.py +529 -0
- multipers/filtrations/filtrations.py +480 -0
- multipers/filtrations.pxd +534 -0
- multipers/filtrations.pxd.tp +332 -0
- multipers/function_rips.cpython-312-darwin.so +0 -0
- multipers/function_rips.pyx +104 -0
- multipers/grids.cpython-312-darwin.so +0 -0
- multipers/grids.pyx +538 -0
- multipers/gudhi/Persistence_slices_interface.h +213 -0
- multipers/gudhi/Simplex_tree_interface.h +274 -0
- multipers/gudhi/Simplex_tree_multi_interface.h +648 -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 +52 -0
- multipers/gudhi/gudhi/Degree_rips_bifiltration.h +2307 -0
- multipers/gudhi/gudhi/Dynamic_multi_parameter_filtration.h +2524 -0
- multipers/gudhi/gudhi/Fields/Multi_field.h +453 -0
- multipers/gudhi/gudhi/Fields/Multi_field_operators.h +460 -0
- multipers/gudhi/gudhi/Fields/Multi_field_shared.h +444 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small.h +584 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +490 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +580 -0
- multipers/gudhi/gudhi/Fields/Z2_field.h +391 -0
- multipers/gudhi/gudhi/Fields/Z2_field_operators.h +389 -0
- multipers/gudhi/gudhi/Fields/Zp_field.h +493 -0
- multipers/gudhi/gudhi/Fields/Zp_field_operators.h +384 -0
- multipers/gudhi/gudhi/Fields/Zp_field_shared.h +492 -0
- multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
- multipers/gudhi/gudhi/Matrix.h +2200 -0
- multipers/gudhi/gudhi/Multi_filtration/Multi_parameter_generator.h +1712 -0
- multipers/gudhi/gudhi/Multi_filtration/multi_filtration_conversions.h +237 -0
- multipers/gudhi/gudhi/Multi_filtration/multi_filtration_utils.h +225 -0
- multipers/gudhi/gudhi/Multi_parameter_filtered_complex.h +485 -0
- multipers/gudhi/gudhi/Multi_parameter_filtration.h +2643 -0
- multipers/gudhi/gudhi/Multi_persistence/Box.h +233 -0
- multipers/gudhi/gudhi/Multi_persistence/Line.h +309 -0
- multipers/gudhi/gudhi/Multi_persistence/Multi_parameter_filtered_complex_pcoh_interface.h +268 -0
- multipers/gudhi/gudhi/Multi_persistence/Persistence_interface_cohomology.h +159 -0
- multipers/gudhi/gudhi/Multi_persistence/Persistence_interface_matrix.h +463 -0
- multipers/gudhi/gudhi/Multi_persistence/Point.h +853 -0
- multipers/gudhi/gudhi/Off_reader.h +173 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +834 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +838 -0
- multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +833 -0
- multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1367 -0
- multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1157 -0
- multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +869 -0
- multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +905 -0
- multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +122 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +260 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +288 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +170 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +247 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +571 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +182 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +130 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +235 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +312 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1092 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +923 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +914 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +930 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1071 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +203 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +886 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +984 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1213 -0
- multipers/gudhi/gudhi/Persistence_matrix/index_mapper.h +58 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +227 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +200 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +166 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +319 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +562 -0
- multipers/gudhi/gudhi/Persistence_on_a_line.h +152 -0
- multipers/gudhi/gudhi/Persistence_on_rectangle.h +617 -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 +769 -0
- multipers/gudhi/gudhi/Points_off_io.h +171 -0
- multipers/gudhi/gudhi/Projective_cover_kernel.h +379 -0
- multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +559 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +121 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
- multipers/gudhi/gudhi/Simplex_tree/filtration_value_utils.h +155 -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 +60 -0
- multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +105 -0
- multipers/gudhi/gudhi/Simplex_tree.h +3170 -0
- multipers/gudhi/gudhi/Slicer.h +848 -0
- multipers/gudhi/gudhi/Thread_safe_slicer.h +393 -0
- multipers/gudhi/gudhi/distance_functions.h +62 -0
- multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
- multipers/gudhi/gudhi/multi_simplex_tree_helpers.h +147 -0
- multipers/gudhi/gudhi/persistence_interval.h +263 -0
- multipers/gudhi/gudhi/persistence_matrix_options.h +188 -0
- multipers/gudhi/gudhi/reader_utils.h +367 -0
- multipers/gudhi/gudhi/simple_mdspan.h +484 -0
- multipers/gudhi/gudhi/slicer_helpers.h +779 -0
- multipers/gudhi/tmp_h0_pers/mma_interface_h0.h +223 -0
- multipers/gudhi/tmp_h0_pers/naive_merge_tree.h +536 -0
- multipers/io.cpython-312-darwin.so +0 -0
- multipers/io.pyx +472 -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 +1667 -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 +134 -0
- multipers/mma_structures.pyx +1483 -0
- multipers/mma_structures.pyx.tp +1126 -0
- multipers/multi_parameter_rank_invariant/diff_helpers.h +85 -0
- multipers/multi_parameter_rank_invariant/euler_characteristic.h +95 -0
- multipers/multi_parameter_rank_invariant/function_rips.h +317 -0
- multipers/multi_parameter_rank_invariant/hilbert_function.h +761 -0
- multipers/multi_parameter_rank_invariant/persistence_slices.h +149 -0
- multipers/multi_parameter_rank_invariant/rank_invariant.h +350 -0
- multipers/multiparameter_edge_collapse.py +41 -0
- multipers/multiparameter_module_approximation/approximation.h +2541 -0
- multipers/multiparameter_module_approximation/debug.h +107 -0
- multipers/multiparameter_module_approximation/format_python-cpp.h +292 -0
- multipers/multiparameter_module_approximation/utilities.h +428 -0
- multipers/multiparameter_module_approximation.cpython-312-darwin.so +0 -0
- multipers/multiparameter_module_approximation.pyx +286 -0
- multipers/ops.cpython-312-darwin.so +0 -0
- multipers/ops.pyx +231 -0
- multipers/pickle.py +89 -0
- multipers/plots.py +550 -0
- multipers/point_measure.cpython-312-darwin.so +0 -0
- multipers/point_measure.pyx +409 -0
- multipers/simplex_tree_multi.cpython-312-darwin.so +0 -0
- multipers/simplex_tree_multi.pxd +136 -0
- multipers/simplex_tree_multi.pyx +11719 -0
- multipers/simplex_tree_multi.pyx.tp +2102 -0
- multipers/slicer.cpython-312-darwin.so +0 -0
- multipers/slicer.pxd +2097 -0
- multipers/slicer.pxd.tp +263 -0
- multipers/slicer.pyx +13042 -0
- multipers/slicer.pyx.tp +1259 -0
- multipers/tensor/tensor.h +672 -0
- multipers/tensor.pxd +13 -0
- multipers/test.pyx +44 -0
- multipers/tests/__init__.py +70 -0
- multipers/torch/__init__.py +1 -0
- multipers/torch/diff_grids.py +240 -0
- multipers/torch/rips_density.py +310 -0
- multipers/vector_interface.pxd +46 -0
- multipers-2.4.0b1.dist-info/METADATA +131 -0
- multipers-2.4.0b1.dist-info/RECORD +184 -0
- multipers-2.4.0b1.dist-info/WHEEL +6 -0
- multipers-2.4.0b1.dist-info/licenses/LICENSE +21 -0
- multipers-2.4.0b1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
|
|
2
|
+
# Python to C++ conversions
|
|
3
|
+
from multipers.filtrations cimport *
|
|
4
|
+
from libcpp.vector cimport vector
|
|
5
|
+
from libcpp cimport bool
|
|
6
|
+
cimport numpy as cnp
|
|
7
|
+
import numpy as np
|
|
8
|
+
from libc.stdint cimport int32_t, int64_t
|
|
9
|
+
from cython.operator cimport dereference
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
###### ------------------- PY TO CPP
|
|
16
|
+
#### ----------
|
|
17
|
+
|
|
18
|
+
cdef inline vector[int32_t] _py2p_i32(int32_t[:] filtration) noexcept nogil:
|
|
19
|
+
# TODO: Is there no directer way to convert a T[:] into a vector[T]?
|
|
20
|
+
# A memcpy would be much quicker than a python/cython for loop...
|
|
21
|
+
# With a continuous memory use, we could also pass the pointers as iterators if we have access to it?
|
|
22
|
+
cdef vector[int32_t] f = vector[int32_t](len(filtration))
|
|
23
|
+
for i in range(len(filtration)):
|
|
24
|
+
f[i] = filtration[i]
|
|
25
|
+
return f
|
|
26
|
+
|
|
27
|
+
cdef inline vector[int32_t] _py2p2_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
28
|
+
cdef vector[int32_t] f = vector[int32_t](filtrations.shape[0] * filtrations.shape[1])
|
|
29
|
+
k = 0
|
|
30
|
+
for i in range(filtrations.shape[0]):
|
|
31
|
+
for j in range(filtrations.shape[1]):
|
|
32
|
+
f[k] = filtrations[i,j]
|
|
33
|
+
k = k + 1
|
|
34
|
+
return f
|
|
35
|
+
|
|
36
|
+
cdef inline vector[Point[int32_t]] _py2vp_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
37
|
+
cdef vector[Point[int32_t]] out
|
|
38
|
+
cdef Point[int32_t] f = Point[int32_t](filtrations.shape[1])
|
|
39
|
+
out.reserve(filtrations.shape[0])
|
|
40
|
+
for i in range(filtrations.shape[0]):
|
|
41
|
+
for j in range(filtrations.shape[1]):
|
|
42
|
+
f[j] = filtrations[i,j]
|
|
43
|
+
out.emplace_back(f)
|
|
44
|
+
return out
|
|
45
|
+
|
|
46
|
+
cdef inline Multi_critical_filtration[int32_t] _py2kc_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
47
|
+
# cdef int32_t[:,:] filtrations = np.asarray(filtrations_, dtype=np.int32)
|
|
48
|
+
cdef vector[int32_t] f = vector[int32_t](filtrations.shape[0] * filtrations.shape[1])
|
|
49
|
+
cdef int k = 0;
|
|
50
|
+
for i in range(filtrations.shape[0]):
|
|
51
|
+
for j in range(filtrations.shape[1]):
|
|
52
|
+
f[k] = filtrations[i,j]
|
|
53
|
+
k = k + 1
|
|
54
|
+
cdef Multi_critical_filtration[int32_t] out = Multi_critical_filtration[int32_t](f.begin(), f.end(), filtrations.shape[1])
|
|
55
|
+
out.simplify()
|
|
56
|
+
return out
|
|
57
|
+
|
|
58
|
+
cdef inline One_critical_filtration[int32_t] _py21c_i32(int32_t[:] filtration) noexcept nogil:
|
|
59
|
+
cdef One_critical_filtration[int32_t] out = _py2p_i32(filtration)
|
|
60
|
+
return out
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
cdef inline vector[One_critical_filtration[int32_t]] _py2v1c_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
64
|
+
# cdef int32_t[:,:] filtrations = np.asarray(filtrations_, dtype=np.int32)
|
|
65
|
+
cdef vector[One_critical_filtration[int32_t]] out
|
|
66
|
+
cdef vector[int32_t] f = vector[int32_t](filtrations.shape[1])
|
|
67
|
+
out.reserve(filtrations.shape[0])
|
|
68
|
+
for i in range(filtrations.shape[0]):
|
|
69
|
+
for j in range(filtrations.shape[1]):
|
|
70
|
+
f[j] = filtrations[i,j]
|
|
71
|
+
out.emplace_back(f)
|
|
72
|
+
return out
|
|
73
|
+
|
|
74
|
+
cdef inline vector[Multi_critical_filtration[int32_t]] _py2vkc_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
75
|
+
# cdef int32_t[:,:] filtrations = np.asarray(filtrations_, dtype=np.int32)
|
|
76
|
+
cdef vector[Multi_critical_filtration[int32_t]] out
|
|
77
|
+
cdef vector[int32_t] f = vector[int32_t](filtrations.shape[1])
|
|
78
|
+
out.reserve(filtrations.shape[0])
|
|
79
|
+
for i in range(filtrations.shape[0]):
|
|
80
|
+
for j in range(filtrations.shape[1]):
|
|
81
|
+
f[j] = filtrations[i,j]
|
|
82
|
+
out.emplace_back(f)
|
|
83
|
+
return out
|
|
84
|
+
|
|
85
|
+
###### ------------------- CPP to PY
|
|
86
|
+
|
|
87
|
+
## tailored for Dynamic_multi_parameter_filtration
|
|
88
|
+
## testing finite or not is not necessary for Multi_parameter_filtration
|
|
89
|
+
## won't work for Degree_rips_filtration
|
|
90
|
+
|
|
91
|
+
## CYTHON BUG: using tuples here will cause some weird issues.
|
|
92
|
+
cdef inline _ff21cview_i32(One_critical_filtration[int32_t]* x, bool copy=False):
|
|
93
|
+
cdef Py_ssize_t num_parameters = dereference(x).num_parameters()
|
|
94
|
+
if not dereference(x).is_finite():
|
|
95
|
+
return np.full(shape=num_parameters, fill_value=dereference(x)(0,0))
|
|
96
|
+
cdef int32_t[:] x_view = <int32_t[:num_parameters]>(&(dereference(x)(0,0)))
|
|
97
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
98
|
+
|
|
99
|
+
cdef inline _ff21cview2_i32(int32_t* x, Py_ssize_t num_parameters, int duplicate, bool copy=False):
|
|
100
|
+
if duplicate:
|
|
101
|
+
return np.full(shape=duplicate, fill_value=dereference(x))
|
|
102
|
+
cdef int32_t[:] x_view = <int32_t[:num_parameters]>(x)
|
|
103
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
104
|
+
|
|
105
|
+
cdef inline _ff2kcview_i32(Multi_critical_filtration[int32_t]* x, bool copy=False):
|
|
106
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
107
|
+
cdef Py_ssize_t p = dereference(x).num_parameters()
|
|
108
|
+
if dereference(x).is_finite():
|
|
109
|
+
duplicate = 0
|
|
110
|
+
else:
|
|
111
|
+
duplicate = p
|
|
112
|
+
return [_ff21cview2_i32(&(dereference(x)(i,0)), p, duplicate, copy=copy) for i in range(k)]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
cdef inline _vff21cview_i32(vector[One_critical_filtration[int32_t]]& x, bool copy = False):
|
|
116
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
117
|
+
return [_ff21cview_i32(&(x[i]), copy=copy) for i in range(num_stuff)]
|
|
118
|
+
|
|
119
|
+
cdef inline _vff2kcview_i32(vector[Multi_critical_filtration[int32_t]]& x, bool copy = False):
|
|
120
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
121
|
+
return [_ff2kcview_i32(&(x[i]), copy=copy) for i in range(num_stuff)]
|
|
122
|
+
###### ------------------- PY TO CPP
|
|
123
|
+
#### ----------
|
|
124
|
+
|
|
125
|
+
cdef inline vector[int64_t] _py2p_i64(int64_t[:] filtration) noexcept nogil:
|
|
126
|
+
# TODO: Is there no directer way to convert a T[:] into a vector[T]?
|
|
127
|
+
# A memcpy would be much quicker than a python/cython for loop...
|
|
128
|
+
# With a continuous memory use, we could also pass the pointers as iterators if we have access to it?
|
|
129
|
+
cdef vector[int64_t] f = vector[int64_t](len(filtration))
|
|
130
|
+
for i in range(len(filtration)):
|
|
131
|
+
f[i] = filtration[i]
|
|
132
|
+
return f
|
|
133
|
+
|
|
134
|
+
cdef inline vector[int64_t] _py2p2_i64(int64_t[:,:] filtrations) noexcept nogil:
|
|
135
|
+
cdef vector[int64_t] f = vector[int64_t](filtrations.shape[0] * filtrations.shape[1])
|
|
136
|
+
k = 0
|
|
137
|
+
for i in range(filtrations.shape[0]):
|
|
138
|
+
for j in range(filtrations.shape[1]):
|
|
139
|
+
f[k] = filtrations[i,j]
|
|
140
|
+
k = k + 1
|
|
141
|
+
return f
|
|
142
|
+
|
|
143
|
+
cdef inline vector[Point[int64_t]] _py2vp_i64(int64_t[:,:] filtrations) noexcept nogil:
|
|
144
|
+
cdef vector[Point[int64_t]] out
|
|
145
|
+
cdef Point[int64_t] f = Point[int64_t](filtrations.shape[1])
|
|
146
|
+
out.reserve(filtrations.shape[0])
|
|
147
|
+
for i in range(filtrations.shape[0]):
|
|
148
|
+
for j in range(filtrations.shape[1]):
|
|
149
|
+
f[j] = filtrations[i,j]
|
|
150
|
+
out.emplace_back(f)
|
|
151
|
+
return out
|
|
152
|
+
|
|
153
|
+
cdef inline Multi_critical_filtration[int64_t] _py2kc_i64(int64_t[:,:] filtrations) noexcept nogil:
|
|
154
|
+
# cdef int64_t[:,:] filtrations = np.asarray(filtrations_, dtype=np.int64)
|
|
155
|
+
cdef vector[int64_t] f = vector[int64_t](filtrations.shape[0] * filtrations.shape[1])
|
|
156
|
+
cdef int k = 0;
|
|
157
|
+
for i in range(filtrations.shape[0]):
|
|
158
|
+
for j in range(filtrations.shape[1]):
|
|
159
|
+
f[k] = filtrations[i,j]
|
|
160
|
+
k = k + 1
|
|
161
|
+
cdef Multi_critical_filtration[int64_t] out = Multi_critical_filtration[int64_t](f.begin(), f.end(), filtrations.shape[1])
|
|
162
|
+
out.simplify()
|
|
163
|
+
return out
|
|
164
|
+
|
|
165
|
+
cdef inline One_critical_filtration[int64_t] _py21c_i64(int64_t[:] filtration) noexcept nogil:
|
|
166
|
+
cdef One_critical_filtration[int64_t] out = _py2p_i64(filtration)
|
|
167
|
+
return out
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
cdef inline vector[One_critical_filtration[int64_t]] _py2v1c_i64(int64_t[:,:] filtrations) noexcept nogil:
|
|
171
|
+
# cdef int64_t[:,:] filtrations = np.asarray(filtrations_, dtype=np.int64)
|
|
172
|
+
cdef vector[One_critical_filtration[int64_t]] out
|
|
173
|
+
cdef vector[int64_t] f = vector[int64_t](filtrations.shape[1])
|
|
174
|
+
out.reserve(filtrations.shape[0])
|
|
175
|
+
for i in range(filtrations.shape[0]):
|
|
176
|
+
for j in range(filtrations.shape[1]):
|
|
177
|
+
f[j] = filtrations[i,j]
|
|
178
|
+
out.emplace_back(f)
|
|
179
|
+
return out
|
|
180
|
+
|
|
181
|
+
cdef inline vector[Multi_critical_filtration[int64_t]] _py2vkc_i64(int64_t[:,:] filtrations) noexcept nogil:
|
|
182
|
+
# cdef int64_t[:,:] filtrations = np.asarray(filtrations_, dtype=np.int64)
|
|
183
|
+
cdef vector[Multi_critical_filtration[int64_t]] out
|
|
184
|
+
cdef vector[int64_t] f = vector[int64_t](filtrations.shape[1])
|
|
185
|
+
out.reserve(filtrations.shape[0])
|
|
186
|
+
for i in range(filtrations.shape[0]):
|
|
187
|
+
for j in range(filtrations.shape[1]):
|
|
188
|
+
f[j] = filtrations[i,j]
|
|
189
|
+
out.emplace_back(f)
|
|
190
|
+
return out
|
|
191
|
+
|
|
192
|
+
###### ------------------- CPP to PY
|
|
193
|
+
|
|
194
|
+
## tailored for Dynamic_multi_parameter_filtration
|
|
195
|
+
## testing finite or not is not necessary for Multi_parameter_filtration
|
|
196
|
+
## won't work for Degree_rips_filtration
|
|
197
|
+
|
|
198
|
+
## CYTHON BUG: using tuples here will cause some weird issues.
|
|
199
|
+
cdef inline _ff21cview_i64(One_critical_filtration[int64_t]* x, bool copy=False):
|
|
200
|
+
cdef Py_ssize_t num_parameters = dereference(x).num_parameters()
|
|
201
|
+
if not dereference(x).is_finite():
|
|
202
|
+
return np.full(shape=num_parameters, fill_value=dereference(x)(0,0))
|
|
203
|
+
cdef int64_t[:] x_view = <int64_t[:num_parameters]>(&(dereference(x)(0,0)))
|
|
204
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
205
|
+
|
|
206
|
+
cdef inline _ff21cview2_i64(int64_t* x, Py_ssize_t num_parameters, int duplicate, bool copy=False):
|
|
207
|
+
if duplicate:
|
|
208
|
+
return np.full(shape=duplicate, fill_value=dereference(x))
|
|
209
|
+
cdef int64_t[:] x_view = <int64_t[:num_parameters]>(x)
|
|
210
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
211
|
+
|
|
212
|
+
cdef inline _ff2kcview_i64(Multi_critical_filtration[int64_t]* x, bool copy=False):
|
|
213
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
214
|
+
cdef Py_ssize_t p = dereference(x).num_parameters()
|
|
215
|
+
if dereference(x).is_finite():
|
|
216
|
+
duplicate = 0
|
|
217
|
+
else:
|
|
218
|
+
duplicate = p
|
|
219
|
+
return [_ff21cview2_i64(&(dereference(x)(i,0)), p, duplicate, copy=copy) for i in range(k)]
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
cdef inline _vff21cview_i64(vector[One_critical_filtration[int64_t]]& x, bool copy = False):
|
|
223
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
224
|
+
return [_ff21cview_i64(&(x[i]), copy=copy) for i in range(num_stuff)]
|
|
225
|
+
|
|
226
|
+
cdef inline _vff2kcview_i64(vector[Multi_critical_filtration[int64_t]]& x, bool copy = False):
|
|
227
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
228
|
+
return [_ff2kcview_i64(&(x[i]), copy=copy) for i in range(num_stuff)]
|
|
229
|
+
###### ------------------- PY TO CPP
|
|
230
|
+
#### ----------
|
|
231
|
+
|
|
232
|
+
cdef inline vector[float] _py2p_f32(float[:] filtration) noexcept nogil:
|
|
233
|
+
# TODO: Is there no directer way to convert a T[:] into a vector[T]?
|
|
234
|
+
# A memcpy would be much quicker than a python/cython for loop...
|
|
235
|
+
# With a continuous memory use, we could also pass the pointers as iterators if we have access to it?
|
|
236
|
+
cdef vector[float] f = vector[float](len(filtration))
|
|
237
|
+
for i in range(len(filtration)):
|
|
238
|
+
f[i] = filtration[i]
|
|
239
|
+
return f
|
|
240
|
+
|
|
241
|
+
cdef inline vector[float] _py2p2_f32(float[:,:] filtrations) noexcept nogil:
|
|
242
|
+
cdef vector[float] f = vector[float](filtrations.shape[0] * filtrations.shape[1])
|
|
243
|
+
k = 0
|
|
244
|
+
for i in range(filtrations.shape[0]):
|
|
245
|
+
for j in range(filtrations.shape[1]):
|
|
246
|
+
f[k] = filtrations[i,j]
|
|
247
|
+
k = k + 1
|
|
248
|
+
return f
|
|
249
|
+
|
|
250
|
+
cdef inline vector[Point[float]] _py2vp_f32(float[:,:] filtrations) noexcept nogil:
|
|
251
|
+
cdef vector[Point[float]] out
|
|
252
|
+
cdef Point[float] f = Point[float](filtrations.shape[1])
|
|
253
|
+
out.reserve(filtrations.shape[0])
|
|
254
|
+
for i in range(filtrations.shape[0]):
|
|
255
|
+
for j in range(filtrations.shape[1]):
|
|
256
|
+
f[j] = filtrations[i,j]
|
|
257
|
+
out.emplace_back(f)
|
|
258
|
+
return out
|
|
259
|
+
|
|
260
|
+
cdef inline Multi_critical_filtration[float] _py2kc_f32(float[:,:] filtrations) noexcept nogil:
|
|
261
|
+
# cdef float[:,:] filtrations = np.asarray(filtrations_, dtype=np.float32)
|
|
262
|
+
cdef vector[float] f = vector[float](filtrations.shape[0] * filtrations.shape[1])
|
|
263
|
+
cdef int k = 0;
|
|
264
|
+
for i in range(filtrations.shape[0]):
|
|
265
|
+
for j in range(filtrations.shape[1]):
|
|
266
|
+
f[k] = filtrations[i,j]
|
|
267
|
+
k = k + 1
|
|
268
|
+
cdef Multi_critical_filtration[float] out = Multi_critical_filtration[float](f.begin(), f.end(), filtrations.shape[1])
|
|
269
|
+
out.simplify()
|
|
270
|
+
return out
|
|
271
|
+
|
|
272
|
+
cdef inline One_critical_filtration[float] _py21c_f32(float[:] filtration) noexcept nogil:
|
|
273
|
+
cdef One_critical_filtration[float] out = _py2p_f32(filtration)
|
|
274
|
+
return out
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
cdef inline vector[One_critical_filtration[float]] _py2v1c_f32(float[:,:] filtrations) noexcept nogil:
|
|
278
|
+
# cdef float[:,:] filtrations = np.asarray(filtrations_, dtype=np.float32)
|
|
279
|
+
cdef vector[One_critical_filtration[float]] out
|
|
280
|
+
cdef vector[float] f = vector[float](filtrations.shape[1])
|
|
281
|
+
out.reserve(filtrations.shape[0])
|
|
282
|
+
for i in range(filtrations.shape[0]):
|
|
283
|
+
for j in range(filtrations.shape[1]):
|
|
284
|
+
f[j] = filtrations[i,j]
|
|
285
|
+
out.emplace_back(f)
|
|
286
|
+
return out
|
|
287
|
+
|
|
288
|
+
cdef inline vector[Multi_critical_filtration[float]] _py2vkc_f32(float[:,:] filtrations) noexcept nogil:
|
|
289
|
+
# cdef float[:,:] filtrations = np.asarray(filtrations_, dtype=np.float32)
|
|
290
|
+
cdef vector[Multi_critical_filtration[float]] out
|
|
291
|
+
cdef vector[float] f = vector[float](filtrations.shape[1])
|
|
292
|
+
out.reserve(filtrations.shape[0])
|
|
293
|
+
for i in range(filtrations.shape[0]):
|
|
294
|
+
for j in range(filtrations.shape[1]):
|
|
295
|
+
f[j] = filtrations[i,j]
|
|
296
|
+
out.emplace_back(f)
|
|
297
|
+
return out
|
|
298
|
+
|
|
299
|
+
###### ------------------- CPP to PY
|
|
300
|
+
|
|
301
|
+
## tailored for Dynamic_multi_parameter_filtration
|
|
302
|
+
## testing finite or not is not necessary for Multi_parameter_filtration
|
|
303
|
+
## won't work for Degree_rips_filtration
|
|
304
|
+
|
|
305
|
+
## CYTHON BUG: using tuples here will cause some weird issues.
|
|
306
|
+
cdef inline _ff21cview_f32(One_critical_filtration[float]* x, bool copy=False):
|
|
307
|
+
cdef Py_ssize_t num_parameters = dereference(x).num_parameters()
|
|
308
|
+
if not dereference(x).is_finite():
|
|
309
|
+
return np.full(shape=num_parameters, fill_value=dereference(x)(0,0))
|
|
310
|
+
cdef float[:] x_view = <float[:num_parameters]>(&(dereference(x)(0,0)))
|
|
311
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
312
|
+
|
|
313
|
+
cdef inline _ff21cview2_f32(float* x, Py_ssize_t num_parameters, int duplicate, bool copy=False):
|
|
314
|
+
if duplicate:
|
|
315
|
+
return np.full(shape=duplicate, fill_value=dereference(x))
|
|
316
|
+
cdef float[:] x_view = <float[:num_parameters]>(x)
|
|
317
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
318
|
+
|
|
319
|
+
cdef inline _ff2kcview_f32(Multi_critical_filtration[float]* x, bool copy=False):
|
|
320
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
321
|
+
cdef Py_ssize_t p = dereference(x).num_parameters()
|
|
322
|
+
if dereference(x).is_finite():
|
|
323
|
+
duplicate = 0
|
|
324
|
+
else:
|
|
325
|
+
duplicate = p
|
|
326
|
+
return [_ff21cview2_f32(&(dereference(x)(i,0)), p, duplicate, copy=copy) for i in range(k)]
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
cdef inline _vff21cview_f32(vector[One_critical_filtration[float]]& x, bool copy = False):
|
|
330
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
331
|
+
return [_ff21cview_f32(&(x[i]), copy=copy) for i in range(num_stuff)]
|
|
332
|
+
|
|
333
|
+
cdef inline _vff2kcview_f32(vector[Multi_critical_filtration[float]]& x, bool copy = False):
|
|
334
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
335
|
+
return [_ff2kcview_f32(&(x[i]), copy=copy) for i in range(num_stuff)]
|
|
336
|
+
###### ------------------- PY TO CPP
|
|
337
|
+
#### ----------
|
|
338
|
+
|
|
339
|
+
cdef inline vector[double] _py2p_f64(double[:] filtration) noexcept nogil:
|
|
340
|
+
# TODO: Is there no directer way to convert a T[:] into a vector[T]?
|
|
341
|
+
# A memcpy would be much quicker than a python/cython for loop...
|
|
342
|
+
# With a continuous memory use, we could also pass the pointers as iterators if we have access to it?
|
|
343
|
+
cdef vector[double] f = vector[double](len(filtration))
|
|
344
|
+
for i in range(len(filtration)):
|
|
345
|
+
f[i] = filtration[i]
|
|
346
|
+
return f
|
|
347
|
+
|
|
348
|
+
cdef inline vector[double] _py2p2_f64(double[:,:] filtrations) noexcept nogil:
|
|
349
|
+
cdef vector[double] f = vector[double](filtrations.shape[0] * filtrations.shape[1])
|
|
350
|
+
k = 0
|
|
351
|
+
for i in range(filtrations.shape[0]):
|
|
352
|
+
for j in range(filtrations.shape[1]):
|
|
353
|
+
f[k] = filtrations[i,j]
|
|
354
|
+
k = k + 1
|
|
355
|
+
return f
|
|
356
|
+
|
|
357
|
+
cdef inline vector[Point[double]] _py2vp_f64(double[:,:] filtrations) noexcept nogil:
|
|
358
|
+
cdef vector[Point[double]] out
|
|
359
|
+
cdef Point[double] f = Point[double](filtrations.shape[1])
|
|
360
|
+
out.reserve(filtrations.shape[0])
|
|
361
|
+
for i in range(filtrations.shape[0]):
|
|
362
|
+
for j in range(filtrations.shape[1]):
|
|
363
|
+
f[j] = filtrations[i,j]
|
|
364
|
+
out.emplace_back(f)
|
|
365
|
+
return out
|
|
366
|
+
|
|
367
|
+
cdef inline Multi_critical_filtration[double] _py2kc_f64(double[:,:] filtrations) noexcept nogil:
|
|
368
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
369
|
+
cdef vector[double] f = vector[double](filtrations.shape[0] * filtrations.shape[1])
|
|
370
|
+
cdef int k = 0;
|
|
371
|
+
for i in range(filtrations.shape[0]):
|
|
372
|
+
for j in range(filtrations.shape[1]):
|
|
373
|
+
f[k] = filtrations[i,j]
|
|
374
|
+
k = k + 1
|
|
375
|
+
cdef Multi_critical_filtration[double] out = Multi_critical_filtration[double](f.begin(), f.end(), filtrations.shape[1])
|
|
376
|
+
out.simplify()
|
|
377
|
+
return out
|
|
378
|
+
|
|
379
|
+
cdef inline One_critical_filtration[double] _py21c_f64(double[:] filtration) noexcept nogil:
|
|
380
|
+
cdef One_critical_filtration[double] out = _py2p_f64(filtration)
|
|
381
|
+
return out
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
cdef inline vector[One_critical_filtration[double]] _py2v1c_f64(double[:,:] filtrations) noexcept nogil:
|
|
385
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
386
|
+
cdef vector[One_critical_filtration[double]] out
|
|
387
|
+
cdef vector[double] f = vector[double](filtrations.shape[1])
|
|
388
|
+
out.reserve(filtrations.shape[0])
|
|
389
|
+
for i in range(filtrations.shape[0]):
|
|
390
|
+
for j in range(filtrations.shape[1]):
|
|
391
|
+
f[j] = filtrations[i,j]
|
|
392
|
+
out.emplace_back(f)
|
|
393
|
+
return out
|
|
394
|
+
|
|
395
|
+
cdef inline vector[Multi_critical_filtration[double]] _py2vkc_f64(double[:,:] filtrations) noexcept nogil:
|
|
396
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
397
|
+
cdef vector[Multi_critical_filtration[double]] out
|
|
398
|
+
cdef vector[double] f = vector[double](filtrations.shape[1])
|
|
399
|
+
out.reserve(filtrations.shape[0])
|
|
400
|
+
for i in range(filtrations.shape[0]):
|
|
401
|
+
for j in range(filtrations.shape[1]):
|
|
402
|
+
f[j] = filtrations[i,j]
|
|
403
|
+
out.emplace_back(f)
|
|
404
|
+
return out
|
|
405
|
+
|
|
406
|
+
###### ------------------- CPP to PY
|
|
407
|
+
|
|
408
|
+
## tailored for Dynamic_multi_parameter_filtration
|
|
409
|
+
## testing finite or not is not necessary for Multi_parameter_filtration
|
|
410
|
+
## won't work for Degree_rips_filtration
|
|
411
|
+
|
|
412
|
+
## CYTHON BUG: using tuples here will cause some weird issues.
|
|
413
|
+
cdef inline _ff21cview_f64(One_critical_filtration[double]* x, bool copy=False):
|
|
414
|
+
cdef Py_ssize_t num_parameters = dereference(x).num_parameters()
|
|
415
|
+
if not dereference(x).is_finite():
|
|
416
|
+
return np.full(shape=num_parameters, fill_value=dereference(x)(0,0))
|
|
417
|
+
cdef double[:] x_view = <double[:num_parameters]>(&(dereference(x)(0,0)))
|
|
418
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
419
|
+
|
|
420
|
+
cdef inline _ff21cview2_f64(double* x, Py_ssize_t num_parameters, int duplicate, bool copy=False):
|
|
421
|
+
if duplicate:
|
|
422
|
+
return np.full(shape=duplicate, fill_value=dereference(x))
|
|
423
|
+
cdef double[:] x_view = <double[:num_parameters]>(x)
|
|
424
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
425
|
+
|
|
426
|
+
cdef inline _ff2kcview_f64(Multi_critical_filtration[double]* x, bool copy=False):
|
|
427
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
428
|
+
cdef Py_ssize_t p = dereference(x).num_parameters()
|
|
429
|
+
if dereference(x).is_finite():
|
|
430
|
+
duplicate = 0
|
|
431
|
+
else:
|
|
432
|
+
duplicate = p
|
|
433
|
+
return [_ff21cview2_f64(&(dereference(x)(i,0)), p, duplicate, copy=copy) for i in range(k)]
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
cdef inline _vff21cview_f64(vector[One_critical_filtration[double]]& x, bool copy = False):
|
|
437
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
438
|
+
return [_ff21cview_f64(&(x[i]), copy=copy) for i in range(num_stuff)]
|
|
439
|
+
|
|
440
|
+
cdef inline _vff2kcview_f64(vector[Multi_critical_filtration[double]]& x, bool copy = False):
|
|
441
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
442
|
+
return [_ff2kcview_f64(&(x[i]), copy=copy) for i in range(num_stuff)]
|
|
443
|
+
cdef inline KFlat_i32_2_python(KFlat_i32* x, bool copy=False, bool raw=False):
|
|
444
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
cdef int num_parameters = 2
|
|
448
|
+
|
|
449
|
+
cdef int32_t[:] data_view = <int32_t[:k]>(&(dereference(x)(0,0)))
|
|
450
|
+
numpy_view = np.asarray(data_view, dtype=np.int32)
|
|
451
|
+
if raw:
|
|
452
|
+
return numpy_view
|
|
453
|
+
return np.concatenate([numpy_view[:,None], np.arange(k, dtype=np.int32)[:,None]], axis=1)
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
cdef inline vect_KFlat_i32_2_python(vector[KFlat_i32]& x, bool copy = False, bool raw=False):
|
|
457
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
458
|
+
return [KFlat_i32_2_python(&(x[i]), copy=copy, raw=raw) for i in range(num_stuff)]
|
|
459
|
+
|
|
460
|
+
cdef inline KFlat_i32 python_2_KFlat_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
461
|
+
cdef vector[double] f = vector[double](filtrations.shape[0] * filtrations.shape[1])
|
|
462
|
+
cdef int k = 0;
|
|
463
|
+
for i in range(filtrations.shape[0]):
|
|
464
|
+
for j in range(filtrations.shape[1]):
|
|
465
|
+
f[k] = filtrations[i,j]
|
|
466
|
+
k = k + 1
|
|
467
|
+
cdef KFlat_i32 out = KFlat_i32(f.begin(), f.end(), filtrations.shape[1])
|
|
468
|
+
out.simplify()
|
|
469
|
+
return out
|
|
470
|
+
|
|
471
|
+
cdef inline vector[KFlat_i32] python_2_vect_KFlat_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
472
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
473
|
+
cdef vector[KFlat_i32] out
|
|
474
|
+
cdef vector[int32_t] f = vector[int32_t](filtrations.shape[1])
|
|
475
|
+
out.reserve(filtrations.shape[0])
|
|
476
|
+
for i in range(filtrations.shape[0]):
|
|
477
|
+
for j in range(filtrations.shape[1]):
|
|
478
|
+
f[j] = filtrations[i,j]
|
|
479
|
+
out.emplace_back(f)
|
|
480
|
+
return out
|
|
481
|
+
cdef inline Flat_i32_2_python(Flat_i32* x, bool copy=False, bool raw=False):
|
|
482
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
cdef int num_parameters = 2
|
|
486
|
+
|
|
487
|
+
cdef int32_t[:] data_view = <int32_t[:k]>(&(dereference(x)(0,0)))
|
|
488
|
+
numpy_view = np.asarray(data_view, dtype=np.int32)
|
|
489
|
+
if raw:
|
|
490
|
+
return numpy_view
|
|
491
|
+
return np.concatenate([numpy_view[:,None], np.arange(k, dtype=np.int32)[:,None]], axis=1)
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
cdef inline vect_Flat_i32_2_python(vector[Flat_i32]& x, bool copy = False, bool raw=False):
|
|
495
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
496
|
+
return [Flat_i32_2_python(&(x[i]), copy=copy, raw=raw) for i in range(num_stuff)]
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
cdef inline Flat_i32 python_2_Flat_i32(int32_t[:] filtration) noexcept nogil:
|
|
501
|
+
cdef int num_parameters = filtration.shape[0]
|
|
502
|
+
cdef Flat_i32 out = Flat_i32(num_parameters)
|
|
503
|
+
cdef int32_t* x
|
|
504
|
+
for i in range(num_parameters):
|
|
505
|
+
x = &out(0,i)
|
|
506
|
+
x[0] = filtration[i]
|
|
507
|
+
return out
|
|
508
|
+
|
|
509
|
+
cdef inline vector[Flat_i32] python_2_vect_Flat_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
510
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
511
|
+
cdef vector[Flat_i32] out
|
|
512
|
+
cdef vector[int32_t] f = vector[int32_t](filtrations.shape[1])
|
|
513
|
+
out.reserve(filtrations.shape[0])
|
|
514
|
+
for i in range(filtrations.shape[0]):
|
|
515
|
+
for j in range(filtrations.shape[1]):
|
|
516
|
+
f[j] = filtrations[i,j]
|
|
517
|
+
out.emplace_back(f)
|
|
518
|
+
return out
|
|
519
|
+
cdef inline KFlat_f64_2_python(KFlat_f64* x, bool copy=False, bool raw=False):
|
|
520
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
cdef int num_parameters = 2
|
|
524
|
+
|
|
525
|
+
cdef double[:] data_view = <double[:k]>(&(dereference(x)(0,0)))
|
|
526
|
+
numpy_view = np.asarray(data_view, dtype=np.float64)
|
|
527
|
+
if raw:
|
|
528
|
+
return numpy_view
|
|
529
|
+
return np.concatenate([numpy_view[:,None], np.arange(k, dtype=np.float64)[:,None]], axis=1)
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
cdef inline vect_KFlat_f64_2_python(vector[KFlat_f64]& x, bool copy = False, bool raw=False):
|
|
533
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
534
|
+
return [KFlat_f64_2_python(&(x[i]), copy=copy, raw=raw) for i in range(num_stuff)]
|
|
535
|
+
|
|
536
|
+
cdef inline KFlat_f64 python_2_KFlat_f64(double[:,:] filtrations) noexcept nogil:
|
|
537
|
+
cdef vector[double] f = vector[double](filtrations.shape[0] * filtrations.shape[1])
|
|
538
|
+
cdef int k = 0;
|
|
539
|
+
for i in range(filtrations.shape[0]):
|
|
540
|
+
for j in range(filtrations.shape[1]):
|
|
541
|
+
f[k] = filtrations[i,j]
|
|
542
|
+
k = k + 1
|
|
543
|
+
cdef KFlat_f64 out = KFlat_f64(f.begin(), f.end(), filtrations.shape[1])
|
|
544
|
+
out.simplify()
|
|
545
|
+
return out
|
|
546
|
+
|
|
547
|
+
cdef inline vector[KFlat_f64] python_2_vect_KFlat_f64(double[:,:] filtrations) noexcept nogil:
|
|
548
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
549
|
+
cdef vector[KFlat_f64] out
|
|
550
|
+
cdef vector[double] f = vector[double](filtrations.shape[1])
|
|
551
|
+
out.reserve(filtrations.shape[0])
|
|
552
|
+
for i in range(filtrations.shape[0]):
|
|
553
|
+
for j in range(filtrations.shape[1]):
|
|
554
|
+
f[j] = filtrations[i,j]
|
|
555
|
+
out.emplace_back(f)
|
|
556
|
+
return out
|
|
557
|
+
cdef inline Flat_f64_2_python(Flat_f64* x, bool copy=False, bool raw=False):
|
|
558
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
cdef int num_parameters = 2
|
|
562
|
+
|
|
563
|
+
cdef double[:] data_view = <double[:k]>(&(dereference(x)(0,0)))
|
|
564
|
+
numpy_view = np.asarray(data_view, dtype=np.float64)
|
|
565
|
+
if raw:
|
|
566
|
+
return numpy_view
|
|
567
|
+
return np.concatenate([numpy_view[:,None], np.arange(k, dtype=np.float64)[:,None]], axis=1)
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
cdef inline vect_Flat_f64_2_python(vector[Flat_f64]& x, bool copy = False, bool raw=False):
|
|
571
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
572
|
+
return [Flat_f64_2_python(&(x[i]), copy=copy, raw=raw) for i in range(num_stuff)]
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
cdef inline Flat_f64 python_2_Flat_f64(double[:] filtration) noexcept nogil:
|
|
577
|
+
cdef int num_parameters = filtration.shape[0]
|
|
578
|
+
cdef Flat_f64 out = Flat_f64(num_parameters)
|
|
579
|
+
cdef double* x
|
|
580
|
+
for i in range(num_parameters):
|
|
581
|
+
x = &out(0,i)
|
|
582
|
+
x[0] = filtration[i]
|
|
583
|
+
return out
|
|
584
|
+
|
|
585
|
+
cdef inline vector[Flat_f64] python_2_vect_Flat_f64(double[:,:] filtrations) noexcept nogil:
|
|
586
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
587
|
+
cdef vector[Flat_f64] out
|
|
588
|
+
cdef vector[double] f = vector[double](filtrations.shape[1])
|
|
589
|
+
out.reserve(filtrations.shape[0])
|
|
590
|
+
for i in range(filtrations.shape[0]):
|
|
591
|
+
for j in range(filtrations.shape[1]):
|
|
592
|
+
f[j] = filtrations[i,j]
|
|
593
|
+
out.emplace_back(f)
|
|
594
|
+
return out
|
|
595
|
+
cdef inline KContiguous_i32_2_python(KContiguous_i32* x, bool copy=False, bool raw=False):
|
|
596
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
cdef Py_ssize_t p = dereference(x).num_parameters()
|
|
600
|
+
if dereference(x).is_finite():
|
|
601
|
+
duplicate = 0
|
|
602
|
+
else:
|
|
603
|
+
duplicate = p
|
|
604
|
+
# TODO : make it contiguous
|
|
605
|
+
return [_ff21cview2_i32(&(dereference(x)(i,0)), p, duplicate, copy=copy) for i in range(k)]
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
cdef inline vect_KContiguous_i32_2_python(vector[KContiguous_i32]& x, bool copy = False, bool raw=False):
|
|
609
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
610
|
+
return [KContiguous_i32_2_python(&(x[i]), copy=copy, raw=raw) for i in range(num_stuff)]
|
|
611
|
+
|
|
612
|
+
cdef inline KContiguous_i32 python_2_KContiguous_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
613
|
+
cdef vector[double] f = vector[double](filtrations.shape[0] * filtrations.shape[1])
|
|
614
|
+
cdef int k = 0;
|
|
615
|
+
for i in range(filtrations.shape[0]):
|
|
616
|
+
for j in range(filtrations.shape[1]):
|
|
617
|
+
f[k] = filtrations[i,j]
|
|
618
|
+
k = k + 1
|
|
619
|
+
cdef KContiguous_i32 out = KContiguous_i32(f.begin(), f.end(), filtrations.shape[1])
|
|
620
|
+
out.simplify()
|
|
621
|
+
return out
|
|
622
|
+
|
|
623
|
+
cdef inline vector[KContiguous_i32] python_2_vect_KContiguous_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
624
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
625
|
+
cdef vector[KContiguous_i32] out
|
|
626
|
+
cdef vector[int32_t] f = vector[int32_t](filtrations.shape[1])
|
|
627
|
+
out.reserve(filtrations.shape[0])
|
|
628
|
+
for i in range(filtrations.shape[0]):
|
|
629
|
+
for j in range(filtrations.shape[1]):
|
|
630
|
+
f[j] = filtrations[i,j]
|
|
631
|
+
out.emplace_back(f)
|
|
632
|
+
return out
|
|
633
|
+
# Assumes it's contiguous
|
|
634
|
+
cdef inline Contiguous_i32_2_python(Contiguous_i32* x, bool copy=False, bool raw=False):
|
|
635
|
+
cdef Py_ssize_t num_parameters = dereference(x).num_parameters()
|
|
636
|
+
if not dereference(x).is_finite():
|
|
637
|
+
return np.full(shape=num_parameters, fill_value=dereference(x)(0,0))
|
|
638
|
+
cdef int32_t[:] x_view = <int32_t[:num_parameters]>(&(dereference(x)(0,0)))
|
|
639
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
640
|
+
|
|
641
|
+
cdef inline vect_Contiguous_i32_2_python(vector[Contiguous_i32]& x, bool copy = False, bool raw=False):
|
|
642
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
643
|
+
return [Contiguous_i32_2_python(&(x[i]), copy=copy, raw=raw) for i in range(num_stuff)]
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
cdef inline Contiguous_i32 python_2_Contiguous_i32(int32_t[:] filtration) noexcept nogil:
|
|
648
|
+
cdef int num_parameters = filtration.shape[0]
|
|
649
|
+
cdef Contiguous_i32 out = Contiguous_i32(num_parameters)
|
|
650
|
+
cdef int32_t* x
|
|
651
|
+
for i in range(num_parameters):
|
|
652
|
+
x = &out(0,i)
|
|
653
|
+
x[0] = filtration[i]
|
|
654
|
+
return out
|
|
655
|
+
|
|
656
|
+
cdef inline vector[Contiguous_i32] python_2_vect_Contiguous_i32(int32_t[:,:] filtrations) noexcept nogil:
|
|
657
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
658
|
+
cdef vector[Contiguous_i32] out
|
|
659
|
+
cdef vector[int32_t] f = vector[int32_t](filtrations.shape[1])
|
|
660
|
+
out.reserve(filtrations.shape[0])
|
|
661
|
+
for i in range(filtrations.shape[0]):
|
|
662
|
+
for j in range(filtrations.shape[1]):
|
|
663
|
+
f[j] = filtrations[i,j]
|
|
664
|
+
out.emplace_back(f)
|
|
665
|
+
return out
|
|
666
|
+
cdef inline KContiguous_f64_2_python(KContiguous_f64* x, bool copy=False, bool raw=False):
|
|
667
|
+
cdef Py_ssize_t k = dereference(x).num_generators()
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
cdef Py_ssize_t p = dereference(x).num_parameters()
|
|
671
|
+
if dereference(x).is_finite():
|
|
672
|
+
duplicate = 0
|
|
673
|
+
else:
|
|
674
|
+
duplicate = p
|
|
675
|
+
# TODO : make it contiguous
|
|
676
|
+
return [_ff21cview2_f64(&(dereference(x)(i,0)), p, duplicate, copy=copy) for i in range(k)]
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
cdef inline vect_KContiguous_f64_2_python(vector[KContiguous_f64]& x, bool copy = False, bool raw=False):
|
|
680
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
681
|
+
return [KContiguous_f64_2_python(&(x[i]), copy=copy, raw=raw) for i in range(num_stuff)]
|
|
682
|
+
|
|
683
|
+
cdef inline KContiguous_f64 python_2_KContiguous_f64(double[:,:] filtrations) noexcept nogil:
|
|
684
|
+
cdef vector[double] f = vector[double](filtrations.shape[0] * filtrations.shape[1])
|
|
685
|
+
cdef int k = 0;
|
|
686
|
+
for i in range(filtrations.shape[0]):
|
|
687
|
+
for j in range(filtrations.shape[1]):
|
|
688
|
+
f[k] = filtrations[i,j]
|
|
689
|
+
k = k + 1
|
|
690
|
+
cdef KContiguous_f64 out = KContiguous_f64(f.begin(), f.end(), filtrations.shape[1])
|
|
691
|
+
out.simplify()
|
|
692
|
+
return out
|
|
693
|
+
|
|
694
|
+
cdef inline vector[KContiguous_f64] python_2_vect_KContiguous_f64(double[:,:] filtrations) noexcept nogil:
|
|
695
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
696
|
+
cdef vector[KContiguous_f64] out
|
|
697
|
+
cdef vector[double] f = vector[double](filtrations.shape[1])
|
|
698
|
+
out.reserve(filtrations.shape[0])
|
|
699
|
+
for i in range(filtrations.shape[0]):
|
|
700
|
+
for j in range(filtrations.shape[1]):
|
|
701
|
+
f[j] = filtrations[i,j]
|
|
702
|
+
out.emplace_back(f)
|
|
703
|
+
return out
|
|
704
|
+
# Assumes it's contiguous
|
|
705
|
+
cdef inline Contiguous_f64_2_python(Contiguous_f64* x, bool copy=False, bool raw=False):
|
|
706
|
+
cdef Py_ssize_t num_parameters = dereference(x).num_parameters()
|
|
707
|
+
if not dereference(x).is_finite():
|
|
708
|
+
return np.full(shape=num_parameters, fill_value=dereference(x)(0,0))
|
|
709
|
+
cdef double[:] x_view = <double[:num_parameters]>(&(dereference(x)(0,0)))
|
|
710
|
+
return np.array(x_view) if copy else np.asarray(x_view)
|
|
711
|
+
|
|
712
|
+
cdef inline vect_Contiguous_f64_2_python(vector[Contiguous_f64]& x, bool copy = False, bool raw=False):
|
|
713
|
+
cdef Py_ssize_t num_stuff = x.size()
|
|
714
|
+
return [Contiguous_f64_2_python(&(x[i]), copy=copy, raw=raw) for i in range(num_stuff)]
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
cdef inline Contiguous_f64 python_2_Contiguous_f64(double[:] filtration) noexcept nogil:
|
|
719
|
+
cdef int num_parameters = filtration.shape[0]
|
|
720
|
+
cdef Contiguous_f64 out = Contiguous_f64(num_parameters)
|
|
721
|
+
cdef double* x
|
|
722
|
+
for i in range(num_parameters):
|
|
723
|
+
x = &out(0,i)
|
|
724
|
+
x[0] = filtration[i]
|
|
725
|
+
return out
|
|
726
|
+
|
|
727
|
+
cdef inline vector[Contiguous_f64] python_2_vect_Contiguous_f64(double[:,:] filtrations) noexcept nogil:
|
|
728
|
+
# cdef double[:,:] filtrations = np.asarray(filtrations_, dtype=np.float64)
|
|
729
|
+
cdef vector[Contiguous_f64] out
|
|
730
|
+
cdef vector[double] f = vector[double](filtrations.shape[1])
|
|
731
|
+
out.reserve(filtrations.shape[0])
|
|
732
|
+
for i in range(filtrations.shape[0]):
|
|
733
|
+
for j in range(filtrations.shape[1]):
|
|
734
|
+
f[j] = filtrations[i,j]
|
|
735
|
+
out.emplace_back(f)
|
|
736
|
+
return out
|