Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Simplex tree] Additional copy constructor for Simplex_tree #1121

Merged

Conversation

hschreiber
Copy link
Collaborator

@hschreiber hschreiber commented Aug 13, 2024

Another copy constructor for the simplex tree copying from a simplex tree with eventually different options as template parameter. Takes also a method converting the filtration values. Will be used to replace the methods multify and flatten in PR #976.

I also changed the default copy constructor such that it copies all the keys. For now, it copied the keys of the vertices (with the default copy constructors of the node), but not for the other faces (the nodes were reconstructed from scratch). Copying the keys is not adding to the complexity, so I think that it is worth correcting the inconsistency. Also, I can imagine scenarios where having the keys can be useful when flatten a multi simplex tree (to keep the correspondences of the boundaries in the boundary matrix used for most of the computations).

Edit: we should also think about the attribute 'data' in the nodes to be copied or not.

Copy link
Member

@mglisse mglisse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some quick comments

src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Show resolved Hide resolved
for (auto& p : root_source.members()){
auto it = root_.members().try_emplace(root_.members().end(), p.first);
it->second.assign_children(&root_);
it->second.assign_filtration(translate_filtration_value(p.second.filtration()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multi, do we have that emplace creates a vector of size 1 containing +inf, then translate creates a vector of size 2 (for instance), then assign_filtration copies that vector, for a total of 3 allocations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted old answer, as I just realized I remembered it all wrong... And I don't remember why I made this choice. I will try the constructor version, that should avoid at least one allocation.

src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
void assign_key(Simplex_key k) { key_ = k; }
Simplex_key key() const { return key_; }
private:
Simplex_key key_;
};
struct Key_simplex_base_dummy {
Key_simplex_base_dummy() {}
Key_simplex_base_dummy(Simplex_key k) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the conclusion was to remove this constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be done now.

src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
@VincentRouvreau VincentRouvreau merged commit 903f210 into GUDHI:master Sep 13, 2024
7 checks passed
@VincentRouvreau VincentRouvreau added the 3.11.0 GUDHI version 3.11.0 label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11.0 GUDHI version 3.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants