Skip to content

Commit 27876ed

Browse files
kp992HumphreyYangclaude
authored andcommitted
[inventory_dynamics] Update code to JAX and latest style guide
Convert the lecture from Numba (jitclass / @jit(parallel=True)) to JAX: - Replace the `Firm` jitclass with a `NamedTuple` and pure update functions. - Use `jax.lax.scan` for the inner time loop and explicit `jax.random` keys. - Vectorize the Monte Carlo draw loops with `jax.vmap` (including the 50,000-draw marginal-distribution cell, which as a Python loop over a jitted call ran ~28s on GPU; vmapped it is ~0.3s). - Use `sample.min()/.max()` in `plot_kde` instead of Python `min()/max()`, which iterate a JAX array element-by-element (~4s per call). - Fix a hidden cross-cell dependency (`sim_length - 1` -> `2 * T`). - Give the two exercise-solution helpers distinct names so they no longer shadow each other. - Minor typo, terminology, and sentence-case title fixes. Whole-lecture execution drops from ~57s to ~5s on an RTX 4080 with identical numerical output. Co-authored-by: Humphrey Yang <39026988+HumphreyYang@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fccf5a9 commit 27876ed

1 file changed

Lines changed: 240 additions & 148 deletions

File tree

0 commit comments

Comments
 (0)