Skip to content

Commit

Permalink
MAINT: Use np.interp as supported by numba
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcky committed Mar 4, 2024
1 parent 0fc5009 commit 73cf999
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lectures/cake_eating_numerical.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In addition to what's in Anaconda, this lecture will need the following librarie
```{code-cell} ipython3
:tags: [hide-output]
!pip install interpolation quantecon
!pip install quantecon
```

We will use the following imports.
Expand Down Expand Up @@ -324,7 +324,6 @@ for the purpose of comparing the results of JAX implementation.
```{code-cell} ipython3
import numpy as np
from numba import prange, njit
from interpolation import interp
from quantecon.optimize import brent_max
```

Expand Down Expand Up @@ -360,7 +359,7 @@ def state_action_value_numba(c, x, v_array, cem):
* v_array: value function array guess, 1-D array
* cem: Cake Eating Numba Model instance
"""
return u_numba(c, cem) + cem.β * interp(cem.x_grid, v_array, x - c)
return u_numba(c, cem) + cem.β * np.interp(x - c, cem.x_grid, v_array)
```

```{code-cell} ipython3
Expand Down
5 changes: 2 additions & 3 deletions lectures/ifp_egm.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ We will use the following libraries and imports.
```{code-cell} ipython3
:tags: [hide-output]
!pip install --upgrade quantecon interpolation
!pip install --upgrade quantecon
```

```{code-cell} ipython3
Expand All @@ -43,7 +43,6 @@ import numpy as np
import jax
import jax.numpy as jnp
from interpolation import interp
from numba import njit, float64
from numba.experimental import jitclass
```
Expand Down Expand Up @@ -483,7 +482,7 @@ def K_egm_nb(a_in, σ_in, ifp):
# Linear interpolation of policy using endogenous grid
def σ(a, z):
return interp(a_in[:, z], σ_in[:, z], a)
return np.interp(a, a_in[:, z], σ_in[:, z])
# Allocate memory for new consumption array
σ_out = np.zeros_like(σ_in)
Expand Down

0 comments on commit 73cf999

Please sign in to comment.