Skip to content

feat(transform): add Rust discrete-mixture transform and wire it into Python API#38

Merged
MthwRobinson merged 9 commits intomainfrom
feat/mixture-rust
Mar 25, 2026
Merged

feat(transform): add Rust discrete-mixture transform and wire it into Python API#38
MthwRobinson merged 9 commits intomainfrom
feat/mixture-rust

Conversation

@MthwRobinson
Copy link
Owner

Description

This PR adds a Rust implementation of discrete mixture transforms and switches Python’s _mixture_discrete path to use the Rust binding for faster and more consistent behavior.

What changed

  • Added mixture_discrete in rust/src/algorithms/transform.rs:
    • validates input lengths (random_variables vs mix_weights)
    • validates mixture weights sum to 1 (with tolerance)
    • combines duplicate support points across component RVs
    • sorts output support and returns a discrete PDF RV
  • Added Sum support for Number in rust/src/algorithms/number.rs to support cleaner weight-sum validation.
  • Exposed the new transform through PyO3:
    • added mixture_discrete_py in rust/src/python/api.rs
    • registered it in rust/src/lib.rs
  • Updated applpy/transform.py so _mixture_discrete calls applpy_rust.mixture_discrete(...) and returns an RV from the Rust result.
  • Added Rust coverage:
    • doc test example for mixture_discrete
    • unit tests for happy path, length mismatch, and invalid weight sums

Overall, the branch replaces Python-side discrete mixture accumulation with a Rust-backed implementation and adds validation/tests around the new behavior.

Testing

Run the following from the repository root:

  • make cargo-check
  • make cargo-test
  • make check
  • make rust-develop
  • make test

@MthwRobinson MthwRobinson merged commit 1540128 into main Mar 25, 2026
8 checks passed
@MthwRobinson MthwRobinson deleted the feat/mixture-rust branch March 25, 2026 18:36
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