DM-53569: Add Region to IVOA STC-S conversion#106
Merged
Conversation
2 tasks
Codecov Report❌ Patch coverage is 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. |
They are now longer necessary and this was a small patch to sphgeom so they do not give much additional context.
This was useful in showing that only the polygon version needed to be in C++.
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
approved these changes
May 28, 2026
andy-slac
left a comment
Contributor
There was a problem hiding this comment.
Looks good, a couple of minor comments.
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]>
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. |
Contributor
|
@timj, yes, I'll check it. |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
doc/changes