Skip to content

feat(algebra): implement discrete RV product in Rust and wire Python RV multiplication#39

Merged
MthwRobinson merged 11 commits intomainfrom
feat/rust-product
Mar 27, 2026
Merged

feat(algebra): implement discrete RV product in Rust and wire Python RV multiplication#39
MthwRobinson merged 11 commits intomainfrom
feat/rust-product

Conversation

@MthwRobinson
Copy link
Owner

Description

This PR moves discrete random-variable product logic from Python to Rust and routes RV multiplication through the Rust-backed FastRV path.

Key changes included in this branch:

  • Added a new Rust algebra module with product_discrete for independent discrete RVs, including:
    • conversion of inputs to PDF form,
    • cartesian-product support/function computation,
    • sorting + de-duplication of repeated support values by summing probabilities.
  • Added Rust-side operator support:
    • impl Mul for RandomVariable,
    • impl Mul for FastRV,
    • Python-exposed product_discrete binding.
  • Registered the new binding in rust/src/lib.rs.
  • Updated Python integration:
    • removed legacy _product_discrete NumPy implementation from applpy/algebra.py,
    • made product() use to_fast_rv()/from_fast_rv() for discrete RV multiplication,
    • added RV.to_fast_rv() and RV.from_fast_rv() helpers in applpy/rv.py,
    • reused RV.from_fast_rv() in bootstrap_rv.
  • Added/updated tests:
    • Rust tests for discrete product behavior (duplicate support merge, CDF input conversion, output metadata),
    • Python tests for FastRV round-trip conversion and discrete multiplication/error paths.
  • Included minor cleanup in Rust error strings (conversion typo fixes).

Testing

Run the following from the repository root:

For Rust changes:

  • make cargo-check
  • make cargo-test

For Python changes:

  • make check
  • make rust-develop
  • make test

@MthwRobinson MthwRobinson merged commit fcbcbf0 into main Mar 27, 2026
8 checks passed
@MthwRobinson MthwRobinson deleted the feat/rust-product branch March 27, 2026 01:05
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