[Numpy-discussion] Confused with Py_ssize_t and Py_intptr_t (intp)

Filip Wasilewski filip at ftv.pl
Fri Mar 31 10:13:05 EST 2006


Hello,

I'm trying to figure out what is the proper type for indexing arrays.
Is it safe to use Py_ssize_t although PyArrayObject dimensions are of
Py_intptr_t (intp) type or use intp instead of Py_ssize_t?

Is there any platform on which these two types has different size or
range?


References:

[1] http://www.python.org/dev/peps/pep-0353/#why-not-py-intptr-t

[2] numpy 0.9.6, arrayobject.c:

    static _int_or_ssize_t
    array_length(PyArrayObject *self)
    {
            if (self->nd != 0) {
                    return self->dimensions[0];
            } else {
                    PyErr_SetString(PyExc_TypeError, "len() of unsized object");
                    return -1;
            }
    }

    // self->dimensions is of intp* type

[3] http://svn.python.org/projects/python/branches/ssize_t/Include/abstract.h

    PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
                                          const void **buffer,
                                          Py_ssize_t *buffer_len);

-- 
best,
fw





More information about the NumPy-Discussion mailing list