[Matrix-SIG] coding examples/advice for building Numeric Python extensions?
Joe Van Andel
vanandel@ucar.edu
Mon, 25 Jan 1999 09:38:02 -0700
This is a multipart MIME message.
--==_Exmh_9916988280
Content-Type: text/plain; charset=us-ascii
I'm starting a new project to build a Doppler radar timeseries processing
environment using NumPy. Perhaps I've missed something, but I haven't
found any documentation that explains how to write my own extension.
I've written the argument handling code by adding some new SWIG templates
(attached)
Now that I'm writing the body of my functions, I've got some questions:
1) When (if ever) I should be concerned about "non-contiguous" arrays.
2) If I want to avoid the overhead of copying megabytes of data to insure
that it is contiguous, how do I access the data in the PyArrayObject?
3) Has someone who is familiar with NumPy written a brief extension writer's guide?
4) At the very least, could someone write somes brief descriptions of the
functions that an extension writer should be using?
5) Can someone recommend a short NumPy extension that would serve as an
example?
(IMHO, I think more people might starting using NumPy if there was
documentation of how to write extensions. )
Thanks much for your help!
Joe VanAndel Internet: vanandel@ucar.edu
National Center for http://www.atd.ucar.edu/~vanandel/home.html
Atmospheric Research
--==_Exmh_9916988280
Content-Type: text/plain ; name="numpy_typemaps.i"; charset=us-ascii
Content-Description: numpy_typemaps.i
%typemap(python,in) PyArrayObject *INPUT
{
$target = (PyArrayObject *)$source;
}
%typemap(python,in) PyArrayObject *INPUT_1D
{
$target = (PyArrayObject *)$source;
if ($target->nd != 1) {
PyErr_SetString(PyExc_TypeError, "must be 1D array");
return NULL;
}
}
%typemap(python,in) PyArrayObject *INPUT_2D
{
$target = (PyArrayObject *)$source;
if ($target->nd != 2) {
// printf("%s: num dim = %d\n", "$target", $target->nd);
PyErr_SetString(PyExc_TypeError, "must be 2D array");
return NULL;
}
}
%typemap(python,out) PyObject * {
$target = $source;
}
--==_Exmh_9916988280--