Skip to content

Commit fdc0824

Browse files
authored
Merge branch 'main' into ci-warnings-action
2 parents b76a005 + cf28a4c commit fdc0824

17 files changed

+91
-79
lines changed

.github/workflows/cache.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
cache:
99
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=quantecon_ubuntu2404/disk=large"
1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v5
1212
with:
1313
ref: ${{ github.event.pull_request.head.sha }}
1414
- name: Setup Anaconda

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
issues: write
1010
pull-requests: write
1111
steps:
12-
- uses: actions/checkout@v4
12+
- uses: actions/checkout@v5
1313
with:
1414
ref: ${{ github.event.pull_request.head.sha }}
1515
- name: Setup Anaconda

.github/workflows/collab.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
image: docker://us-docker.pkg.dev/colab-images/public/runtime:latest
88
options: --gpus all
99
steps:
10-
- uses: actions/checkout@v4
10+
- uses: actions/checkout@v5
1111
with:
1212
ref: ${{ github.event.pull_request.head.sha }}
1313
# Install build software

.github/workflows/linkcheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
# Checkout the live site (html)
1515
- name: Checkout
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v5
1717
with:
1818
ref: gh-pages
1919
- name: Link Checker

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=quantecon_ubuntu2404/disk=large"
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@v4
12+
uses: actions/checkout@v5
1313
- name: Setup Anaconda
1414
uses: conda-incubator/setup-miniconda@v3
1515
with:

lectures/career.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ class CareerWorkerProblem:
206206
207207
self.F_probs = BetaBinomial(grid_size - 1, F_a, F_b).pdf()
208208
self.G_probs = BetaBinomial(grid_size - 1, G_a, G_b).pdf()
209-
self.F_mean = np.sum(self.θ * self.F_probs)
210-
self.G_mean = np.sum(self.ϵ * self.G_probs)
209+
self.F_mean = self.θ @ self.F_probs
210+
self.G_mean = self.ϵ @ self.G_probs
211211
212212
# Store these parameters for str and repr methods
213213
self._F_a, self._F_b = F_a, F_b

lectures/kalman.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,10 @@ e2 = np.empty(T-1)
783783
784784
for t in range(1, T):
785785
kn.update(y[:,t])
786-
e1[t-1] = np.sum((x[:, t] - kn.x_hat.flatten())**2)
787-
e2[t-1] = np.sum((x[:, t] - A @ x[:, t-1])**2)
786+
diff1 = x[:, t] - kn.x_hat.flatten()
787+
diff2 = x[:, t] - A @ x[:, t-1]
788+
e1[t-1] = diff1 @ diff1
789+
e2[t-1] = diff2 @ diff2
788790
789791
fig, ax = plt.subplots(figsize=(9,6))
790792
ax.plot(range(1, T), e1, 'k-', lw=2, alpha=0.6,

lectures/lagrangian_lqdp.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,29 +206,29 @@ It is useful to proceed with the following steps:
206206
* arrange the resulting equation and the second equation of {eq}`lag-lqdp-eq2` into the form
207207
208208
$$
209-
L\ \begin{pmatrix}x_{t+1}\cr \mu_{t+1}\cr\end{pmatrix}\ = \ N\ \begin{pmatrix}x_t\cr \mu_t\cr\end{pmatrix}\
209+
L\ \begin{bmatrix}x_{t+1}\cr \mu_{t+1}\cr\end{bmatrix}\ = \ N\ \begin{bmatrix}x_t\cr \mu_t\cr\end{bmatrix}\
210210
,\ t \geq 0,
211211
$$ (eq:systosolve)
212212
213213
where
214214
215215
$$
216-
L = \ \begin{pmatrix}I & BQ^{-1} B^\prime \cr 0 & A^\prime\cr\end{pmatrix}, \quad N = \
217-
\begin{pmatrix}A & 0\cr -R & I\cr\end{pmatrix}.
216+
L = \ \begin{bmatrix}I & BQ^{-1} B^\prime \cr 0 & A^\prime\cr\end{bmatrix}, \quad N = \
217+
\begin{bmatrix}A & 0\cr -R & I\cr\end{bmatrix}.
218218
$$
219219
220220
When $L$ is of full rank (i.e., when $A$ is of full rank), we can write
221221
system {eq}`eq:systosolve` as
222222
223223
$$
224-
\begin{pmatrix}x_{t+1}\cr \mu_{t+1}\cr\end{pmatrix}\ = M\ \begin{pmatrix}x_t\cr\mu_t\cr\end{pmatrix}
224+
\begin{bmatrix}x_{t+1}\cr \mu_{t+1}\cr\end{bmatrix}\ = M\ \begin{bmatrix}x_t\cr\mu_t\cr\end{bmatrix}
225225
$$ (eq4orig)
226226
227227
where
228228
229229
$$
230-
M\equiv L^{-1} N = \begin{pmatrix}A+B Q^{-1} B^\prime A^{\prime-1}R &
231-
-B Q^{-1} B^\prime A^{\prime-1}\cr -A^{\prime -1} R & A^{\prime -1}\cr\end{pmatrix}.
230+
M\equiv L^{-1} N = \begin{bmatrix}A+B Q^{-1} B^\prime A^{\prime-1}R &
231+
-B Q^{-1} B^\prime A^{\prime-1}\cr -A^{\prime -1} R & A^{\prime -1}\cr\end{bmatrix}.
232232
$$ (Mdefn)
233233
234234
+++
@@ -262,7 +262,7 @@ To proceed, we study properties of the $(2n \times 2n)$ matrix $M$ defined in {e
262262
It helps to introduce a $(2n \times 2n)$ matrix
263263
264264
$$
265-
J = \begin{pmatrix}0 & -I_n\cr I_n & 0\cr\end{pmatrix}.
265+
J = \begin{bmatrix}0 & -I_n\cr I_n & 0\cr\end{bmatrix}.
266266
$$
267267
268268
The rank of $J$ is $2n$.
@@ -308,12 +308,12 @@ $$
308308
y_{t+1} = M y_t
309309
$$ (eq658)
310310
311-
where $y_t = \begin{pmatrix}x_t\cr \mu_t\cr\end{pmatrix}$.
311+
where $y_t = \begin{bmatrix}x_t\cr \mu_t\cr\end{bmatrix}$.
312312
313313
Consider a **triangularization** of $M$
314314
315315
$$
316-
V^{-1} M V= \begin{pmatrix}W_{11} & W_{12} \cr 0 & W_{22}\cr\end{pmatrix}
316+
V^{-1} M V= \begin{bmatrix}W_{11} & W_{12} \cr 0 & W_{22}\cr\end{bmatrix}
317317
$$ (eqn:triangledecomp)
318318
319319
where
@@ -353,9 +353,9 @@ and where $W^t_{ii}$ is $W_{ii}$ raised to the $t$th power.
353353
Write equation {eq}`eq6510` as
354354
355355
$$
356-
\begin{pmatrix}y^\ast_{1t}\cr y^\ast_{2t}\cr\end{pmatrix}\ =\ \left[\begin{matrix} W^t_{11} &
357-
W_{12, t}\cr 0 & W^t_{22}\cr\end{matrix}\right]\quad \begin{pmatrix}y^\ast_{10}\cr
358-
y^\ast_{20}\cr\end{pmatrix}
356+
\begin{bmatrix}y^\ast_{1t}\cr y^\ast_{2t}\cr\end{bmatrix}\ =\ \left[\begin{matrix} W^t_{11} &
357+
W_{12, t}\cr 0 & W^t_{22}\cr\end{matrix}\right]\quad \begin{bmatrix}y^\ast_{10}\cr
358+
y^\ast_{20}\cr\end{bmatrix}
359359
$$
360360
361361
where $y^\ast_t = V^{-1} y_t$, and in particular where
@@ -394,7 +394,7 @@ But notice that because $(V^{21}\ V^{22})$ is the second row block of
394394
the inverse of $V,$ it follows that
395395
396396
$$
397-
(V^{21} \ V^{22})\quad \begin{pmatrix}V_{11}\cr V_{21}\cr\end{pmatrix} = 0
397+
(V^{21} \ V^{22})\quad \begin{bmatrix}V_{11}\cr V_{21}\cr\end{bmatrix} = 0
398398
$$
399399
400400
which implies

lectures/lake_model.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ $$
155155
X_{t+1} = A X_t
156156
\quad \text{where} \quad
157157
A :=
158-
\begin{pmatrix}
158+
\begin{bmatrix}
159159
(1-d)(1-\lambda) + b & (1-d)\alpha + b \\
160160
(1-d)\lambda & (1-d)(1-\alpha)
161-
\end{pmatrix}
161+
\end{bmatrix}
162162
$$
163163

164164
This law tells us how total employment and unemployment evolve over time.
@@ -170,16 +170,16 @@ Now let's derive the law of motion for rates.
170170
To get these we can divide both sides of $X_{t+1} = A X_t$ by $N_{t+1}$ to get
171171

172172
$$
173-
\begin{pmatrix}
173+
\begin{bmatrix}
174174
U_{t+1}/N_{t+1} \\
175175
E_{t+1}/N_{t+1}
176-
\end{pmatrix} =
176+
\end{bmatrix} =
177177
\frac1{1+g} A
178-
\begin{pmatrix}
178+
\begin{bmatrix}
179179
U_{t}/N_{t}
180180
\\
181181
E_{t}/N_{t}
182-
\end{pmatrix}
182+
\end{bmatrix}
183183
$$
184184

185185
Letting
@@ -699,7 +699,7 @@ def _update_bellman(α, β, γ, c, σ, w_vec, p_vec, V, V_new, U):
699699
V_new[w_idx] = u(w, σ) + β * ((1 - α) * V[w_idx] + α * U)
700700
701701
U_new = u(c, σ) + β * (1 - γ) * U + \
702-
β * γ * np.sum(np.maximum(U, V) * p_vec)
702+
β * γ * (np.maximum(U, V) @ p_vec)
703703
704704
return U_new
705705
@@ -836,8 +836,8 @@ def compute_steady_state_quantities(c, τ):
836836
u, e = x
837837
838838
# Compute steady state welfare
839-
w = np.sum(V * p_vec * (w_vec - τ > w_bar)) / np.sum(p_vec * (w_vec -
840-
τ > w_bar))
839+
mask = (w_vec - τ > w_bar)
840+
w = ((V * p_vec * mask) @ np.ones_like(p_vec)) / ((p_vec * mask) @ np.ones_like(p_vec))
841841
welfare = e * w + u * U
842842
843843
return e, u, welfare

lectures/linear_algebra.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,25 @@ Continuing on from the previous example, the inner product and norm can be compu
246246
follows
247247

248248
```{code-cell} python3
249-
np.sum(x * y) # Inner product of x and y
249+
np.sum(x * y) # Inner product of x and y, method 1
250250
```
251251

252+
```{code-cell} python3
253+
x @ y # Inner product of x and y, method 2 (preferred)
254+
```
255+
256+
The `@` operator is preferred because it uses optimized BLAS libraries that implement fused multiply-add operations, providing better performance and numerical accuracy compared to the separate multiply and sum operations.
257+
252258
```{code-cell} python3
253259
np.sqrt(np.sum(x**2)) # Norm of x, take one
254260
```
255261

256262
```{code-cell} python3
257-
np.linalg.norm(x) # Norm of x, take two
263+
np.sqrt(x @ x) # Norm of x, take two (preferred)
264+
```
265+
266+
```{code-cell} python3
267+
np.linalg.norm(x) # Norm of x, take three
258268
```
259269

260270
### Span

0 commit comments

Comments
 (0)