Skip to content

Speed up functions that can emit a warning or raise an error#248

Merged
avalentino merged 1 commit into
liberfa:mainfrom
eerovaher:faster-check_errwarn
May 14, 2026
Merged

Speed up functions that can emit a warning or raise an error#248
avalentino merged 1 commit into
liberfa:mainfrom
eerovaher:faster-check_errwarn

Conversation

@eerovaher
Copy link
Copy Markdown
Contributor

This PR speeds up all the functions in core.py for which the corresponding ufunc returns a status code that is checked by check_errwarn(). The speedup is easily noticeable for scalars and small arrays. For example, on current main

$ cat timing_setup.py 
import numpy as np

from erfa import cal2jd


scalar_year = 2026
scalar_month = 6
scalar_day = 20

arr_year = np.full((1000,), 2026)
arr_month = np.full((1000,), 6)
arr_day = np.full((1000,), 20)
$ ipython -i timing_setup.py 
Python 3.11.12 (main, May 17 2025, 13:48:36) [Clang 20.1.4 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.13.0 -- An enhanced Interactive Python. Type '?' for help.
Tip: You can find how to type a LaTeX symbol by back-completing it, eg `\θ<tab>` will expand to `\theta`.

In [1]: %timeit cal2jd(scalar_year, scalar_month, scalar_day)
4.21 μs ± 19.3 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

In [2]: %timeit cal2jd(arr_year, arr_month, arr_day)
8.79 μs ± 28.2 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

but with this PR

In [1]: %timeit cal2jd(scalar_year, scalar_month, scalar_day)
2.88 μs ± 1.4 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

In [2]: %timeit cal2jd(arr_year, arr_month, arr_day)
7.74 μs ± 15.8 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

This speeds up all the functions in `core.py` for which the
corresponding ufunc returns a status code, i.e. the functions that can
emit a warning or raise an error.
@avalentino avalentino merged commit 5e5f676 into liberfa:main May 14, 2026
28 checks passed
@eerovaher eerovaher deleted the faster-check_errwarn branch May 14, 2026 12:05
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