Repository navigation
NNIDist(): score all pairs in one C++ call - #228
Open
ms609-agent wants to merge 1 commit into
Open
ms609-agent wants to merge 1 commit into
ms609-agent wants to merge 1 commit into
Conversation
Renumber and postorder each tree once, compute each tree's splits once, and score every pair in cpp_nni_distance_all_pairs(). Output identical to CompareAll(trees, NNIDist). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| for (int32_t i = 0; i < n_edge - 1; ++i) { /* final edge is second root edge */ | ||
| const ptrdiff_t parent_row_i = (edge(i, 0) - 1) * n_bin; | ||
| const ptrdiff_t child_row_i = (edge(i, 1) - 1) * n_bin; | ||
| const ptrdiff_t parent_row_i = (tree.parent[i] - 1) * n_bin; |
| const ptrdiff_t parent_row_i = (edge(i, 0) - 1) * n_bin; | ||
| const ptrdiff_t child_row_i = (edge(i, 1) - 1) * n_bin; | ||
| const ptrdiff_t parent_row_i = (tree.parent[i] - 1) * n_bin; | ||
| const ptrdiff_t child_row_i = (tree.child[i] - 1) * n_bin; |
Performance benchmark results
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #228 +/- ##
==========================================
+ Coverage 97.74% 97.77% +0.02%
==========================================
Files 60 60
Lines 6575 6648 +73
==========================================
+ Hits 6427 6500 +73
Misses 148 148 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NNIDist(trees)(one list, all pairs) now renumbers and postorders each tree once and scores every pair in a single C++ call (cpp_nni_distance_all_pairs()), instead ofCompareAll()→.NNIDistSingle()per pair. Each tree's splits are computed once; per pair only the split matching and scoring run.cpp_nni_distance()shares the same core (nni_tree(),nni_edge_to_splits(),nni_rf_matching(),nni_score()). Two-argumentNNIDist(tree1, tree2)is unchanged.Identity. Output is
identical()toCompareAll(trees, NNIDist)(old path) on all 945 7-leaf trees, unrooted 7-leaf trees, random 60–200-leaf trees with shuffled labels, 3-leaf trees, polytomies, and lists that mix rooted and unrooted trees with equal edge counts (a pair is scored under the first tree's rootedness, as before; the second tree's splits are recomputed in that case).Benchmark (release installs, min of N, single thread, local R-devel, same session):
Main's 945-tree time includes the multiPhylo indexing cost fixed in #227; this PR bypasses
CompareAll()so doesn't conflict with it. Recorded in.AGENTS/memory/Optimizations.md. At 200 leaves the O(s²) split matching now dominates; sorting canonical splits would allow a linear merge (follow-up).New R and C++ lines covered by
test-tree_distance_nni.R; NEWS entry added.🤖 Generated with Claude Code