[SciPy-user] Does scipy-newcore break the sequence protocol?

Gerard Vermeulen gerard.vermeulen at grenoble.cnrs.fr
Tue Nov 1 04:00:37 CST 2005

The following code using the sequence protocol works with Numeric-23
and numarray, but fails with scipy-newcore (checked out a few days ago):

    float v[3];
    printf("SbColor gets a %s.\n", a0->ob_type->tp_name);
    if ((PySequence_Check(a0)) && 3 == PySequence_Length(a0)) {
        PyObject *item;
        int ok = 1;
        // Does scipy-newcore break the sequence protocol?
        for (int i=0; i<3; i++) {
            item = PySequence_GetItem(a0, i);
            printf("item %d is a %s.\n", i, item->ob_type->tp_name);
            if (PyFloat_CheckExact(item)) {
                v[i] = float(PyFloat_AsDouble(item));
            } else if (PyInt_CheckExact(item)) {
                v[i] = float(PyInt_AsLong(item));
            } else {
                ok = 0;
        if (!ok) { 
                "The sequence may only contain integers and floats.");
            return 0;
        } else {
            sipCpp = new SbColor(v);
    } else { 

This interpreter session shows what happens if I create a new
SbColor using a newcore scipy array as argument instead of a tuple:

>>> from scipy import *
Importing io to scipy
Importing interpolate to scipy
Importing fftpack to scipy
Importing special to scipy
Importing cluster to scipy
Importing sparse to scipy
Importing signal to scipy
Failed to import signal
cannot import name comb
Importing utils to scipy
Importing lib to scipy
Importing integrate to scipy
Importing optimize to scipy
Importing linalg to scipy
Importing stats to scipy
>>> import iv
>>> c = iv.SbColor((0, 0, 0.5))
SbColor gets a tuple.
item 0 is a int.
item 1 is a int.
item 2 is a float.
>>> c = iv.SbColor(array((0, 0, 0.5)))
SbColor gets a scipy.ndarray.
item 0 is a float64_arrtype.
item 1 is a float64_arrtype.
item 2 is a float64_arrtype.
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: The sequence may only contain integers and floats.


PS: why is scipy so noisy? I also get all those 'Importing..' messages
when my binary module only calls import_array()? 

More information about the SciPy-user mailing list