Skip to content

Commit 4283a22

Browse files
committed
Ch9 first draft, and lots of review changes from erik and jim.
1 parent 579769d commit 4283a22

62 files changed

Lines changed: 1300 additions & 168 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Chapter0/Scene2.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ def construct(self):
5858
self.play(*[FadeOut(highlight) for highlight in highlights])
5959

6060
matrix_and_labels = VGroup(dense_matrix, *row_labels, *col_labels)
61-
self.play(matrix_and_labels.animate.to_edge(LEFT))
61+
self.play(matrix_and_labels.animate.to_edge(LEFT, buff=1.2))
62+
63+
source_label = Text("Source", font_size=24, color=GRAY).rotate(PI / 2)
64+
source_label.next_to(matrix_and_labels, LEFT, buff=0.3)
65+
source_label.set_y(dense_matrix.get_center()[1])
66+
67+
dest_label = Text("Destination", font_size=24, color=GRAY)
68+
dest_label.next_to(matrix_and_labels, UP, buff=0.3)
69+
dest_label.set_x(dense_matrix.get_center()[0])
70+
71+
self.play(FadeIn(source_label), FadeIn(dest_label))
6272

6373
# Create the graph, shift it to the right, and raise it by 0.5 units
6474
nodes = [i for i in range(num_rows)]
@@ -98,12 +108,15 @@ def construct(self):
98108
for j in range(num_cols):
99109
if matrix_data[i][j] != 0:
100110
value = matrix_data[i][j]
101-
value_text = Tex(str(value)).move_to(dense_matrix.get_entries()[i * num_cols + j].get_center())
111+
value_text = Tex(str(value), color=WHITE)
112+
value_text.move_to(dense_matrix.get_entries()[i * num_cols + j].get_center())
113+
bg = BackgroundRectangle(value_text, color=BLACK, fill_opacity=0.8, buff=0.1, corner_radius=0.05)
114+
label = VGroup(bg, value_text)
102115
edge_center = graph.edges[(i, j)].get_center()
103116

104117
# Move the value to the graph edge with a slight delay
105-
self.play(value_text.animate.move_to(edge_center))
106-
edge_labels.add(value_text)
118+
self.play(label.animate.move_to(edge_center))
119+
edge_labels.add(label)
107120
self.wait(0.1) # Small delay for clarity
108121

109122
# Unhighlight the previous node and edges
@@ -134,6 +147,8 @@ def construct(self):
134147
FadeOut(matrix_label),
135148
FadeOut(graph_label),
136149
FadeOut(edge_labels),
150+
FadeOut(source_label),
151+
FadeOut(dest_label),
137152
run_time=1 # Smooth fade-out transition
138153
)
139154
self.wait(0.5)

Chapter0/Scene3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dotenv import load_dotenv
77
load_dotenv()
88

9-
from scene_utils import CHAPTER0_MATRIX_DATA, create_adjacency_digraph, setup_scene
9+
from scene_utils import CHAPTER0_MATRIX_DATA, create_adjacency_digraph, animate_vertex_fill, setup_scene
1010

1111

1212
class Scene3(VoiceoverScene, Scene):
@@ -137,7 +137,7 @@ def construct(self):
137137
col_highlight = SurroundingRectangle(sparse_matrix.get_rows()[3], color=YELLOW, buff=0.1)
138138
self.play(Create(col_highlight))
139139

140-
node_highlight = ApplyMethod(graph.vertices[3].set_fill, YELLOW, 1)
140+
node_highlight = animate_vertex_fill(graph.vertices[3], YELLOW, 1)
141141
outgoing_edges = [
142142
graph.edges[(3, j)].animate.set_stroke(color=YELLOW, width=4)
143143
for j in range(6) if (3, j) in graph.edges

Chapter1/Scene1.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def construct(self):
1616
title = Tex("Installing Python-GraphBLAS").scale(1.5).to_edge(UP)
1717

1818
with self.voiceover(
19-
"""Installing Python GraphBLAS is straightforward using pip.
19+
"""Installing Python GraphBLAS is straightforward using pip,
20+
or conda for those using Anaconda or Miniforge environments.
2021
The package automatically includes SuiteSparse GraphBLAS,
2122
which is a high-performance implementation of the GraphBLAS
2223
specification developed by Tim Davis at Texas A and M
@@ -28,11 +29,26 @@ def construct(self):
2829
pip_code = Code(
2930
code_string="pip install python-graphblas",
3031
language="bash",
31-
background="window"
32+
background="window",
33+
formatter_style="dracula",
3234
).scale(1.2)
3335
self.play(FadeIn(pip_code))
36+
self.wait(1)
37+
38+
# Conda install option
39+
conda_code = Code(
40+
code_string="conda install -c conda-forge python-graphblas",
41+
language="bash",
42+
background="window",
43+
formatter_style="dracula",
44+
).scale(1.2)
45+
conda_code.next_to(pip_code, DOWN, buff=0.5)
46+
self.play(FadeIn(conda_code))
3447
self.wait(2)
3548

49+
# Fade out install commands before showing alternatives
50+
self.play(FadeOut(pip_code), FadeOut(conda_code))
51+
3652
with self.voiceover(
3753
"""If Python isn't your preferred language, GraphBLAS
3854
bindings are also available for other environments. Julia
@@ -43,22 +59,21 @@ def construct(self):
4359
# Show alternatives
4460
alternatives = VGroup(
4561
Tex("Julia: ").scale(0.8),
46-
Code(code_string="using GraphBLAS", language="julia", background="window").scale(0.7),
62+
Code(code_string="using GraphBLAS", language="julia", background="window", formatter_style="dracula").scale(0.7),
4763
).arrange(RIGHT, buff=0.3)
4864

4965
postgres_alt = VGroup(
5066
Tex("PostgreSQL: ").scale(0.8),
51-
Code(code_string="CREATE EXTENSION onesparse;", language="sql", background="window").scale(0.7),
67+
Code(code_string="CREATE EXTENSION onesparse;", language="sql", background="window", formatter_style="dracula").scale(0.7),
5268
).arrange(RIGHT, buff=0.3)
5369

5470
alt_group = VGroup(alternatives, postgres_alt).arrange(DOWN, buff=0.5)
55-
alt_group.next_to(pip_code, DOWN, buff=0.8)
5671

5772
self.play(FadeIn(alternatives))
5873
self.wait(1)
5974
self.play(FadeIn(postgres_alt))
6075
self.wait(2)
6176

6277
# Cleanup
63-
self.play(FadeOut(title), FadeOut(pip_code), FadeOut(alt_group))
78+
self.play(FadeOut(title), FadeOut(alt_group))
6479
self.wait(0.5)

Chapter1/Scene2.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def construct(self):
3535
size=6
3636
)""",
3737
language="python",
38-
background="window"
38+
background="window",
39+
formatter_style="dracula",
3940
).scale(0.7)
4041
vector_code.to_edge(LEFT, buff=0.5).shift(DOWN * 0.5)
4142
self.play(FadeIn(vector_code))
@@ -78,7 +79,8 @@ def construct(self):
7879
nrows=6, ncols=6
7980
)""",
8081
language="python",
81-
background="window"
82+
background="window",
83+
formatter_style="dracula",
8284
).scale(0.65)
8385
matrix_code.to_edge(LEFT, buff=0.3).shift(DOWN * 0.5)
8486
self.play(FadeIn(matrix_code))
@@ -115,7 +117,8 @@ def construct(self):
115117
5: {4: 2}
116118
}, nrows=6, ncols=6)""",
117119
language="python",
118-
background="window"
120+
background="window",
121+
formatter_style="dracula",
119122
).scale(0.65)
120123
dict_code.to_edge(LEFT, buff=0.3).shift(DOWN * 0.5)
121124
self.play(FadeIn(dict_code))
@@ -144,7 +147,8 @@ def construct(self):
144147
edges, nrows=6, ncols=6
145148
)""",
146149
language="python",
147-
background="window"
150+
background="window",
151+
formatter_style="dracula",
148152
).scale(0.65)
149153
edgelist_code.to_edge(LEFT, buff=0.3).shift(DOWN * 0.5)
150154
self.play(FadeIn(edgelist_code))
@@ -167,7 +171,8 @@ def construct(self):
167171
A = gbio.mmread("karate.mtx")
168172
print(A) # 34x34 matrix, 78 edges""",
169173
language="python",
170-
background="window"
174+
background="window",
175+
formatter_style="dracula",
171176
).scale(0.7)
172177
mmread_code.to_edge(LEFT, buff=0.5).shift(DOWN * 0.5)
173178
self.play(FadeIn(mmread_code))

Chapter1/Scene3.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def construct(self):
9999
# Matrix-vector multiply
100100
w << A.mxv(v)""",
101101
language="python",
102-
background="window"
102+
background="window",
103+
formatter_style="dracula",
103104
).scale(0.7)
104105
code.to_edge(DOWN, buff=0.3)
105106
self.play(FadeIn(code))
@@ -124,7 +125,7 @@ def construct(self):
124125
result_entry, color=GREEN, buff=0.1
125126
)
126127

127-
self.play(Create(row_highlight), run_time=0.2)
128+
self.play(Create(row_highlight), run_time=0.5)
128129

129130
# Show which vector elements contribute
130131
contributing = []
@@ -133,27 +134,28 @@ def construct(self):
133134
mat_entry = matrix.get_entries()[i * num_cols + j]
134135
vec_entry = vector.get_entries()[j]
135136
contributing.append(
136-
SurroundingRectangle(
137-
VGroup(mat_entry, vec_entry), color=BLUE, buff=0.05
138-
)
137+
SurroundingRectangle(mat_entry, color=BLUE, buff=0.05)
138+
)
139+
contributing.append(
140+
SurroundingRectangle(vec_entry, color=BLUE, buff=0.05)
139141
)
140142

141143
if contributing:
142-
self.play(*[Create(c) for c in contributing], run_time=0.2)
144+
self.play(*[Create(c) for c in contributing], run_time=0.4)
143145
self.play(
144146
result_entry.animate.set_opacity(1),
145147
Create(result_highlight),
146-
run_time=0.3
148+
run_time=0.5
147149
)
148150
self.play(
149151
*[FadeOut(c) for c in contributing],
150152
FadeOut(result_highlight),
151-
run_time=0.2
153+
run_time=0.4
152154
)
153155
else:
154-
self.wait(0.2)
156+
self.wait(0.3)
155157

156-
self.play(FadeOut(row_highlight), run_time=0.2)
158+
self.play(FadeOut(row_highlight), run_time=0.5)
157159

158160
with self.voiceover(
159161
"""Python also supports the at-sign operator as shorthand for
@@ -163,7 +165,8 @@ def construct(self):
163165
shorthand_code = Code(
164166
code_string="# Shorthand syntax\nw << A @ v",
165167
language="python",
166-
background="window"
168+
background="window",
169+
formatter_style="dracula",
167170
).scale(0.8)
168171
shorthand_code.to_edge(DOWN, buff=0.5)
169172
self.play(FadeIn(shorthand_code))

Chapter1/Scene4.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def construct(self):
2626
num_nodes = len(matrix_data)
2727

2828
with self.voiceover(
29-
"""Breadth-first search is one of the most fundamental graph
30-
algorithms. At its core, each step of BFS finds all neighbors
31-
of the current frontier nodes, and that's exactly what
29+
"""Breadth-first search is one of the most fundamental
30+
graph algorithms. Each step of BFS finds all neighbors of
31+
the current frontier nodes, and that's exactly what
3232
matrix-vector multiplication does."""
3333
):
3434
self.play(Write(title))

Chapter1/Scene5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def construct(self):
2929
summary_bullets.next_to(title, DOWN, buff=0.5)
3030

3131
self.play(FadeIn(summary_bullets, shift=UP, lag_ratio=0.2))
32-
self.wait(2)
32+
self.wait(4)
3333

3434
self.play(FadeOut(title), FadeOut(summary_bullets))
3535

@@ -52,6 +52,6 @@ def construct(self):
5252
preview_bullets.next_to(title, DOWN, buff=0.5)
5353

5454
self.play(FadeIn(preview_bullets, shift=UP, lag_ratio=0.2))
55-
self.wait(3)
55+
self.wait(4)
5656

5757
# No cleanup - chapter ends on the preview

0 commit comments

Comments
 (0)