Skip to content

Links into nodes: post processing algorithm - Reduced echelon form#1326

Open
figueroa1395 wants to merge 17 commits intomainfrom
feature/add_reduced_echelon_form_function
Open

Links into nodes: post processing algorithm - Reduced echelon form#1326
figueroa1395 wants to merge 17 commits intomainfrom
feature/add_reduced_echelon_form_function

Conversation

@figueroa1395
Copy link
Copy Markdown
Member

@figueroa1395 figueroa1395 commented Mar 10, 2026

In this PR I introduce the first step of the post processing algorithm of merging links into nodes feature.

The things that need to happen are:

  • Forward elimination (elimination game) algorithm implementation.
  • Unit test the forward elimination algorithm.
  • Backward substitution algorithm implementation.
  • Unit test backward substitution algorithm.
  • Combine to above to make the reduced echelon form algorithm implementation.

Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
@figueroa1395 figueroa1395 self-assigned this Mar 10, 2026
@figueroa1395 figueroa1395 added feature New feature or request do-not-merge This should not be merged labels Mar 10, 2026
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
@figueroa1395 figueroa1395 marked this pull request as ready for review March 18, 2026 14:56
@figueroa1395 figueroa1395 removed the do-not-merge This should not be merged label Mar 18, 2026
@sonarqubecloud
Copy link
Copy Markdown


enum class EdgeDirection : IntS { Away = -1, Towards = 1 };

struct COOSparseMatrix {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please add a docstring to explain the abbreviation COO

Comment on lines +46 to +53
bool get_value(IntS& value, uint64_t row_idx, uint64_t col_idx) const {
assert(row_number != 0 && "row_number must be set before getting values from data_map");
if (auto const it = data_map.find(row_idx * row_number + col_idx); it != data_map.end()) {
value = it->second;
return true;
}
return false;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there a reason you want to use a target value pattern rather than a throwing value? it may be good to instead use std::optional instead. Yes it is slightly less memory efficient, but it is much more readable and better indicating the intention

assert(row_number != 0 && "row_number must be set before adding values in data_map");
auto const key = row_idx * row_number + col_idx;
if (auto const it = data_map.find(key); it != data_map.end()) {
it->second = static_cast<IntS>(it->second + value);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
it->second = static_cast<IntS>(it->second + value);
it->second = narrow_cast<IntS>(it->second + value);

Comment on lines +82 to +85
[[nodiscard]] constexpr Idx from_node(BranchIdx const& edge) { return edge[0]; }
[[nodiscard]] constexpr Idx& from_node(BranchIdx& edge) { return edge[0]; }
[[nodiscard]] constexpr Idx to_node(BranchIdx const& edge) { return edge[1]; }
[[nodiscard]] constexpr Idx& to_node(BranchIdx& edge) { return edge[1]; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't use nodiscard yet in the rest of our code. NOTE: i am very much in favor of using it, but I remember a discussion in which we said we did not want to use it. We can revisit if we want to.

// unordered_set for O(1) insert/erase during reattachment
[[nodiscard]] inline auto build_adjacency_map(std::span<BranchIdx> edges) -> AdjacencyMap {
AdjacencyMap adjacency_map{};
for (auto const& [raw_index, edge] : enumerate(std::as_const(edges))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please resolve the sonar cloud warning (see also #1257)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants