Skip to content

Commit

Permalink
[CPP] use variable when getting pivot index
Browse files Browse the repository at this point in the history
Remove check for first insertion for pivot_to_death_idx hash table

Signed-off-by: julian <[email protected]>
  • Loading branch information
julian committed Jan 7, 2022
1 parent 300e2f3 commit 72aff5e
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions gph/src/ripser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1385,10 +1385,11 @@ class ripser
}
diameter_entry_t e;

index_t pivot_idx;
while (true) {
if (get_index(pivot) != -1) {
auto pair =
pivot_column_index.find(get_index(get_entry(pivot)));
pivot_idx = get_index(pivot);
if (pivot_idx != -1) {
auto pair = pivot_column_index.find(pivot_idx);
if (pair != pivot_column_index.end()) {
entry_t old_entry_column_to_add;
index_t index_column_to_add;
Expand Down Expand Up @@ -1438,7 +1439,7 @@ class ripser
retire_column(index_column_to_reduce,
working_reduction_column,
reduction_matrix, columns_to_reduce,
dim, get_index(pivot),
dim, pivot_idx,
memory_manager);

if (pivot_column_index.update(
Expand All @@ -1462,12 +1463,11 @@ class ripser
retire_column(index_column_to_reduce,
working_reduction_column,
reduction_matrix, columns_to_reduce, dim,
get_index(pivot), memory_manager);
pivot_idx, memory_manager);

// equivalent to CAS in the original algorithm
auto insertion_result = pivot_column_index.insert(
{get_index(get_entry(pivot)),
make_entry(index_column_to_reduce,
{pivot_idx, make_entry(index_column_to_reduce,
get_coefficient(pivot))});
if (!insertion_result
.second) // failed to insert, somebody
Expand All @@ -1479,22 +1479,13 @@ class ripser

/* Pairs should be extracted if insertion was
* first one ! */
auto new_idx_finite_bar = idx_finite_bar++;
death_diams[new_idx_finite_bar] = get_diameter(pivot);
auto first_ins =
pivot_to_death_idx
.insert({get_index(get_entry(pivot)),
new_idx_finite_bar})
.second;

/* If the pivot was already inserted, retrieve the index
* of the corresponding column
auto new_idx_fin_bar = idx_finite_bar++;
death_diams[new_idx_fin_bar] = get_diameter(pivot);
/* Not necessary to check about first insertion because
* we already verified with pivot_column_index insert.
* We insert in the same pivot_idx
*/
if (!first_ins) {
new_idx_finite_bar =
get_index(pivot_to_death_idx.find(get_index(
get_entry(pivot)))->second);
}
pivot_to_death_idx.insert({pivot_idx, new_idx_fin_bar});

if (return_flag_persistence_generators) {
// Inessential flag persistence generators in dim >
Expand All @@ -1504,7 +1495,7 @@ class ripser

index_t birth_idx =
get_index(get_entry(column_to_reduce));
index_t death_idx = get_index(get_entry(pivot));
index_t death_idx = pivot_idx;

get_simplex_vertices(birth_idx, dim, n,
vertices_birth.rbegin());
Expand All @@ -1516,15 +1507,15 @@ class ripser
edge_t death_edge =
get_youngest_edge_simplex(vertices_death);

finite_generator[new_idx_finite_bar] = {
finite_generator[new_idx_fin_bar] = {
birth_edge.first, birth_edge.second,
death_edge.first, death_edge.second};
}

if (return_cocycles) {
// Representative cocycle
working_reduction_column.push(column_to_reduce);
cocycles_finite[new_idx_finite_bar] =
cocycles_finite[new_idx_fin_bar] =
compute_cocycles(working_reduction_column, dim);
}

Expand Down Expand Up @@ -1586,7 +1577,7 @@ class ripser
/* We push the order of the generator simplices by when
* they are inserted as bars. This can be done because
* get_index(it->second) is equivalent to
* `new_idx_finite_bar` in the core algorithm
* `new_idx_fin_bar` in the core algorithm
*/
ordered_location.push_back(get_index(it->second));
#if defined(SORT_BARCODES)
Expand Down

0 comments on commit 72aff5e

Please sign in to comment.