Skip to content

Modernize Numba lecture#512

Merged
mmcky merged 2 commits into
mainfrom
numba_edits
Apr 8, 2026
Merged

Modernize Numba lecture#512
mmcky merged 2 commits into
mainfrom
numba_edits

Conversation

@jstac

@jstac jstac commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

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

jstac commented Apr 4, 2026

Copy link
Copy Markdown
Contributor Author

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

jstac commented Apr 4, 2026

Copy link
Copy Markdown
Contributor Author

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

@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request April 4, 2026 23:29 Inactive
@mmcky

mmcky commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Reviewed — looks good overall. Pushed a small fix for two minor issues:

  • Grammar: Added missing 'which' in the overview ('we discussed vectorization, which can improve...')
  • Capitalization: 'Matlab' → 'MATLAB' (official name)

The rest of the changes are solid modernization. LGTM to merge.

@mmcky mmcky self-requested a review April 8, 2026 08:05
@github-actions github-actions Bot temporarily deployed to pull request April 8, 2026 08:14 Inactive
@mmcky

mmcky commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

thanks @jstac this is looking great - just minor tweaks. Merging now.

@mmcky mmcky merged commit ab53ebc into main Apr 8, 2026
5 checks passed
@mmcky mmcky deleted the numba_edits branch April 8, 2026 08:15
@mmcky

mmcky commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

✅ Translation sync completed (zh-cn)

Target repo: QuantEcon/lecture-python-programming.zh-cn
Translation PR: QuantEcon/lecture-python-programming.zh-cn#17
Files synced (1):

  • lectures/numba.md

@mmcky

mmcky commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

\translate-resync fa

@mmcky

mmcky commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

\translate-resync fa

@mmcky

mmcky commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

✅ Translation sync completed (fa)

Target repo: QuantEcon/lecture-python-programming.fa
Translation PR: QuantEcon/lecture-python-programming.fa#91
Files synced (1):

  • lectures/numba.md

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.

2 participants