Skip to content

Commit 9edc59f

Browse files
jstacclaude
andcommitted
Improve lecture flow and reorganize content
This commit includes pedagogical improvements across three lectures: **numba.md:** - Improve sentence flow with better transitions - Change Wikipedia multithreading link to internal reference - Add "(multithreading)=" label to Multithreaded Loops section - Remove "Numba will be a key part of our lectures..." sentence - Add transition phrase "Beyond speed gains from compilation" - Clarify NumPy arrays "which have well-defined types" - Change "For example" to "Notably" for better flow - Add "Conversely" transition for prange vs range comparison **numpy.md:** - Add "### Basics" subheading for better organization - Emphasize "flat" array concept with bold formatting - Improve shape attribute explanation with inline comments - Remove np.asarray vs np.array comparison examples - Remove np.genfromtxt reference, keep only np.loadtxt - Remove redundant note about zero-based indices - Improve searchsorted() description formatting - Remove redundant NumPy function examples (np.sum, np.mean) - Simplify matrix multiplication section (remove old Python version notes) - Simplify @ operator examples, remove redundant demonstrations - Remove manual for-loop equivalent of broadcasting - Remove higher-dimensional broadcasting code examples - Remove higher-dimensional ValueError example - Add "### Mutability" subheading and improve organization - Change "Vectorized Functions" to "Universal Functions" heading - Emphasize terminology with bold: **vectorized functions**, **ufuncs**, **universal functions** - Add note about JAX's np.vectorize - Remove "Speed Comparisons" section (moved to numpy_vs_numba_vs_jax.md) - Remove "Implicit Multithreading in NumPy" section (moved to numpy_vs_numba_vs_jax.md) **numpy_vs_numba_vs_jax.md:** - Change title from "Parallelization" to "NumPy vs Numba vs JAX" - Add jax to pip install command - Add missing imports: random, mpl_toolkits.mplot3d, matplotlib.cm - Add "### Speed Comparisons" section (moved from numpy.md) - Add "### Vectorization vs Loops" section (moved from numpy.md) - Add "### Universal Functions" section (moved from numpy.md) - Add "### Implicit Multithreading in NumPy" section (moved from numpy.md) - Change "some examples" to "an example" in multithreading description 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2d0c0e3 commit 9edc59f

File tree

3 files changed

+224
-313
lines changed

3 files changed

+224
-313
lines changed

lectures/numba.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ The key idea is to compile functions to native machine code instructions on the
6767

6868
When it succeeds, the compiled code is extremely fast.
6969

70-
Numba is specifically designed for numerical work and can also do other tricks such as [multithreading](https://en.wikipedia.org/wiki/Multithreading_%28computer_architecture%29).
71-
72-
Numba will be a key part of our lectures --- especially those lectures involving dynamic programming.
70+
Beyond speed gains from compilation, Numba is specifically designed for numerical work and can also do other tricks such as {ref}`multithreading`.
7371

7472
This lecture introduces the main ideas.
7573

@@ -244,7 +242,7 @@ Successful type inference is a key part of JIT compilation.
244242

245243
As you can imagine, inferring types is easier for simple Python objects (e.g., simple scalar data types such as floats and integers).
246244

247-
Numba also plays well with NumPy arrays.
245+
Numba also plays well with NumPy arrays, which have well-defined types.
248246

249247
In an ideal setting, Numba can infer all necessary type information.
250248

@@ -297,7 +295,7 @@ As mentioned above, at present Numba can only compile a subset of Python.
297295

298296
However, that subset is ever expanding.
299297

300-
For example, Numba is now quite effective at compiling classes.
298+
Notably, Numba is now quite effective at compiling classes.
301299

302300
If a class is successfully compiled, then its methods act as JIT-compiled
303301
functions.
@@ -447,6 +445,7 @@ function.
447445

448446
When Numba compiles machine code for functions, it treats global variables as constants to ensure type stability.
449447

448+
(multithreading)=
450449
## Multithreaded Loops in Numba
451450

452451
In addition to JIT compilation, Numba provides powerful support for parallel computing on CPUs.
@@ -603,7 +602,7 @@ independence fails, and this is why we use ordinary `range` instead of `prange`.
603602
When you see us using `prange` in later lectures, it is because the
604603
independence of tasks holds true.
605604

606-
When you see us using ordinary `range` in a jitted function, it is either because the speed gain from parallelization is small or because independence fails.
605+
Conversely, when you see us using ordinary `range` in a jitted function, it is either because the speed gain from parallelization is small or because independence fails.
607606

608607
## Exercises
609608

0 commit comments

Comments
 (0)