-
Notifications
You must be signed in to change notification settings - Fork 8
Lazy compilation for numba gufuncs #103
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| import numpy as np | ||
| from numba import guvectorize | ||
|
|
||
| from scoringrules.core.utils import lazy_gufunc_wrapper_mv | ||
|
|
||
|
|
||
| @guvectorize( | ||
| [ | ||
| "void(float32[:], float32[:,:], float32[:])", | ||
| "void(float64[:], float64[:,:], float64[:])", | ||
| ], | ||
| "(d),(m,d)->()", | ||
| cache=True, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't fully understand the motivation for caching the energy score gufunc but not the other gufuncs imported at import time, e.g. (fair and nrg) crps and variogram score? The weighted interval score is also cached but lazily loaded. Again, why this score and not the other scores? |
||
| ) | ||
| def _energy_score_gufunc( | ||
| obs: np.ndarray, | ||
|
|
@@ -27,13 +30,8 @@ def _energy_score_gufunc( | |
| out[0] = e_1 / M - 0.5 / (M**2) * e_2 | ||
|
|
||
|
|
||
| @guvectorize( | ||
| [ | ||
| "void(float32[:], float32[:,:], float32[:], float32[:], float32[:])", | ||
| "void(float64[:], float64[:,:], float64[:], float64[:], float64[:])", | ||
| ], | ||
| "(d),(m,d),(),(m)->()", | ||
| ) | ||
| @lazy_gufunc_wrapper_mv | ||
| @guvectorize("(d),(m,d),(),(m)->()") | ||
| def _owenergy_score_gufunc( | ||
| obs: np.ndarray, | ||
| fct: np.ndarray, | ||
|
|
@@ -43,7 +41,6 @@ def _owenergy_score_gufunc( | |
| ): | ||
| """Compute the Outcome-Weighted Energy Score for a finite ensemble.""" | ||
| M = fct.shape[0] | ||
| ow = ow[0] | ||
|
|
||
| e_1 = 0.0 | ||
| e_2 = 0.0 | ||
|
|
@@ -57,13 +54,8 @@ def _owenergy_score_gufunc( | |
| out[0] = e_1 / (M * wbar) - 0.5 * e_2 / (M**2 * wbar**2) | ||
|
|
||
|
|
||
| @guvectorize( | ||
| [ | ||
| "void(float32[:], float32[:,:], float32[:], float32[:], float32[:])", | ||
| "void(float64[:], float64[:,:], float64[:], float64[:], float64[:])", | ||
| ], | ||
| "(d),(m,d),(),(m)->()", | ||
| ) | ||
| @lazy_gufunc_wrapper_mv | ||
| @guvectorize("(d),(m,d),(),(m)->()") | ||
| def _vrenergy_score_gufunc( | ||
| obs: np.ndarray, | ||
| fct: np.ndarray, | ||
|
|
@@ -73,7 +65,6 @@ def _vrenergy_score_gufunc( | |
| ): | ||
| """Compute the Vertically Re-scaled Energy Score for a finite ensemble.""" | ||
| M = fct.shape[0] | ||
| ow = ow[0] | ||
|
|
||
| e_1 = 0.0 | ||
| e_2 = 0.0 | ||
|
|
||
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.
nrg estimator could also be lazily loaded - currently it also has the longer decorator, as if it is not lazily loaded