
On Mon, Jul 16, 2012 at 5:28 PM, Charles R Harris <charlesr.harris@gmail.com> wrote:
Hi All,
Working lazy imports would be useful to have. Ralf is opposed to the idea because it caused all sorts of problems on different platforms when it was tried in scipy. I thought I'd open the topic for discussion so that folks who had various problems/solutions could offer input and the common experience could be collected in one place. Perhaps there is a solution that actually works.
I have never seen a lazy import system that did not cause issues in one way or the other. Lazy imports make a lot of sense for an application (e.g. mercurial), but I think it is a mistake to solve this at the numpy level. This should be solved at the application level, and there are solutions for that. For example, using the demandimport code from mercurial (GPL) cuts down the numpy import time by 3 on my mac if one uses np.zeros (100ms -> 50 ms, of which 25 are taken by python itself): """ import demandimport demandimport.enable() import numpy as np a = np.zeros(10) """ To help people who need fast numpy imports, I would suggest the following course of actions: - start benchmarking numpy import in a per-commit manner to detect significant regressions (like what happens with polynomial code) - have a small FAQ on it, with suggestion for people who need to optimize their short-lived script cheers, David