Skip to content

Modernize Numba lecture#512

Open
jstac wants to merge 1 commit intomainfrom
numba_edits
Open

Modernize Numba lecture#512
jstac wants to merge 1 commit intomainfrom
numba_edits

Conversation

@jstac
Copy link
Copy Markdown
Contributor

@jstac jstac commented Apr 4, 2026

Summary

  • Modernize and clean up the Numba lecture
  • Fix deprecated patterns and improve clarity

Test plan

  • Converted to Python via jupytext and executed successfully

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jstac
Copy link
Copy Markdown
Contributor Author

jstac commented Apr 4, 2026

Detailed list of changes

  1. Added nopython mode note — Inserted a {note} directive in the Type Inference section explaining that @jit now defaults to nopython=True (since Numba 0.59), that @njit is an equivalent alias, and that the old silent "object mode" fallback no longer applies.

  2. Replaced deprecated numpy.random.randn imports — Removed from numpy.random import randn and replaced bare randn() calls with np.random.randn() in the wealth simulation (h()) and the option pricing exercise (compute_call_price_parallel()).

  3. Replaced from random import uniform — Removed the from random import uniform import (which is fragile inside jitted code) and replaced uniform(0, 1) calls with np.random.uniform(0, 1) in both the serial and parallel calculate_pi exercises.

  4. Fixed bootstrap example parameter bug — The bootstrap() function used n_resamples from global scope and shadowed its own n parameter with n = len(data). Renamed the parameter from n to n_resamples so the example fails only for the intended reason (unjitted mean function).

  5. Replaced deprecated np.int_ — Changed dtype=np.int_ to dtype=np.int64 in the Markov chain exercise (both the hint text and the code). np.int_ is a deprecated NumPy type alias.

  6. Added "Caching Compiled Code" subsection — New short section under "Dangers and Limitations" demonstrating @jit(cache=True) to persist compiled code across sessions.

  7. Replaced np.maximum with max on scalar — In the option pricing exercise, np.maximum(np.exp(s) - K, 0) was operating on scalars; replaced with the simpler max(np.exp(s) - K, 0).

  8. Standardized @jit usage — Replaced @njit with @jit throughout for consistency, since the lecture now explains they are equivalent.

  9. Prose cleanup — Streamlined the Overview section, removed the "Compiling Classes" section (jitclass/experimental), and tightened various explanatory paragraphs.

@jstac
Copy link
Copy Markdown
Contributor Author

jstac commented Apr 4, 2026

@mmcky please review and merge when ready. no need to publish yet

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant