Skip to content

Commit

Permalink
Trac #33837: sage.{numerical,calculus,probability}: Remove use of SAG…
Browse files Browse the repository at this point in the history
…E_TMP in doctests

(split out from #33213)

URL: https://trac.sagemath.org/33837
Reported by: mkoeppe
Ticket author(s): Michael Orlitzky
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed May 24, 2022
2 parents 028e704 + 386562c commit 36286c8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/sage/calculus/calculus.py
Expand Up @@ -1620,7 +1620,9 @@ def laplace(ex, t, s, algorithm='maxima'):
91/8*e^(4*t) + 629/8*e^(-4*t)
sage: p1 = plot(xt,0,1/2,rgbcolor=(1,0,0))
sage: p2 = plot(yt,0,1/2,rgbcolor=(0,1,0))
sage: (p1+p2).save(os.path.join(SAGE_TMP, "de_plot.png"))
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f:
....: (p1+p2).save(f.name)
Another example::
Expand Down
28 changes: 16 additions & 12 deletions src/sage/calculus/ode.pyx
Expand Up @@ -236,8 +236,9 @@ class ode_solver(object):
sage: T.function=f_1
sage: T.jacobian=j_1
sage: T.ode_solve(y_0=[1,0],t_span=[0,100],params=[10.0],num_points=1000)
sage: outfile = os.path.join(SAGE_TMP, 'sage.png')
sage: T.plot_solution(filename=outfile)
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f:
....: T.plot_solution(filename=f.name)
The solver line is equivalent to::
Expand All @@ -261,9 +262,10 @@ class ode_solver(object):
By default T.plot_solution() plots the y_0, to plot general y_i use::
sage: T.plot_solution(i=0, filename=outfile)
sage: T.plot_solution(i=1, filename=outfile)
sage: T.plot_solution(i=2, filename=outfile)
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f:
....: T.plot_solution(i=0, filename=f.name)
....: T.plot_solution(i=1, filename=f.name)
....: T.plot_solution(i=2, filename=f.name)
The method interpolate_solution will return a spline interpolation
through the points found by the solver. By default y_0 is
Expand Down Expand Up @@ -321,13 +323,15 @@ class ode_solver(object):
following (WARNING: the following is *not* automatically
doctested)::
sage: T = ode_solver() # not tested
sage: T.algorithm = "bsimp" # not tested
sage: vander = van_der_pol() # not tested
sage: T.function=vander # not tested
sage: T.ode_solve(y_0 = [1,0], t_span=[0,2000], num_points=1000) # not tested
sage: T.plot_solution(i=0, filename=os.path.join(SAGE_TMP, 'test.png')) # not tested
sage: T = ode_solver() # not tested
sage: T.algorithm = "bsimp" # not tested
sage: vander = van_der_pol() # not tested
sage: T.function=vander # not tested
sage: T.ode_solve(y_0 = [1,0], t_span=[0,2000], # not tested
....: num_points=1000) # not tested
sage: from tempfile import NamedTemporaryFile # not tested
sage: with NamedTemporaryFile(suffix=".png") as f: # not tested
....: T.plot_solution(i=0, filename=f.name) # not tested
"""
def __init__(self,function=None,jacobian=None,h = 1e-2,error_abs=1e-10,error_rel=1e-10, a=False,a_dydt=False,scale_abs=False,algorithm="rkf45",y_0=None,t_span=None,params = []):
Expand Down
9 changes: 7 additions & 2 deletions src/sage/numerical/backends/generic_backend.pyx
Expand Up @@ -948,7 +948,9 @@ cdef class GenericBackend:
2
sage: p.add_linear_constraint([(0, 1], (1, 2)], None, 3) # optional - Nonexistent_LP_solver
sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver
sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp")) # optional - Nonexistent_LP_solver
sage: from tempfile import NamedTemporaryFile # optional - Nonexistent_LP_solver
sage: with NamedTemporaryFile(suffix=".lp") as f: # optional - Nonexistent_LP_solver
....: p.write_lp(f.name)
"""
raise NotImplementedError()

Expand All @@ -968,7 +970,10 @@ cdef class GenericBackend:
2
sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3) # optional - Nonexistent_LP_solver
sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver
sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp")) # optional - Nonexistent_LP_solver
sage: from tempfile import NamedTemporaryFile # optional - Nonexistent_LP_solver
sage: with NamedTemporaryFile(suffix=".lp") as f: # optional - Nonexistent_LP_solver
....: p.write_lp(f.name)
"""
raise NotImplementedError()

Expand Down
10 changes: 4 additions & 6 deletions src/sage/probability/probability_distribution.pyx
Expand Up @@ -164,16 +164,14 @@ cdef class ProbabilityDistribution:
EXAMPLES:
This saves the histogram plot to
``my_general_distribution_plot.png`` in the temporary
directory ``SAGE_TMP``::
This saves the histogram plot to a temporary file::
sage: from sage.probability.probability_distribution import GeneralDiscreteDistribution
sage: import os
sage: import tempfile
sage: P = [0.3, 0.4, 0.3]
sage: X = GeneralDiscreteDistribution(P)
sage: file = os.path.join(SAGE_TMP, "my_general_distribution_plot")
sage: X.generate_histogram_plot(file)
sage: with tempfile.NamedTemporaryFile() as f:
....: X.generate_histogram_plot(f.name)
"""
import pylab
l = [float(self.get_random_element()) for _ in range(num_samples)]
Expand Down

0 comments on commit 36286c8

Please sign in to comment.