[SciPy-User] checking fpr array type in C extension

Berthold Hoellmann berthold.hoellmann@gl-group....
Fri Jun 18 03:04:23 CDT 2010


I do have problems for checking for integer array types in a C extension
under Windows. I've put together a small example to illustrate the


hoel@pc090498 ~/pytest $ cat tst.c
#include <stdio.h>
#include "Python.h"
#include "numpy/arrayobject.h"
#define TRY(E) (E) ; if(PyErr_Occurred()) {fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); return NULL;}
static PyObject*
inttest_cfunc (PyObject *dummy, PyObject *args) {
  PyArrayObject *array;
  TRY(PyArg_ParseTuple(args, "O!:inttest", &PyArray_Type, &array));
  fprintf(stderr, "PyArray_TYPE(array): %ld; NPY_INT: %ld\n", PyArray_TYPE(array), NPY_INT);
  if (PyArray_TYPE(array) == NPY_INT) { fprintf(stderr, "found NPY_INT\n");
  } else {                              fprintf(stderr, "NPY_INT not found\n"); }

static PyMethodDef mymethods[] = {
  { "inttestfunc", inttest_cfunc, METH_VARARGS, "Doc string"},
  {NULL, NULL, 0, NULL} /* Sentinel */

inittst(void) {
  (void)Py_InitModule("tst", mymethods);

hoel@pc090498 ~/pytest $ python setup.py build
running build

hoel@pc090498 ~/pytest $ cat xx.py
import tst, sys
import numpy as np
print >>sys.stderr, np.__version__, np.__path__

hoel@pc090498 ~/pytest $ PYTHONPATH=build/lib.win32-2.5/ python xx.py
1.4.1 ['C:\\Python25\\lib\\site-packages\\numpy']
PyArray_TYPE(array): 7; NPY_INT: 5
NPY_INT not found
PyArray_TYPE(array): 1; NPY_INT: 5
NPY_INT not found
PyArray_TYPE(array): 3; NPY_INT: 5
NPY_INT not found
PyArray_TYPE(array): 7; NPY_INT: 5
NPY_INT not found
PyArray_TYPE(array): 9; NPY_INT: 5
NPY_INT not found


NPY_INT32 is 7, but shouldn't NPY_INT correspond to numpy.int. And what
kind of int is NPY_INT in this case?

Kind regards

Berthold Höllmann
Germanischer Lloyd AG
Berthold Höllmann
Project Engineer, CAE Development
Brooktorkai 18
20457 Hamburg
Phone: +49(0)40 36149-7374
Fax: +49(0)40 36149-7320
e-mail: berthold.hoellmann@gl-group.com
Internet: http://www.gl-group.com

This e-mail and any attachment thereto may contain confidential information and/or information protected by intellectual property rights for the exclusive attention of the intended addressees named above. Any access of third parties to this e-mail is unauthorised. Any use of this e-mail by unintended recipients such as total or partial copying, distribution, disclosure etc. is prohibited and may be unlawful. When addressed to our clients the content of this e-mail is subject to the General Terms and Conditions of GL's Group of Companies applicable at the date of this e-mail. 

If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer.

GL's Group of Companies does not warrant and/or guarantee that this message at the moment of receipt is authentic, correct and its communication free of errors, interruption etc. 

Germanischer Lloyd AG, 31393 AG HH, Hamburg, Vorstand: Dr. Hermann J. Klein, Dr. Joachim Segatz, Pekka Paasivaara, Vorsitzender des Aufsichtsrats: Dr. Wolfgang Peiner

More information about the SciPy-User mailing list