-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-575: bring back inv_triangle_number #577
Conversation
glass/fields.py
Outdated
@@ -51,15 +51,25 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R: | |||
return decorator | |||
|
|||
|
|||
def _is_inv_triangle_number(triangle_number: int) -> tuple[int, bool]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of this return signature. The signature minimises repetitions but I am open to any better implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just have _inv_triangle_number()
throw an exception if it's not -- both downstream functions can catch and rethrow it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I have updated the implementation.
glass/fields.py
Outdated
def nfields_from_nspectra(nspectra: int) -> int: | ||
r""" | ||
Returns the number of fields for a number of spectra. | ||
|
||
Given the number of spectra *nspectra*, returns the number of | ||
fields *n* such that ``n * (n + 1) // 2 == nspectra``. | ||
""" | ||
n = math.floor(math.sqrt(2 * nspectra)) | ||
if n * (n + 1) // 2 != nspectra: | ||
n, is_inv_triangle = _is_inv_triangle_number(nspectra) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_is_inv_triangle_number
will similarly be used in a new function (to be added in #533) which will be specific to alm
.
The docstrings are fixed now. |
Co-authored-by: Patrick J. Roddy <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting test failures now.
I have recently got numeric errors here https://github.com/astro-informatics/sleplet/actions/runs/13656527580 so I wonder if there has been a recent NumPy change or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Co-authored-by: Patrick J. Roddy <[email protected]>
Description
Add
_is_inv_triangle_number
to check for triangle numbers and use it internally innfields_from_nspectra
. The refactor might not look very useful right now, but it paves the way for adding annfields_from_nspectra
-equivalent function foralm
in #533 without repeating the core logic.Closes: #575
Checks