Ticket #11714: trac_11714.patch

File trac_11714.patch, 6.0 KB (added by William Stein, 11 years ago)
  • sage/calculus/all.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1314039861 25200
    # Node ID d5386383a9e883cb8be926883af104bde4e24a9b
    # Parent  5b36a670c858c406cd730f862193ae5c7066d074
    trac 11714: Make sure numpy does not get imported on startup
    
    diff --git a/sage/calculus/all.py b/sage/calculus/all.py
    a b  
    1515
    1616from var import (var, function, clear_vars)
    1717
    18 from riemann import Riemann_Map
     18# We lazy import Riemann_Map, since it imports numpy.
     19#from riemann import Riemann_Map
     20from sage.misc.lazy_import import lazy_import
     21lazy_import('sage.calculus.riemann', 'Riemann_Map')
    1922
    20 from interpolators import polygon_spline, complex_cubic_spline
     23# from interpolators import polygon_spline, complex_cubic_spline
     24lazy_import('sage.calculus.interpolators', 'polygon_spline')
     25lazy_import('sage.calculus.interpolators', 'complex_cubic_spline')
     26
    2127
    2228from sage.modules.all import vector
    2329
  • sage/finance/all.py

    diff --git a/sage/finance/all.py b/sage/finance/all.py
    a b  
    22
    33from markov_multifractal import MarkovSwitchingMultifractal
    44
    5 from time_series import TimeSeries, autoregressive_fit
     5#from time_series import TimeSeries, autoregressive_fit
     6from sage.misc.lazy_import import lazy_import
     7lazy_import('sage.finance.time_series', 'TimeSeries')
     8lazy_import('sage.finance.time_series', 'autoregressive_fit')
    69
    7 from fractal import (stationary_gaussian_simulation,
    8                      fractional_gaussian_noise_simulation,
    9                      fractional_brownian_motion_simulation,
    10                      multifractal_cascade_random_walk_simulation)
    11 
    12 ## def TimeSeries(values):
    13 ##     """
    14 ##     Initialize new time series.
    15 
    16 ##     INPUT:
    17 ##         values -- integer (number of values) or an iterable of floats
    18 
    19 ##     EXAMPLES:
    20 ##     This implicity calls init.
    21 ##         sage: finance.TimeSeries([pi, 3, 18.2])
    22 ##         [3.1416, 3.0000, 18.2000]
    23 ##     """
    24 ##     # A dirty trick to avoid importing time_series (hence vector_real_double_dense)
    25 ##     # every time sage starts up, but to make sure that the finance.TimeSeries
    26 ##     # function is VERY fast.  The first time this function is called it is
    27 ##     # immediately replaced by the fast compiled version in the time_series
    28 ##     # module.
    29 ##     from time_series import TimeSeries
    30 ##     globals()['TimeSeries'] = TimeSeries
    31 ##     return TimeSeries(values)
     10#from fractal import (stationary_gaussian_simulation,
     11#                     fractional_gaussian_noise_simulation,
     12#                     fractional_brownian_motion_simulation,
     13#                     multifractal_cascade_random_walk_simulation)
     14lazy_import('sage.finance.fractal', 'stationary_gaussian_simulation')
     15lazy_import('sage.finance.fractal', 'fractional_gaussian_noise_simulation')
     16lazy_import('sage.finance.fractal', 'fractional_brownian_motion_simulation')
     17lazy_import('sage.finance.fractal', 'multifractal_cascade_random_walk_simulation')
  • sage/misc/lazy_import.pyx

    diff --git a/sage/misc/lazy_import.pyx b/sage/misc/lazy_import.pyx
    a b  
    697697    """
    698698    Create a lazy import object and inject it into the caller's global
    699699    namespace. For the purposes of introspection and calling, this
    700     like performing a lazy "from module import name" where the import
     700    is like performing a lazy "from module import name" where the import
    701701    is delayed until the object actually is used or inspected.
    702702   
    703703    INPUT:
  • sage/plot/all.py

    diff --git a/sage/plot/all.py b/sage/plot/all.py
    a b  
    2020from ellipse import ellipse
    2121from contour_plot import contour_plot, implicit_plot, region_plot
    2222from density_plot import density_plot
    23 from complex_plot import complex_plot
     23
     24#from complex_plot import complex_plot
     25from sage.misc.lazy_import import LazyImport
     26complex_plot = LazyImport('sage.plot.complex_plot', 'complex_plot')
     27
    2428from arc import arc
    2529
    2630from animate import Animation as animate
  • sage/plot/plot3d/implicit_plot3d.py

    diff --git a/sage/plot/plot3d/implicit_plot3d.py b/sage/plot/plot3d/implicit_plot3d.py
    a b  
    22Implicit Plots
    33"""
    44
    5 from implicit_surface import ImplicitSurface
    6 
    75def implicit_plot3d(f, xrange, yrange, zrange, **kwds):
    86    r"""
    97    Plots an isosurface of a function.
     
    258256    #   respectively.
    259257
    260258
     259    from implicit_surface import ImplicitSurface
    261260    G = ImplicitSurface(f, xrange, yrange, zrange, **kwds)
    262261    G._set_extra_kwds(kwds)
    263262    return G
  • sage/stats/all.py

    diff --git a/sage/stats/all.py b/sage/stats/all.py
    a b  
    11from r import (ttest)
    22from basic_stats import (mean, mode, std, variance, median, moving_average)
    33
    4 import hmm.all as hmm
     4#import hmm.all as hmm
     5from sage.misc.lazy_import import lazy_import
     6lazy_import('sage.stats.hmm.all', 'hmm')
    57
    6 from sage.finance.time_series import TimeSeries
    7 from intlist import IntList
     8#from sage.finance.time_series import TimeSeries
     9lazy_import('sage.finance.time_series', 'TimeSeries')
    810
     11#from intlist import IntList
     12lazy_import('sage.stats.intlist', 'IntList')
     13
  • sage/tests/startup.py

    diff --git a/sage/tests/startup.py b/sage/tests/startup.py
    a b  
    88    ... else: print True   # nothing when not on sage.math
    99    True
    1010
     11Ensure that certain modules are not loaded at startup::
     12
     13    sage: from sage.tests.startup import ensure_module_not_loaded
     14    sage: ensure_module_not_loaded('numpy')
     15
    1116"""
     17
     18import os
     19
     20def ensure_module_not_loaded(module):
     21    """
     22    EXAMPLES::
     23   
     24        sage: from sage.tests.startup import ensure_module_not_loaded
     25
     26    This one isn't::
     27   
     28        sage: ensure_module_not_loaded('squeemish_osafrage')
     29
     30    This module is imported::
     31   
     32        sage: ensure_module_not_loaded('pickle')
     33        Traceback (most recent call last):
     34        ...
     35        AssertionError
     36    """
     37    cmd = 'sage -startuptime |grep " %s:" > /dev/null'%module
     38    assert os.system(cmd) != 0