[Numpy-discussion] "import numpy" performance

Robert Kern robert.kern@gmail....
Mon Jul 2 16:06:31 CDT 2012


On Mon, Jul 2, 2012 at 9:43 PM, Benjamin Root <ben.root@ou.edu> wrote:
>
> On Mon, Jul 2, 2012 at 4:34 PM, Nathaniel Smith <njs@pobox.com> wrote:

>> I think this ship has sailed, but it'd be worth looking into lazy
>> importing, where 'numpy.fft' isn't actually imported until someone
>> starts using it. There are a bunch of libraries that do this, and one
>> would have to fiddle to get compatibility with all the different
>> python versions and make sure you're not killing performance (might
>> have to be in C) but something along the lines of
>>
>> class _FFTModule(object):
>>   def __getattribute__(self, name):
>>     mod = importlib.import_module("numpy.fft")
>>     _FFTModule.__getattribute__ = mod.__getattribute__
>>     return getattr(mod, name)
>> fft = _FFTModule()
>
> Not sure how this would impact projects like ipython that does
> tab-completion support, but I know that that would drive me nuts in my basic
> tab-completion setup I have for my regular python terminal.  Of course, in
> the grand scheme of things, that really isn't all that important, I don't
> think.

We used to do it for scipy. It did interfere with tab completion. It
did drive many people nuts.

-- 
Robert Kern


More information about the NumPy-Discussion mailing list