Skip to content

Commit

Permalink
create_exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
shlff committed Mar 13, 2024
1 parent d409e13 commit 94779d0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lectures/inventory_dynamics.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,21 @@ key = random.PRNGKey(27)
print(f"Frequency of at least two stock outs = {freq}")
```

### Alternative implementation with `lax.fori_loop`
```{exercise-start}
:label: inventory_dynamics_ex1
```

Write a `fori_loop` version of the last function. See if you can increase the
speed while generating a similar answer.

```{exercise-end}
```

Now let's write a `lax.fori_loop` version that JIT compiles the whole function
```{solution-start} inventory_dynamics_ex1
:class: dropdown
```

Here is a `lax.fori_loop` version that JIT compiles the whole function

```{code-cell} ipython3
@jax.jit
Expand Down Expand Up @@ -508,6 +520,5 @@ Note the time the routine takes to run, as well as the output
print(f"Frequency of at least two stock outs = {freq}")
```

```{code-cell} ipython3
```{solution-end}
```

0 comments on commit 94779d0

Please sign in to comment.