Skip to content

feat(transform): add Rust-backed discrete truncate and wire it into Python API#37

Merged
MthwRobinson merged 6 commits intomainfrom
feat/rust-truncate
Mar 24, 2026
Merged

feat(transform): add Rust-backed discrete truncate and wire it into Python API#37
MthwRobinson merged 6 commits intomainfrom
feat/rust-truncate

Conversation

@MthwRobinson
Copy link
Owner

Description

This PR adds a Rust implementation of discrete truncation and integrates it into the Python transform flow.

Between main and this feature branch, the change set introduces a new transform::truncate_discrete algorithm in Rust that:

  • converts inputs to PDF form,
  • validates truncation bounds,
  • computes retained mass in the requested support range,
  • renormalizes probabilities,
  • returns clear errors for invalid bounds or zero retained mass.

The Rust function is exported through the Python bindings (truncate_discrete), registered in the extension module, and then used by applpy/transform.py to replace the previous pure-Python discrete truncation path.

The PR also:

  • adds a strict import-time error message in Python when applpy_rust is not built,
  • includes Rust doc-test coverage and Rust unit tests for truncation behavior and bound validation,
  • updates Python unit expectations so invalid equal bounds now raise ValueError.

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 cee7496 into main Mar 24, 2026
8 checks passed
@MthwRobinson MthwRobinson deleted the feat/rust-truncate branch March 24, 2026 19:53
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