[SciPy-dev] Support for numpy scalars in weave?

Norbert Nemec Norbert.Nemec.list at gmx.de
Wed May 17 09:32:22 EDT 2006


Hi there,

it seems that weave does not yet correctly handle variables of the numpy
scalar types.

Consider the following code:

---------------------------------
!/usr/bin/env python

from numpy import *
import scipy.weave
import scipy.weave.converters

pycpx = 1.0
npcpx = array([1j])[0]

scipy.weave.inline(r"""
    std::complex<double> a = pycpx * 1.0;
    std::complex<double> b = npcpx * 1.0;
    """,
    arg_names=["pycpx","npcpx"],
    type_converters=scipy.weave.converters.blitz,
)
-----------------------------------

running it (with up-to-date CVS versions of numpy and scipy installed)
gives an error compiling the produced C++-code. Closer analysis shows
the critical lines in the produced C++ file:

-------------
        py_pycpx = get_variable("pycpx",raw_locals,raw_globals);
        std::complex<double> pycpx = convert_to_complex(py_pycpx,"pycpx");
        py_npcpx = get_variable("npcpx",raw_locals,raw_globals);
        py::object npcpx = convert_to_catchall(py_npcpx,"npcpx");
-------------

Obviously, the "complex128scalar" type of numpy is unknown to weave.

I think this should be fairly easy to fix for anyone who knows the weave
internals a bit better than me.

Greetings,
Norbert




More information about the SciPy-Dev mailing list