[Matrix-SIG] howdoi use PyArray_As2D in a sentence?

Les Schaffer godzilla@netmeg.net (Les Schaffer)
Fri, 29 Jan 1999 23:45:36 -0500 (EST)


I am trying to figure out how to pass NumPy 2D arrays to my own C
extension modules as double ** data. i am using typemaps and SWIG to
do the wrapping.

i am looking in the sources at PyArray_As2D and it appears to let
arr->data be set to char **, which i can cast to double **.

but arrayobject.c shows that the first argument to PyArray_As2D is a
PyObject **, not a PyArrayObject ** which has me confused.

what IS the correct way to use PyArray_As2D?

here is the SWIG typemap i am using in order to pass double **:

%typemap(python, in) double ** {
	 
	PyArrayObject *arr;
	int nd, d1, d2, d3; 

	PyObject ** op;
	char ***ptr; 

	arr = (PyArrayObject *) $source;
	nd = arr->nd;
	d1 = arr->dimensions[0];
	d1 = arr->dimensions[1];

	op = (PyObject **) &arr;
	
	PyArray_As2D( op, ptr, &d1, &d2, PyArray_ObjectType( *op, d3 ));
	
	$target = (double **) *ptr; 
}

but i am getting segfaults in array_fromobject(op), called from
PyArray_ContiguousFromObject(*op), called from PyArray_As2D().

any help would be appreciated.

thanks

-- 
____        Les Schaffer              ___| --->> Engineering R&D <<---
Theoretical & Applied Mechanics          |  Designspring, Inc. 
Center for Radiophysics & Space Research |  http://www.designspring.com/
Cornell Univ.  schaffer@tam.cornell.edu  |  les@designspring.com