[Numpy-discussion] minimal numpy ?

David Cournapeau david@ar.media.kyoto-u.ac...
Mon May 11 22:42:06 CDT 2009


Hi Robert,

Robert wrote:
> for use in binary distribution where I need only basics and fast 
> startup/low memory footprint, I try to isolate the minimal ndarray 
> type and what I need..
>
> with "import numpy" or "import numpy.core.multiarray" almost the 
> whole numpy package tree is imported, _dotblas  etc.
> cxFreeze produces some 10MB numpy baggage (4MB zipped)
>   

Yes, we have some circular import going on. Ideally, numpy.core should
be totally independent from the rest of the package. When built with -Os
(or the equivalent with non posix compilers), numpy/core is ~ 800 kb zip
compressed (2.4 Mb, uncompressed).
> yet when copying and using the multiarray DLL only, I can create 
> arrays, but he most things fail:
>
>  >>> import multiarray
>  >>> x=multiarray.array([5,6])
>  >>> x+x
> Traceback (most recent call last):
>    File "<interactive input>", line 1, in <module>
> TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 
> 'numpy.ndarray'
>   

I think you need at least umath to make this work: when doing import
numpy.core.multiarray, you pull out the whole numpy (because import
foo.bar induces import foo I believe), whereas import multiarray just
imports the multiarray C extension.

So my suggestion would be to modify numpy such as you can do import
numpy after having removed most directories inside numpy. The big ones
are distutils and f2py, which should already save 2.5 Mb and are not
used at all in numpy itself. IIRC, the only problematic package is
numpy.lib (we import numpy.lib in numpy.core IIRC).

cheers,

David


More information about the Numpy-discussion mailing list