Skip to content

DM-53569: Add Region to IVOA STC-S conversion#106

Merged
timj merged 24 commits into
mainfrom
tickets/DM-53569
May 28, 2026
Merged

DM-53569: Add Region to IVOA STC-S conversion#106
timj merged 24 commits into
mainfrom
tickets/DM-53569

Conversation

@timj

@timj timj commented May 26, 2026

Copy link
Copy Markdown
Member

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.99160% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.44%. Comparing base (04536d8) to head (3a225cd).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/Ellipse.cc 57.50% 2 Missing and 15 partials ⚠️
src/CompoundRegion.cc 60.00% 0 Missing and 10 partials ⚠️
src/ConvexPolygon.cc 47.36% 1 Missing and 9 partials ⚠️
src/Circle.cc 52.94% 1 Missing and 7 partials ⚠️
include/lsst/sphgeom/Region.h 50.00% 2 Missing ⚠️
python/lsst/sphgeom/_region.cc 0.00% 0 Missing and 1 partial ⚠️
python/lsst/sphgeom/_sphgeom.cc 0.00% 0 Missing and 1 partial ⚠️
src/Box.cc 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
+ Coverage   72.22%   72.44%   +0.21%     
==========================================
  Files         114      115       +1     
  Lines        6978     7215     +237     
  Branches     2230     2289      +59     
==========================================
+ Hits         5040     5227     +187     
- Misses        398      404       +6     
- Partials     1540     1584      +44     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

timj added 2 commits May 27, 2026 13:34
They are now longer necessary and this was a small patch to sphgeom
so they do not give much additional context.
@timj
timj force-pushed the tickets/DM-53569 branch from b9a573b to eaa8544 Compare May 27, 2026 20:38
timj added 2 commits May 27, 2026 13:39
This was useful in showing that only the polygon version needed
to be in C++.
@timj
timj force-pushed the tickets/DM-53569 branch from eaa8544 to db2770e Compare May 27, 2026 20:39
The std::string const& overloads of decodeBase64 and
decodeOverlapsBase64 called themselves rather than forwarding to the
std::string_view const& overloads, since overload resolution prefers
the exact match over the string->string_view conversion. Cast to
std::string_view to force the intended overload. Apple clang 21 flags
this via -Winfinite-recursion.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@andy-slac andy-slac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, a couple of minor comments.

Comment thread python/lsst/sphgeom/_continue_class.py Outdated
Comment thread python/lsst/sphgeom/_continue_class.py Outdated
Comment thread python/lsst/sphgeom/_continue_class.py Outdated
timj and others added 2 commits May 28, 2026 10:13
Both compound regions accept an arbitrary number of operands, not just
two; update the class docstrings to match.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Add an optional ``frame`` argument to ``Region._ivoa_stcs_body`` (and
to ``ConvexPolygon::toIvoaStcsBody`` in C++) so the frame keyword is
written directly after the shape name in a single pass.  Previously
``Region.to_ivoa_stcs`` built the bare body, partitioned it, and
re-formatted with the frame inserted -- an extra O(N) string copy on
every call.  Compound regions still call ``_ivoa_stcs_body()`` with
no frame on inner operands so the keyword appears only at the
outermost level.

A throughput benchmark on a 4-vertex polygon improves from 1.59M to
2.26M ops/sec (~30%); larger polygons see smaller proportional gains
(8% at 64 vertices) since the body construction dominates.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@timj

timj commented May 28, 2026

Copy link
Copy Markdown
Member Author

@andy-slac since everything was rewritten (but is the same logic) in C++ let me know if you feel like doing a new review.

@andy-slac

Copy link
Copy Markdown
Contributor

@timj, yes, I'll check it.

@andy-slac andy-slac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good.

Comment thread include/lsst/sphgeom/Region.h Outdated
Move ``to_ivoa_stcs`` and its private body builder out of the Python
``_continue_class.py`` shim and into the C++ Region hierarchy.

- ``Region`` now defines a non-virtual public ``toIvoaStcs(frame)``
  wrapper around a ``virtual toIvoaStcsBody(frame)``; the base
  implementation throws ``IvoaStcsNotImplemented``, a new exception
  declared with default visibility so RTTI matches across the
  binding boundary on macOS.
- ``Circle``, ``Ellipse``, ``Box``, ``ConvexPolygon``, ``UnionRegion``
  and ``IntersectionRegion`` all override ``toIvoaStcsBody``.  Numbers
  are formatted with ``std::to_chars`` (shortest round-trip), matching
  what ``ConvexPolygon`` already did.  Compound regions walk
  ``getOperand(i)`` directly -- no clone and no Python iterator, which
  was the bottleneck flagged on the PR.
- ``_sphgeom.cc`` registers a pybind11 exception translator that maps
  ``IvoaStcsNotImplemented`` to the built-in ``NotImplementedError`` so
  the existing exception contract is preserved.
- The Python ``Region.to_ivoa_stcs``, ``_ivoa_stcs_body`` (every
  override), the ``_ellipse_position_angle_degrees`` helper and the
  ConvexPolygon ``_ivoa_stcs_body`` binding are removed; the private
  body method is no longer reachable from Python at all.
- The body-helper tests in ``tests/test_stcs.py`` are converted to call
  ``to_ivoa_stcs(frame="")``, which now yields the bare body via the
  public API.  ``test_intersection`` switches to a token-based check
  because ``std::to_chars`` emits ``5`` rather than ``5.0`` for
  integer-valued doubles (the value still round-trips exactly).

Microbenchmark on the same M-series host as the earlier numbers
(``bench/bench_stcs.py``, not committed):

  ConvexPolygon[  4].to_ivoa_stcs()    0.63 -> 0.39 us  (-38%)
  ConvexPolygon[ 64].to_ivoa_stcs()    6.43 -> 5.85 us  (-9%)
  ConvexPolygon[256].to_ivoa_stcs()   25.32 -> 23.75 us (-6%)
  Circle.to_ivoa_stcs()                5.72 -> 0.23 us  (-96%, ~25x)
  UnionRegion(Poly64, Poly64)         14.22 -> 11.67 us (-18%)

Circle (and by extension Ellipse / Union of cheap operands) sees by
far the largest gain because its body builder was previously pure
Python; ConvexPolygon, whose body was already in C++, gains only the
small wrapper overhead.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@timj
timj force-pushed the tickets/DM-53569 branch from 3029d1b to 3a225cd Compare May 28, 2026 18:37
@timj
timj merged commit afb225b into main May 28, 2026
28 checks passed
@timj
timj deleted the tickets/DM-53569 branch May 28, 2026 19:29
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