Skip to content

test+fix: direct tests for e2h/h2e, h2e rejects <2 rows, document contract - #240

Open
petercorke wants to merge 2 commits into
rai-opensource:masterfrom
petercorke:test/homogeneous-conversions
Open

petercorke wants to merge 2 commits into
rai-opensource:masterfrom
petercorke:test/homogeneous-conversions

Conversation

@petercorke

@petercorke petercorke commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

e2h and h2e had a single assertion each (N-vector input only). The matrix path and h2e's per-column scaling were only exercised indirectly through the pose tests, and the shape contract for 2D input was undocumented.

Tests (tests/base/test_transformsNd.py)

  • vector input as list, tuple, 1D array and column vector
  • matrix input for both functions
  • h2e scaling by each column's own last element
  • h2e(e2h(x)) and e2h(h2e(x)) round trips
  • ValueError for bad types
  • a characterization test pinning that a (1,N) array is a matrix of N 1-vectors, not a row vector. This documents current behavior rather than endorsing it, so any change to it is deliberate.

Behavior change (small)

  • h2e now raises ValueError for input with fewer than two rows (a (1,N) array, a length-1 vector, or a scalar). Previously it returned an empty (0,N) array, which is never useful: a homogeneous point has at least two elements. Checked callers in MVTB (Camera.py, ImageReshape.py); both pass 3-row arrays.
  • e2h is unchanged.

Docstrings (spatialmath/base/transformsNd.py)

  • Both functions state the contract up front: each column is a point, rows are never points, with explicit shapes and a note on how to convert a row vector (pass its transpose).
  • :raises: entries added; e2h's :seealso: pointed at itself, now h2e.

Rank-0 and rank-3 rejection is covered by #239 (isvector) and is deliberately not duplicated here; this PR is independent of it.

Full suite: 355 passed, 3 skipped.

🤖 Generated with Claude Code

e2h/h2e had one assertion each (N-vector only), with the matrix path and
h2e scaling only exercised indirectly via the pose tests. Add tests for
vector input types, matrix input, per-column scaling, round trips, bad
types, and pin the current (1,N)-is-a-matrix interpretation.

Docstrings: e2h's :seealso: pointed at itself (now h2e); document the
(1,N) interpretation in both.

No behavior change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

h2e of a (1,N) array, a length-1 vector or a scalar returned an empty
(0,N) array, which is never useful (a homogeneous point has at least two
elements). Raise ValueError instead.

Docstrings for e2h and h2e now state the contract up front: columns are
points, rows never are, with explicit shapes, the (1,N) consequence and
:raises: entries.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke petercorke changed the title test: add direct tests for e2h/h2e; fix docstring seealso test+fix: direct tests for e2h/h2e, h2e rejects <2 rows, document contract Oct 10, 2026
@taughz taughz mentioned this pull request Oct 11, 2026
19 tasks

This branch has not been deployed

No deployments
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