Skip to content

perf(tl): vectorize ancestral_states sum for array data#56

Merged
colganwi merged 1 commit intomainfrom
perf/ancestral-states-sum
Apr 13, 2026
Merged

perf(tl): vectorize ancestral_states sum for array data#56
colganwi merged 1 commit intomainfrom
perf/ancestral-states-sum

Conversation

@colganwi
Copy link
Copy Markdown
Collaborator

Summary

  • Replaces per-feature tree traversal loop with a single bottom-up pass using numpy for the sum method
  • Reduces complexity from O(n_nodes × n_features) tree traversals to one

Test plan

  • Existing ancestral_states tests pass
  • Verify correctness of sum output against previous implementation
  • Benchmark on large arrays to confirm speedup

🤖 Generated with Claude Code

Replace the per-feature tree traversal loop with a single bottom-up pass
using numpy for the sum method, reducing complexity from O(n_nodes * n_features)
tree traversals to one.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@colganwi colganwi merged commit 619c770 into main Apr 13, 2026
7 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.04%. Comparing base (2afbd61) to head (789fad2).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #56      +/-   ##
==========================================
+ Coverage   93.99%   94.04%   +0.04%     
==========================================
  Files          35       35              
  Lines        2983     3004      +21     
==========================================
+ Hits         2804     2825      +21     
  Misses        179      179              
Files with missing lines Coverage Δ
src/pycea/tl/ancestral_states.py 97.46% <100.00%> (+0.24%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@colganwi colganwi deleted the perf/ancestral-states-sum branch April 13, 2026 15:51
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 789fad2729

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +204 to +205
result = np.nansum(stacked, axis=0)
result[np.all(np.isnan(stacked), axis=0)] = np.nan
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve NaNs when summing array-valued descendants

Using np.nansum here changes the sum reconstruction semantics by treating missing child values as zero instead of propagating missingness. In the previous per-index implementation (and still in scalar sum), a child value of NaN made the parent NaN for that feature ([NaN, 2] -> NaN), but this branch now returns 2. That silently converts unknown measurements into observed totals and can materially change reconstructed ancestral states for arrays with partial missing data.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant