Skip to content

Move normal and generalized ufunc code generation differences from ufunc.c template to erfa_generator#283

Merged
avalentino merged 2 commits into
liberfa:mainfrom
eerovaher:abstract-Function
Jul 1, 2026
Merged

Move normal and generalized ufunc code generation differences from ufunc.c template to erfa_generator#283
avalentino merged 2 commits into
liberfa:mainfrom
eerovaher:abstract-Function

Conversation

@eerovaher

Copy link
Copy Markdown
Contributor

Some ERFA function wrappers are normal ufuncs, others are generalized ufuncs. On current main the erfa/ufunc.c template has to repeatedly check a function's signature property to decide which of the two cases it is dealing with and what the generated code should be. This PR introduces the UFunc and GUFunc classes to erfa_generator.py, which are both subclasses of Function (which is now abstract). The new Function.from_c_code() class method determines whether an ERFA function should be wrapped by a normal or a generalized ufunc and returns a UFunc or a GUFunc instance accordingly. The template now never has to check which case it is dealing with, it can call the same properties either way. Overall this simplifies the template's implementation at the cost of making erfa_generator.py more complicated, but that is a good tradeoff because Python code can be checked with tools such as Ruff or Mypy and there is better IDE support.

There are no differences in the code erfa_generator produces.

eerovaher added 2 commits July 1, 2026 21:30
It is better to move code from templates to `erfa_generator.py` because
Python code can be checked with tools such as Ruff or Mypy and Python
has better IDE support.
Some ERFA functions get wrapped by a normal ufunc, others by a
generalized ufunc. So far the different code generation for the two
cases has been implemented in the `erfa/ufunc.c` template, but now there
are separate `UFunc` and `GUFunc` classes in `erfa_generator.py` that
are both subclasses of `Function` (which is now abstract). Overall this
means complexity is moved from the template to `erfa_generator.py`,
which is preferable because Python code can be checked with tools such
as Ruff or Mypy and there is better IDE support.
@avalentino avalentino merged commit 50ca0e8 into liberfa:main Jul 1, 2026
27 checks passed
@eerovaher eerovaher deleted the abstract-Function branch July 2, 2026 20:06
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