Помогите разобраться с передачей матрицы из функции.
$ cat matrix.c
#include <python2.7/Python.h>
#include <stdlib.h>
static PyObject *matrix_maker_cmd(PyObject *self,PyObject *val)
{
double nRow,nCol;
double **a;
int i,j;
if(!PyArg_ParseTuple(val,"ii",&nRow,&nCol))
return NULL;
a = malloc(nRow*nCol*6);
for(i=0; i<nRow; ++i){
for(j=0; j<nCol; ++j){
a[i][j]=cos(i+j);
}
}
return Py_BuildValue("d",a);
}
static PyMethodDef threeMethods[] = {
{"matrix_maker",matrix_maker_cmd,METH_VARARGS,"calc matrix elem"},
{NULL,NULL,0,NULL}
};
void initthree(void)
{
Py_InitModule("matrix",threeMethods);
}
$ cat test_matrix.py
#!/usr/bin/python
import matrix
print matrix_maker(5,4)
$ ./test_matrix.py
Traceback (most recent call last):
File "./test_matrix.py", line 2, in <module>
import matrix
ImportError: dynamic module does not define init function (initmatrix)