Skip to content

Commit 7457bb1

Browse files
authored
use fori_loop (#114)
1 parent bfe2b34 commit 7457bb1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lectures/wealth_dynamics.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.5
7+
jupytext_version: 1.15.2
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -139,12 +139,11 @@ def gini_jax(y):
139139
n = y.shape[0]
140140
g_sum = 0
141141
142-
# Define the function for each update
143-
def sum_y_gini(g_sum, i):
142+
def sum_y_gini(i, g_sum):
144143
g_sum += jnp.sum(jnp.abs(y[i] - y))
145-
return g_sum, g_sum
146-
147-
g_sum, _ = jax.lax.scan(sum_y_gini, 0, jnp.arange(n))
144+
return g_sum
145+
146+
g_sum = jax.lax.fori_loop(0, n, sum_y_gini, 0)
148147
return g_sum / (2 * n * jnp.sum(y))
149148
```
150149

0 commit comments

Comments
 (0)