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

Fix fast cofaces for insert_batch_vertices #971

Conversation

VincentRouvreau
Copy link
Contributor

Fix #970
To be discussed if storing information in a std::vector<Vertex_handle> is a good idea 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.

Try a simple loop with if(!x.is_linked()) update(x);, it will be less likely to go wrong.

Comment on lines 1322 to 1325
std::vector<Vertex_handle> old_members(root_.members().size());
if constexpr (Options::link_nodes_by_label) {
for (auto sh = root_.members().begin(); sh != root_.members().end(); sh++)
old_members.emplace_back(sh->first);
Copy link
Member

Choose a reason for hiding this comment

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

You create old_members that contains n copies of 0 then append the rest to it? Did you mean to use reserve instead?

root_.members_.insert(boost::begin(verts), boost::end(verts));
if (dimension_ < 0 && !root_.members_.empty()) dimension_ = 0;
for (auto sh = root_.members().begin(); sh != root_.members().end(); sh++) {
if constexpr (Options::link_nodes_by_label) {
if (std::find(old_members.begin(), old_members.end(), sh->first) == std::end(old_members))
Copy link
Member

Choose a reason for hiding this comment

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

No, using std::find yields a quadratic cost, whereas both vectors are sorted so it would be possible to walk on both at the same time in linear time.

if (std::find(old_members.begin(), old_members.end(), sh->first) == std::end(old_members))
update_simplex_tree_after_node_insertion(sh);
} else {
update_simplex_tree_after_node_insertion(sh);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this appears in both branches, but with a test in one branch?

@@ -1321,6 +1321,12 @@ class Simplex_tree {
return Dit_value_t(v, Node(&root_, filt)); });
root_.members_.insert(boost::begin(verts), boost::end(verts));
if (dimension_ < 0 && !root_.members_.empty()) dimension_ = 0;
if constexpr (Options::link_nodes_by_label) {
for (auto sh = root_.members().begin(); sh != root_.members().end(); sh++) {
if (nodes_label_to_list_.find(sh->first) == nodes_label_to_list_.end())
Copy link
Member

Choose a reason for hiding this comment

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

Or something like

Suggested change
if (nodes_label_to_list_.find(sh->first) == nodes_label_to_list_.end())
if (!sh->second.list_max_vertex_hook_.is_linked())

?

@VincentRouvreau VincentRouvreau added the 3.9.0 GUDHI version 3.9.0 label Sep 27, 2023
@VincentRouvreau VincentRouvreau merged commit 78d8440 into GUDHI:master Sep 27, 2023
7 checks passed
@VincentRouvreau VincentRouvreau deleted the insert_batch_vertices_fast_cofaces branch September 27, 2023 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9.0 GUDHI version 3.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Simplex_tree] insert_batch_vertices shall call update_simplex_tree_after_node_insertion
2 participants