# HG changeset patch
# User Robert Bradshaw <robertwb@math.washington.edu>
# Date 1301130596 25200
# Node ID 09f0506c9424f8b6ccef209edd3a6f26033f0e93
# Parent ec32aa4b0fedbb842b6caaa4a9616167a9dc4697
#11043 - Lazily import plot, numpy, etc. to speed up startup.
diff --git a/sage/all.py b/sage/all.py
a
|
b
|
|
16 | 16 | sage: frames=[x for x in gc.get_objects() if inspect.isframe(x)] |
17 | 17 | sage: len(frames) |
18 | 18 | 11 |
19 | | |
| 19 | |
| 20 | Make sure numpy is not imported at startup:: |
| 21 | |
| 22 | sage: os.system('''sage -c "assert 'numpy' not in sys.modules"''') == 0 |
| 23 | True |
20 | 24 | """ |
21 | 25 | |
22 | 26 | from __future__ import with_statement |
… |
… |
|
103 | 107 | from sage.functions.all import * |
104 | 108 | from sage.calculus.all import * |
105 | 109 | |
106 | | from sage.server.all import * |
| 110 | lazy_import("sage.server.all", "*", overwrite=False) |
107 | 111 | import sage.tests.all as tests |
108 | 112 | |
109 | 113 | from sage.crypto.all import * |
110 | 114 | import sage.crypto.mq as mq |
111 | 115 | |
112 | | from sage.plot.all import * |
113 | | from sage.plot.plot3d.all import * |
| 116 | lazy_import("sage.plot.all", "*", overwrite=False) |
| 117 | lazy_import("sage.plot.plot3d.all", "*", overwrite=False) |
114 | 118 | |
115 | 119 | from sage.coding.all import * |
116 | 120 | from sage.combinat.all import * |
117 | 121 | |
118 | 122 | lazy_import("sage.lfunctions.all", "*", overwrite=False) |
119 | 123 | |
120 | | from sage.geometry.all import * |
121 | | from sage.geometry.triangulation.all import * |
| 124 | lazy_import("sage.geometry.all", "*", overwrite=False) |
| 125 | lazy_import("sage.geometry.triangulation.all", "*", overwrite=False) |
122 | 126 | |
123 | 127 | from sage.homology.all import * |
124 | 128 | |
125 | 129 | from sage.quadratic_forms.all import * |
126 | 130 | |
127 | | from sage.gsl.all import * |
| 131 | lazy_import("sage.gsl.all", "*", overwrite=False) |
128 | 132 | |
129 | 133 | from sage.games.all import * |
130 | 134 | |
… |
… |
|
137 | 141 | from sage.stats.all import * |
138 | 142 | import sage.stats.all as stats |
139 | 143 | |
140 | | import sage.finance.all as finance |
| 144 | lazy_import("sage.finance", "all", "finance", overwrite=False) |
141 | 145 | |
142 | 146 | import sage.interacts.all as interacts |
143 | 147 | |
diff --git a/sage/calculus/all.py b/sage/calculus/all.py
a
|
b
|
|
| 1 | from sage.misc.lazy_import import lazy_import |
| 2 | |
1 | 3 | from calculus import maxima as maxima_calculus |
2 | 4 | from calculus import (laplace, inverse_laplace, |
3 | 5 | limit, lim) |
… |
… |
|
15 | 17 | |
16 | 18 | from var import (var, function, clear_vars) |
17 | 19 | |
18 | | from riemann import Riemann_Map |
19 | | |
20 | | from interpolators import polygon_spline, complex_cubic_spline |
| 20 | lazy_import('sage.calculus.riemann', 'Riemann_Map') |
| 21 | lazy_import('sage.calculus.interpolators', ('polygon_spline', 'complex_cubic_spline')) |
21 | 22 | |
22 | 23 | from sage.modules.all import vector |
23 | 24 | |
diff --git a/sage/calculus/desolvers.py b/sage/calculus/desolvers.py
a
|
b
|
|
57 | 57 | ########################################################################## |
58 | 58 | |
59 | 59 | from sage.interfaces.maxima import MaximaElement, Maxima |
60 | | from sage.plot.all import line |
61 | 60 | from sage.symbolic.expression import is_SymbolicEquation |
62 | 61 | from sage.symbolic.ring import is_SymbolicVariable |
63 | 62 | from sage.calculus.functional import diff |
… |
… |
|
1049 | 1048 | x00 = x01 |
1050 | 1049 | t00 = t00 + h |
1051 | 1050 | soln.append([t00,x00,y00]) |
| 1051 | from sage.plot.all import line |
1052 | 1052 | Q1 = line([[x[0],x[1]] for x in soln], rgbcolor=(1/4,1/8,3/4)) |
1053 | 1053 | Q2 = line([[x[0],x[2]] for x in soln], rgbcolor=(1/2,1/8,1/4)) |
1054 | 1054 | return [Q1,Q2] |
diff --git a/sage/functions/prime_pi.pyx b/sage/functions/prime_pi.pyx
a
|
b
|
|
28 | 28 | |
29 | 29 | from sage.rings.integer import Integer |
30 | 30 | from sage.rings.fast_arith import prime_range |
31 | | import sage.plot.all |
32 | 31 | |
33 | 32 | cdef extern from "math.h": |
34 | 33 | double sqrt(double) |
diff --git a/sage/functions/spike_function.py b/sage/functions/spike_function.py
a
|
b
|
|
2 | 2 | |
3 | 3 | import math |
4 | 4 | |
5 | | from sage.plot.all import line |
6 | 5 | from sage.modules.free_module_element import vector |
7 | 6 | from sage.rings.all import RDF |
8 | 7 | |
… |
… |
|
249 | 248 | new_x = xmax |
250 | 249 | v.append( (new_x, 0) ) |
251 | 250 | x = new_x |
| 251 | from sage.plot.all import line |
252 | 252 | L = line(v, **kwds) |
253 | 253 | L.xmin(xmin-1); L.xmax(xmax) |
254 | 254 | return L |
diff --git a/sage/functions/transcendental.py b/sage/functions/transcendental.py
a
|
b
|
|
37 | 37 | from sage.symbolic.function import GinacFunction, BuiltinFunction, is_inexact |
38 | 38 | from sage.symbolic.ring import SR |
39 | 39 | |
40 | | import sage.plot.all |
41 | | |
42 | 40 | CC = complex_field.ComplexField() |
43 | 41 | I = CC.gen(0) |
44 | 42 | |
diff --git a/sage/gsl/dwt.pyx b/sage/gsl/dwt.pyx
a
|
b
|
|
25 | 25 | |
26 | 26 | #include 'gsl.pxi' |
27 | 27 | |
28 | | import sage.plot.all |
29 | | |
30 | 28 | #import gsl_array |
31 | 29 | #cimport gsl_array |
32 | 30 | |
… |
… |
|
137 | 135 | cdef int i |
138 | 136 | cdef double x |
139 | 137 | v = [] |
140 | | point = sage.plot.all.point |
| 138 | from sage.plot.all import point |
141 | 139 | if xmin == None: |
142 | 140 | x_min = 0 |
143 | 141 | if xmax == None: |
diff --git a/sage/gsl/fft.pyx b/sage/gsl/fft.pyx
a
|
b
|
|
26 | 26 | |
27 | 27 | include '../ext/stdsage.pxi' |
28 | 28 | |
29 | | import sage.plot.all |
30 | | import sage.libs.pari.all |
31 | 29 | from sage.rings.integer import Integer |
32 | 30 | from sage.rings.complex_number import ComplexNumber |
33 | 31 | |
… |
… |
|
93 | 91 | cdef int i |
94 | 92 | v = [] |
95 | 93 | |
96 | | pari = sage.libs.pari.all.pari |
97 | | point = sage.plot.all.point |
| 94 | from sage.libs.pari.all import pari |
| 95 | from sage.plot.all import point |
98 | 96 | pi = pari('Pi') |
99 | 97 | s = 1/(3*pi) # so arg gets scaled between -1/3 and 1/3. |
100 | 98 | |
… |
… |
|
115 | 113 | cdef double pr_x, x, h |
116 | 114 | v = [] |
117 | 115 | |
118 | | point = sage.plot.all.point |
| 116 | from sage.plot.all import point |
119 | 117 | |
120 | 118 | for i from xmin <= i < xmax: |
121 | 119 | x = self.data[2*i] |
diff --git a/sage/plot/all.py b/sage/plot/all.py
a
|
b
|
|
| 1 | import sage.misc.lazy_import |
| 2 | assert sage.misc.lazy_import.check_lazy() |
| 3 | |
1 | 4 | from plot import (Graphics, plot, |
2 | 5 | graphics_array, |
3 | 6 | list_plot, parametric_plot, |
diff --git a/sage/stats/all.py b/sage/stats/all.py
a
|
b
|
|
| 1 | from sage.misc.lazy_import import lazy_import |
| 2 | |
1 | 3 | from r import (ttest) |
2 | 4 | from basic_stats import (mean, mode, std, variance, median, moving_average) |
3 | 5 | |
4 | | import hmm.all as hmm |
| 6 | lazy_import("sage.stats.hmm", "all", "hmm") |
5 | 7 | |
6 | | from sage.finance.time_series import TimeSeries |
7 | | from intlist import IntList |
| 8 | lazy_import("sage.finance.time_series", "TimeSeries") |
| 9 | lazy_import("sage.stats.intlist", "IntList") |
8 | 10 | |