[MATRIX-SIG] Extending NumPy
Hoon Yoon - IPT Quant
hyoon@nyptsrv1.etsd.ml.com
Tue, 19 Aug 1997 09:28:19 -0400
Hello,
I am finally embarking on extending Python with C programs and at
this point I am trying to push in Lists of strings and get back
lists of strings and Numerical arrays back from a C function.
Unfortunately, I am having problems finding examples of these
codes in C. I guess the following from gdmodule does show how
to kinda pass in a list or tuple into a C prog, but I am lost on
how to do this for string arrays (multiple) and get back string
arrays and most of all Numeric Arrays:
*****************************************************************
Nice example of how to do this with number tuple
Can I use **points to do this for string tuple and args1, args2, args3?
*****************************************************************
static PyObject *image_lines(self, args)
imageobject *self;
PyObject *args;
{
PyObject *point, *points, *bit;
int color, i, x,y,ox,oy;
if (!PyArg_ParseTuple(args, "O!i", &PyTuple_Type, &points, &color))
{
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!i", &PyList_Type, &points, &color))
points = PyList_AsTuple(points);
else return NULL;
}
point = PyTuple_GET_ITEM(points,0);
ox = PyInt_AS_LONG((PyIntObject *)PyTuple_GET_ITEM(point,0));
oy = PyInt_AS_LONG((PyIntObject *)PyTuple_GET_ITEM(point,1));
for (i=1; i<PyTuple_Size(points); i++)
{
point = PyTuple_GET_ITEM(points,i);
x = PyInt_AS_LONG((PyIntObject *)PyTuple_GET_ITEM(point,0));
y = PyInt_AS_LONG((PyIntObject *)PyTuple_GET_ITEM(point,1));
gdImageLine(self->imagedata, X(ox), Y(oy), X(x), Y(y), color);
ox=x;oy=y;
}
Py_INCREF(Py_None);
return Py_None;
}
**********************************************************************
Can anyone show me some example of these extentions, I've mentioned
here? At least I would like to get back list in list
[[1,2,3],[4,5,6]] type of thing, which I could easily convert back
to a Num Array.
Much appreciated,
Hoon,
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________