summaryrefslogtreecommitdiff
path: root/src/python/include/Simplex_tree_interface.h
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2020-05-29 17:56:45 +0200
committerMarc Glisse <marc.glisse@inria.fr>2020-05-29 17:56:45 +0200
commit34207229b3ab2936aecd953997286a0daab88a83 (patch)
treea6271b2eec86d848c6443d4cceb47e29227148d5 /src/python/include/Simplex_tree_interface.h
parent48d9ff9986cb3a6e36f60142784c2a02317dd327 (diff)
convert matrix to SimplexTree
Diffstat (limited to 'src/python/include/Simplex_tree_interface.h')
-rw-r--r--src/python/include/Simplex_tree_interface.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/python/include/Simplex_tree_interface.h b/src/python/include/Simplex_tree_interface.h
index 56d7c41d..295b1b7f 100644
--- a/src/python/include/Simplex_tree_interface.h
+++ b/src/python/include/Simplex_tree_interface.h
@@ -36,6 +36,8 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> {
using Skeleton_simplex_iterator = typename Base::Skeleton_simplex_iterator;
using Complex_simplex_iterator = typename Base::Complex_simplex_iterator;
using Extended_filtration_data = typename Base::Extended_filtration_data;
+ using Siblings = typename Base::Siblings;
+ using Node = typename Base::Node;
public:
@@ -57,6 +59,30 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> {
return (result.second);
}
+ void insert_matrix(double* filtrations, int n, int stride0, int stride1, double max_filtration) {
+ // We could delegate to insert_graph, but wrapping the matrix in a graph interface is too much work
+ assert(this->num_simplices() == 0);
+ auto& rm = this->root()->members_;
+ for(int i=0; i<n; ++i) {
+ char* p = (char*)filtrations + i * stride0;
+ double fv = *(double*)(p + i * stride1);
+ if(fv > max_filtration) continue;
+ auto sh = rm.emplace_hint(rm.end(), i, Node(this->root(), fv));
+ Siblings* children = nullptr;
+ // Should we make a first pass to count the number of edges so we can reserve the right space?
+ for(int j=i+1; j<n; ++j) {
+ double fe = *(double*)(p + j * stride1);
+ if(fe > max_filtration) continue;
+ if(!children) {
+ children = new Siblings(this->root(), i);
+ sh->second.assign_children(children);
+ }
+ children->members().emplace_hint(children->members().end(), j, Node(children, fe));
+ }
+ }
+
+ }
+
// Do not interface this function, only used in alpha complex interface for complex creation
bool insert_simplex(const Simplex& simplex, Filtration_value filtration = 0) {
Insertion_result result = Base::insert_simplex(simplex, filtration);