-
-
Notifications
You must be signed in to change notification settings - Fork 45
Use np.interp instead of interpolation.interp #387
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
Conversation
Many thanks @kp992 . @mmcky or @HumphreyYang , could you please do a first round review of this? The aim is that swapping to NumPy's interp should not change outputs or degrade performance. |
Note that this is related to QuantEcon/lecture-python-advanced.myst#156 |
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 @kp992 I confirm the np.interp
has been updated nicely and the function arguments have been switched successfully.
@jstac re: performance
Some lectures actually improved and some are a bit slower. I don't see any major timing issues. |
Remaining lectures to migrate
@kp992 can you let me know if there is an equivalent to |
@kp992 I know it violates our usual practice but let's try and fix them all in one PR -- so they are in one commit. This lecture series is not in high frequency editing at the moment so I am happy with that approach. |
from numba import njit, prange, vectorize | ||
from interpolation import mlinterp, interp | ||
from interpolation import mlinterp |
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.
@kp992 is there a corresponding function in numpy
for mlinterp
?
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.
No @mmcky, there's not.
There is in SciPy but it's not jit compilable. Let's stick to interpolation for the multivariate case.
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.
That's right, @jstac. I didn't find mlinterp
in numpy too.
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.
@kp992 we will need interpolation
package updated unless mlinterp
doesn't use generated_jit
. Would you have time to look into that?
@@ -1,5 +1,4 @@ | |||
import numpy as np | |||
from interpolation import interp |
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 didn't see pip install interpolation
removed from this lecture... was that task forgotten?
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 @jstac. I think we can remove this file completely. This isn't use anywhere in any lectures. In optgrowth
, it seems to be have been replace by from scipy.interpolate import interp1d
.
% git grep bellman_operator
lectures/_static/lecture_specific/odu/odu.py: def bellman_operator(self, v):
lectures/_static/lecture_specific/wald_friedman/wald_class.py: def bellman_operator(self, J):
lectures/_static/lecture_specific/wald_friedman/wald_class.py: J = qe.compute_fixed_point(self.bellman_operator, np.zeros(self.m),
lectures/_static/lecture_specific/wald_friedman/wf_first_pass.py:def bellman_operator(pgrid, c, f0, f1, L0, L1, J):
lectures/_static/lecture_specific/wald_friedman/wf_first_pass.py:bell_op = lambda vf: bellman_operator(pg, 0.5, f0, f1, 5.0, 5.0, vf)
thanks @jstac for searching the |
@kp992 are you happy for this to be merged? |
This PR replaces
interpolation.interp
tonp.interp
now thatnumba
supportsnp.interp
directly. Also, removesplt.rcParams["figure.figsize"] = (11, 5) #set default figure size
redundant line.