Repository navigation
Prune trees with different leaf sets in C++ (#123) - #221
Open
ms609-agent wants to merge 9 commits into
Open
ms609-agent wants to merge 9 commits into
ms609-agent wants to merge 9 commits into
Conversation
Pairs of trees with different leaves were compared by pruning each pair with KeepTip() in R, once for the score and again for each normalizing value, holding n(n-1) pruned trees in memory. cpp_pruned_pairs() now restricts each tree's splits to the shared leaves, merges splits that coincide, and scores the pair and its information content in one OpenMP pass. TreeDistance() on 150 gene trees: 15.6 s -> 1.0 s. Also fixes, for trees with differing leaf sets: - all-pairs scores, which misaligned leaves when pruning Splits objects; - RobinsonFoulds(trees), which ignored the differing leaves; - tree1-vs-tree2 matrices, which were transposed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NEWS.md had a cp1252 multiplication sign, which spell_check_package() rejects as invalid UTF-8. The r-hub fedora-44 ape binary links libRlapack.so, which the current gcc-asan image no longer ships, so dependency installation failed before any TreeDist code ran. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Building ape from source fixed only ape: mvtnorm and other r-hub fedora-44 binaries also link libRlapack.so, which the gcc-asan image lacks. Symlink it to the LAPACK library R itself uses instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #221 +/- ##
==========================================
+ Coverage 97.57% 97.65% +0.07%
==========================================
Files 60 60
Lines 6056 6305 +249
==========================================
+ Hits 5909 6157 +248
- Misses 147 148 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Checking leaf sets with TipLabels() slowed RobinsonFoulds(trees) by c. 8% (CI benchmark). as.ClusterTable() already errors on a leaf missing from the first tree; trees whose leaves are a strict subset are caught by comparing each table's leaf count, in C++. The same check closes that loophole in the cross-pairs fast path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
The R loop used when a scoring function has no C++ version (or a cluster is registered) still pruned Splits without reordering their leaves. Cover it and the one-vs-many fallback with tests, restoring project coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
readxl 1.6.0 needs R >= 4.2; the 2026-06-05 snapshot has 1.5.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Performance benchmark results
|
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.
Closes #123.
What
Trees with different leaf sets were compared by pruning each pair with
KeepTip()in R — once for the score (.SplitDistanceAllPairs()etc.), again in.MaxValue(), and again inNormalizeInfo()— holding n(n−1) prunedphyloobjects in memory at once.New
cpp_pruned_pairs()(inpairwise_distances.cpp) restricts each tree's splits to the leaves it shares with its partner, drops trivial splits, merges splits that coincide after pruning, then scores the pair with the existing batch kernels and reports each pruned tree's information content (clustering entropy / splitwise info / split count). It runs in OpenMP over pairs, with per-thread scratch. Wired into:.SplitDistanceAllPairs(),.SplitDistanceManyMany()and.SplitDistanceOneMany()(MCI, IRF, MSD, MSI, SPI, Nye/Jaccard, RF);.MaxValue()andNormalizeInfo()when the information function isClusteringEntropy,SplitwiseInfoorNSplits.NormalizeInfo()also no longer prunes trees wheninfoInBothor a numerichowis given.Other scoring and information functions keep the R path.
Benchmark (150 random trees, 40–70 of 80 leaves, 1 thread, optimised build)
TreeDistance(trees)PhylogeneticInfoDistance(trees, normalize = TRUE)RobinsonFoulds(trees[1:60], trees[61:150])gc()max, MB)Bug fixes found along the way (in NEWS)
KeepTip()on aSplitsobject keeps that tree's own leaf order, so the two pruned trees' bits could refer to different leaves. Example: MCI 2.60 from all-pairs vs 3.56 from comparing the pruned pair directly. The new code matches theKeepTip()-on-phyloreference for every metric (seetest-pruned_pairs.R).RobinsonFoulds(trees)with differing leaf sets went through the ClusterTable path, which ignores the leaf differences, and returned wrong values.f(list1, list2)was transposed when leaf sets differed (rows weretree2), unlike the same-leaves case. Rows now always correspond totree1..SharedOnly()now lists N × M pairs in column-major order to match. One existing expectation intest-different-tips.Rencoded the transposed shape and is updated. This is a user-visible change.Notes for review
SplitListcan only be built from anRawMatrix, so each thread builds one before the parallel region, sized to the largest input, and overwrites its public fields for each pair. That depends on the TreeToolsSplitListlayout (row stride ≥ pruned bin count); a capacity constructor in TreeTools would be tidier but would need aLinkingTobump.NaN, which matches the existing 1-vs-1 behaviour.spelling::spell_check_package()errors locally on a Windows UTF-8 issue that already exists inNEWS.md; CI'stests/spelling.Rwill cover it.🤖 Generated with Claude Code