Happy Holidays...
Working Python-C numpy C-API with
if (!PyArg_ParseTuple(args, "lOO!O!O!O!O!O!O!", &N, &mychunk, &PyArray_Type, &py_local_F, &PyArray_Type, &py_centers, &PyArray_Type, &py_normals, &PyArray_Type, &py_v1, &PyArray_Type, &py_v2, &PyArray_Type, &py_v3, &PyArray_Type, &py_areas))
return NULL;
works with the info code output from the C program:
void print_pyfunction_info(char* name, PyArrayObject *arr)
{
int d = PyArray_NDIM(arr);
npy_intp N = PyArray_SIZE(arr);
printf("Python array name=%s ndim=%i, size=%li \n", name, d, N);
}
and calling this function in the C program:
char name1[128] = "py_v1";
print_pyfunction_info(name1, py_v1);
char name2[128] = "py_v2";
print_pyfunction_info(name2, py_v2);
char name3[128]="py_v3";
print_pyfunction_info(name3, py_v3);
char name4[128]="py_centers";
print_pyfunction_info(name4, py_centers);
char name5[128]="py_normals";
print_pyfunction_info(name5, py_normals);
char name7[128]="py_local_F";
print_pyfunction_info(name7, py_local_F);
Produces the correct output:
Python array name=py_v1 ndim=2, size=120
Python array name=py_v2 ndim=2, size=120
Python array name=py_v3 ndim=2, size=120
Python array name=py_centers ndim=2, size=120
Python array name=py_normals ndim=2, size=120
Python array name=py_local_F ndim=2, size=1600
Works fine!
Now, appending one object, one array and one long integer which are perfectly correctly passed to C:
if (!PyArg_ParseTuple(args, "lOO!O!O!O!O!O!O!OO!l", &N, &mychunk, &PyArray_Type, &py_local_F, &PyArray_Type, &py_centers, &PyArray_Type, &py_normals, &PyArray_Type, &py_v1, &PyArray_Type, &py_v2, &PyArray_Type, &py_v3, &PyArray_Type, &py_areas, &cells, &PyArray_Type, &py_rootbounds, &Ncells))
return NULL;
Breaks with segfault in the info (and if not asked for info, when I used local_F array):
char name1[128] = "py_v1";
print_pyfunction_info(name1, py_v1);
char name2[128] = "py_v2";
print_pyfunction_info(name2, py_v2);
char name3[128]="py_v3";
print_pyfunction_info(name3, py_v3);
char name4[128]="py_centers";
print_pyfunction_info(name4, py_centers);
char name5[128]="py_normals";
print_pyfunction_info(name5, py_normals);
char name6[128]="py_rootbounds";
print_pyfunction_info(name6, py_rootbounds);
char name7[128]="py_local_F";
print_pyfunction_info(name7, py_local_F);
Breaks with segfault:
Python array name=py_v1 ndim=2, size=120
Python array name=py_v2 ndim=2, size=120
Python array name=py_v3 ndim=2, size=120
Python array name=py_centers ndim=2, size=120
Python array name=py_normals ndim=2, size=120
Python array name=py_rootbounds ndim=1, size=6
Fatal Python error: Segmentation fault
From the Python side local_F is the same, it is a 40x40 array
local_F {} [[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]]
I am out of resources, any help is greatly appreciated.
Best wishes!