Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sage should *never* ever import numpy by default on startup. Yet again it does! #6494

Closed
williamstein opened this issue Jul 9, 2009 · 10 comments

Comments

@williamstein
Copy link
Contributor

$ ./sage -startuptime |grep numpy
         decorators_numpy: 0.000 (IPython.testing)
                 numpy: 0.056 (complex_plot)
                  numpy.__config__: 0.000 (numpy)
                  version: 0.000 (numpy)
                  _import_tools: 0.000 (numpy)
                  add_newdocs: 0.035 (numpy)
                   numpy.lib: 0.026 (add_newdocs)
                    info: 0.000 (numpy.lib)
                    numpy.version: 0.000 (numpy.lib)
                    type_check: 0.016 (numpy.lib)
                     numpy.core.numeric: 0.015 (type_check)
                      multiarray: 0.001 (numpy.core.numeric)
                      umath: 0.001 (numpy.core.numeric)
                       numpy.core.multiarray: 0.000 (umath)
                      _internal: 0.002 (numpy.core.numeric)
                       numpy.compat: 0.000 (_internal)
                        _inspect: 0.000 (numpy.compat)
                        py3k: 0.000 (numpy.compat)
                      numerictypes: 0.001 (numpy.core.numeric)
                      _sort: 0.000 (numpy.core.numeric)
                      numeric: 0.002 (numpy.core.numeric)
                      defchararray: 0.001 (numpy.core.numeric)
                      records: 0.000 (numpy.core.numeric)
                      memmap: 0.000 (numpy.core.numeric)
                      scalarmath: 0.000 (numpy.core.numeric)
                       numpy.core.umath: 0.000 (scalarmath)
                      function_base: 0.000 (numpy.core.numeric)
                      machar: 0.000 (numpy.core.numeric)
                       numpy.core.fromnumeric: 0.000 (machar)
                      getlimits: 0.000 (numpy.core.numeric)
                      shape_base: 0.000 (numpy.core.numeric)
                      numpy.testing: 0.005 (numpy.core.numeric)
                       numpy.testing.utils: 0.004 (numpy.testing)
                        nosetester: 0.003 (numpy.testing.utils)
                       utils: 0.000 (numpy.testing)
                       numpytest: 0.000 (numpy.testing)
                    index_tricks: 0.004 (numpy.lib)
                     numpy.core.numerictypes: 0.000 (index_tricks)
                     numpy.core: 0.000 (index_tricks)
                     numpy.lib.twodim_base: 0.000 (index_tricks)
                      numpy.lib.utils: 0.001 (arraysetops)
                     numpy.matrixlib: 0.001 (index_tricks)
                      defmatrix: 0.001 (numpy.matrixlib)
                    stride_tricks: 0.000 (numpy.lib)
                    twodim_base: 0.000 (numpy.lib)
                    scimath: 0.000 (numpy.lib)
                     numpy.lib.type_check: 0.000 (scimath)
                    numpy.lib.function_base: 0.000 (numpy.lib)
                    numpy.linalg: 0.003 (numpy.lib)
                     linalg: 0.003 (numpy.linalg)
                      numpy.matrixlib.defmatrix: 0.000 (linalg)
                    npyio: 0.002 (numpy.lib)
                    financial: 0.000 (numpy.lib)
                    arrayterator: 0.000 (numpy.lib)
                   numpy.lib._compiled_base: 0.000 (add_newdocs)
                   numpy.lib.index_tricks: 0.000 (add_newdocs)
                  testing: 0.000 (numpy)
                  core: 0.000 (numpy)
                  compat: 0.000 (numpy)
                  lib: 0.000 (numpy)
                  fft: 0.001 (numpy)
                  polyutils: 0.000 (numpy)
                  polytemplate: 0.000 (numpy)
                  chebyshev: 0.005 (numpy)
                  mtrand: 0.002 (numpy)
                  ctypeslib: 0.001 (numpy)
                   numpy.core._internal: 0.000 (ctypeslib)
                  ma: 0.005 (numpy)
                  matrixlib: 0.000 (numpy)
0.056 numpy (complex_plot)
0.035 add_newdocs (numpy)

I think this is because of the new complex_plot module, which I think I positively reviewed, so this is my fault. To resolve this ticket, make that import sufficiently lazy. Also, make a doctest that verifies that numpy is not imported when Sage starts up.

CC: @williamstein @jasongrout @robertwb

Component: packages: standard

Reviewer: Mike Hansen

Issue created by migration from https://trac.sagemath.org/ticket/6494

@mwhansen
Copy link
Contributor

Attachment: trac_6494.patch.gz

@mwhansen
Copy link
Contributor

Author: Mike Hansen

@mwhansen
Copy link
Contributor

comment:1

I don't think you can cimport numpy without causing an import in the module. Thus, a number of things have to be lazily imported. This will cause a problem if people do

sage: from sage.finance.all import TimeSeries
sage: isinstance(foo, TimeSeries)

since TimeSeries will be a LazyImport object rather than a class. I'm not sure the best thing to do, but I've posted a patch anyway.

@jasongrout
Copy link
Member

comment:2

numpy recently has made great improvements in its import speed, so maybe this isn't quite the issue it used to be?

@jdemeyer
Copy link

comment:4

I'm not going to judge whether numpy imports are still an issue or not, but in any case the patch needs to be rebased:

patching file sage/calculus/all.py
Hunk #2 succeeded at 16 (offset 1 line).
patching file sage/finance/all.py
patching file sage/interfaces/gnuplot.py
patching file sage/plot/all.py
Hunk #2 FAILED at 21.
1 out of 2 hunks FAILED -- saving rejects to file sage/plot/all.py.rej
patching file sage/plot/plot3d/implicit_plot3d.py
Hunk #2 succeeded at 255 (offset 10 lines).
patching file sage/stats/all.py
patching file sage/stats/hmm/all.py

@jdemeyer

This comment has been minimized.

@mwhansen
Copy link
Contributor

comment:5

This ticket is invalid now as all of the changes appearing in it are already in the Sage library.

@mwhansen mwhansen removed this from the sage-5.0 milestone Mar 28, 2012
@jdemeyer
Copy link

comment:6

You shouldn't just close tickets, leave that to the release manager.

@jdemeyer
Copy link

Reviewer: Mike Hansen

@jdemeyer
Copy link

Changed author from Mike Hansen to none

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants