Skip to content

Commit 63edc00

Browse files
committed
src/sage/tests/books: tweak a "Computational Math..." doctest
One of the tests for the "Computational Math..." book is plotting lines on a vector field by calling scipy.integrate.odeint repeatedly. This test runs, y = integrate.odeint(f, k, t) p += line(zip(t, flatten(y))) in an attempt to flatten y, which is returned as a numpy array of 1-dimensional numpy arrays. However, flatten() isn't smart enough to handle that: it returns a list of 1-dimensional numpy arrays rather than a list of floating point numbers. And numpy-1.25.x now warns about casting 1-dimensional arrays to float deep in our plotting infrastructure. Instead, we now call y.tolist() before passing it to flatten(), and this does the right thing.
1 parent 5c38acd commit 63edc00

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@
134134
sage: t = srange(0, 5, 0.1); p = Graphics()
135135
sage: for k in srange(0, 10, 0.15):
136136
....: y = integrate.odeint(f, k, t)
137-
....: p += line(zip(t, flatten(y)))
137+
....: p += line(zip(t, flatten(y.tolist())))
138138
sage: t = srange(0, -5, -0.1); q = Graphics()
139139
sage: for k in srange(0, 10, 0.15):
140140
....: y = integrate.odeint(f, k, t)
141-
....: q += line(zip(t, flatten(y)))
141+
....: q += line(zip(t, flatten(y.tolist())))
142142
sage: y = var('y')
143143
sage: v = plot_vector_field((1, -cos(x*y)), (x,-5,5), (y,-2,11))
144144
sage: g = p + q + v; g.show()

0 commit comments

Comments
 (0)