Skip to content

Add host-only Python bindings crate multicalc-py - #330

Open
rtmongold wants to merge 1 commit into
mainfrom
add-multicalc-py-bindings
Open

Add host-only Python bindings crate multicalc-py#330
rtmongold wants to merge 1 commit into
mainfrom
add-multicalc-py-bindings

Conversation

@rtmongold

@rtmongold rtmongold commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #48

Expose a slice of crate-root multicalc over PyO3/maturin as import multicalc_py. Host f64 only; const-generic sizes are fixed in the type name. Workspace-internal (publish = false), with pytest coverage and crate/type docs.

Checklist

  • cargo test + cargo clippy --all-targets clean locally
  • New public APIs have a doc example
  • No unwrap/expect/panic on library paths (typed errors instead)

@rtmongold
rtmongold force-pushed the add-multicalc-py-bindings branch 2 times, most recently from f32bd34 to 3adada4 Compare August 24, 2026 23:52
@rtmongold
rtmongold marked this pull request as ready for review August 24, 2026 23:58
@rtmongold
rtmongold requested a review from kmolan as a code owner August 24, 2026 23:58
@kmolan

kmolan commented Aug 26, 2026

Copy link
Copy Markdown
Owner

will look at this by this weekend.

Comment thread crates/multicalc-py/src/callables.rs Outdated
});
match result {
Ok(output) => S::from_f64(output),
Err(_) => S::from_f64(f64::NAN),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

here and in other places, why are we swallowing error and simply returning NAN?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ScalarFn::eval can't return PyErr, so NaN was used as a sentinel for multicalc's non-finite checks. That dropped the original Python exception. We now stash the first callback error and re-raise it at the pyfunction boundary via .finish().

use crate::convert::{matrix_from_rows, matrix_to_rows, vector_from_list, vector_to_list};
use crate::errors;

macro_rules! bind_vector {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

add a getter function so users can inspect contents of the vector. Similar to to_list of the sqaure matrix defined below

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added to_list() on all vector types, matching the matrix API — returns a plain list[float] of components.

Comment thread crates/multicalc-py/src/estimation.rs Outdated

/// Weight particles with `measurement_model` (two state components to a 2-vector prediction) and a 2-vector measurement.
fn update(&mut self, measurement_model: Py<PyAny>, measurement: Vec<f64>) -> PyResult<()> {
let likelihood = GaussianLikelihood::<2>::new(Matrix::<2, 2>::identity())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

why identity?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch — identity() was a placeholder, not an intentional default. GaussianLikelihood needs the measurement-noise covariance, so I added measurement_noise to ParticleFilter2x2.new and use that in update instead.

Comment thread crates/multicalc-py/src/kinematics.rs Outdated
})
}

fn len(&self) -> usize {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

len so we can do len(tree). Here and in other places. Same for repr and version everywhere applicable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Switched len() to len so len(tree) works. Added len and repr on other sized/value types (vectors, matrices, polynomials, paths, scan geometry), and exposed version on the module alongside version().

@rtmongold
rtmongold force-pushed the add-multicalc-py-bindings branch 2 times, most recently from 08275b8 to c552b85 Compare August 31, 2026 11:00
Expose a slice of crate-root multicalc over PyO3/maturin as import
multicalc_py. Host f64 only; const-generic sizes are fixed in the type
name. Workspace-internal (publish = false), with pytest coverage and
crate/type docs.
@rtmongold
rtmongold force-pushed the add-multicalc-py-bindings branch from c552b85 to a07e94b Compare August 31, 2026 11:06
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.

Add Python bindings

2 participants