Skip to content

Add runtime array validation - #83

Merged
charlesbmi merged 3 commits into
mainfrom
runtime-array-validation
Oct 16, 2026
Merged

charlesbmi merged 3 commits into
mainfrom
runtime-array-validation

Conversation

@charlesbmi

Copy link
Copy Markdown
Collaborator

Summary

  • enforce jaxtyping array shape and dtype annotations with beartype on public wavefront, geometry, and PyMUST helper APIs
  • make beartype a runtime dependency while keeping the beamforming performance path undecorated
  • add regressions for malformed fixed axes and mismatched named dimensions

Tests

  • make check
  • 164 passed, 2 skipped

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Runtime checking unintentionally rejects integer values for parameters typed as floating-point numbers.

2 open findings
What changed in this PR

Adds runtime beartype enforcement for public array-oriented APIs.

Changes:

  • Decorates wavefront, geometry, and PyMUST helpers with jaxtyping validation.
  • Adds malformed-shape and type regression tests.
  • Promotes beartype to a runtime dependency.
File Description
src/​mach/​wavefront.py Enables runtime validation for wavefront APIs.
src/​mach/​geometry.py Enables validation for coordinate conversions.
src/​mach/​io/​must.py Validates PyMUST helper inputs and outputs.
tests/​test_wavefront.py Tests invalid wavefront dimensions.
tests/​test_geometry.py Tests mismatched angle dimensions.
tests/​io/​test_must.py Tests invalid PyMUST helper inputs.
pyproject.toml Promotes beartype to runtime dependencies.
uv.lock Updates locked dependency groups.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mach/io/must.py Resolved
Comment thread src/mach/wavefront.py Resolved
@charlesbmi
charlesbmi requested a balanced review from Copilot October 16, 2026 04:35
@charlesbmi
charlesbmi merged commit 8894014 into main Oct 16, 2026
4 checks passed
@charlesbmi
charlesbmi deleted the runtime-array-validation branch October 16, 2026 04:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Single-point NumPy calls regress, integer pitches fail, and the promised PyMUST runtime validation remains missing.

2 open findings
2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Preserve Array protocol for single-point plane and spherical calls

src/​mach/​wavefront.py:25

The new return checks reject valid single-point NumPy calls to both plane and spherical (without aperture bounds). When points_m.shape == (3,), xp.vecdot and _spherical_distance return NumPy scalars, which lack methods required by the Array protocol, including __dlpack_device__. The decorators therefore raise TypeCheckError after computing valid distances. Wrap plane's return value and _spherical_distance's final expression with xp.asarray, and add NumPy single-point regressions for both APIs; the array-api-strict tests miss these cases.

🧠 Review effort: Balanced

Comment thread src/mach/io/must.py
def linear_probe_positions(n_elements: int, pitch: float) -> Float[np.ndarray, "{n_elements} xyz=3"]:
def linear_probe_positions(
n_elements: int,
pitch: float | int,
Comment thread src/mach/io/must.py
Comment on lines +71 to +74
def linear_probe_positions(
n_elements: int,
pitch: float | int,
) -> Float[np.ndarray, "{n_elements} xyz=3"]:
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.

2 participants