Move normal and generalized ufunc code generation differences from ufunc.c template to erfa_generator#283
Merged
Conversation
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
approved these changes
Jul 1, 2026
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.
Some ERFA function wrappers are normal ufuncs, others are generalized ufuncs. On current
maintheerfa/ufunc.ctemplate has to repeatedly check a function'ssignatureproperty to decide which of the two cases it is dealing with and what the generated code should be. This PR introduces theUFuncandGUFuncclasses toerfa_generator.py, which are both subclasses ofFunction(which is now abstract). The newFunction.from_c_code()class method determines whether an ERFA function should be wrapped by a normal or a generalized ufunc and returns aUFuncor aGUFuncinstance 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 makingerfa_generator.pymore 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_generatorproduces.