[Numpy-discussion] Exporting Numpy C functionality to other extension modules
jmiller at stsci.edu
Fri Jan 17 14:16:03 EST 2003
Take a look at the attached extension module "testlite" which
demonstrates the technique I evolved from this discussion. As we
discussed, this usage pattern enables the construction of an extension
which will take advantage of numarray if it is there, but will continue
to work if the user has not installed numarray. Here's how it works:
1. I created a new API function, PyArray_isArray() which is safe to
call in all contexts. I defined it as:
#define PyArray_isArray(o) (PyArray_API && NA_isNumArray(o))
I added NA_isNumArray(o) to the numarray C-API because it was the easy
way to do it.
2. Ordinary API functions are safe to call once an object has been
identified to be a numarray because it implies (locally) that the
PyArray_API pointer has been initialized.
3. I tried out the standard import_array() code and added some cleanup
for the case where numarray is not installed.
The only caveat I see at this point is that you are required to include
numarray headers in order to use this. In numarray's case, this might
necessitate header updates and/or function call modifications. The
numarray C-API should stabilize pretty soon, but I don't think its
quite there yet.
The same approach should apply to Numeric.
This stuff is in numarray CVS now and should be in the next numarray
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the NumPy-Discussion