Skip range_extension_c for pure nodes in Mondrian classifier#1841
Merged
MaxHalford merged 1 commit intomainfrom Apr 28, 2026
Merged
Skip range_extension_c for pure nodes in Mondrian classifier#1841MaxHalford merged 1 commit intomainfrom
MaxHalford merged 1 commit intomainfrom
Conversation
When split_pure=False (default), check node purity before computing range extensions. Pure nodes will never split, so the expensive range_extension_c call can be skipped entirely. Benchmarks show ~3-5% speedup on datasets with 50+ features. Credit: @shi-zq for the observation in #1835. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
split_pure=False(default), moves the purity check before therange_extension_ccall in the classifier's downward pass. Pure nodes never split, so the range extension computation can be skipped entirely.Benchmark results
range_extension_ccost scales linearly with feature count (~1μs at 20 features, ~10μs at 200).Pure nodes are ~50% of all nodes (exclusively leaves — branches are always impure). The optimization saves one
range_extension_ccall perlearn_oneat the terminal pure leaf.(5000 samples, best of 5 runs,
split_pure=False,seed=42)Test plan
pytest river/tree/mondrian/passes (including doctests)🤖 Generated with Claude Code