I want to work with my Numpy arrays in extension C. Many examples in this case use the PyArrayObject structure,
array->data , array->strides[0] , array->strides[1] , ...
to reach the data if I wanted to reach my array in a more familiar (or tidier) way with indices like
array[i][j]
how should i act like that? Should I output (bool *) an array-> data and work with the C array that I created? (my elements are bools)
Declaring my function yet (of course, not finished)
static PyObject * xor_masking(PyObject *self, PyObject *args) { PyObject *input; PyObject *mask; PyObject *adjacency; PyObject *state; PyArrayObject *arr_mask; PyArrayObject *arr_adjacency; PyArrayObject *arr_state; PyArrayObject *arr_next_state; double sum; int counter_node, n_nodes; if (!PyArg_ParseTuple(args, "OOO:xor_masking_C", &mask, &adjacency, &state)) return NULL; arr_mask = (PyArrayObject *) PyArray_ContiguousFromObject(mask, PyArray_BOOL, 2, 2); arr_adjacency = (PyArrayObject *) PyArray_ContiguousFromObject(adjacency, PyArray_BOOL, 2, 2); arr_state = (PyArrayObject *) PyArray_ContiguousFromObject(state, PyArray_BOOL, 2, 2); if (array == NULL) return NULL; int n_mask_0 = mask->dimensions[0]; int n_mask_1 = mask->dimensions[1]; int n_adjacency_0 = adjacency->dimensions[0]; int n_adjacency_1 = adjacency->dimensions[1]; int n_state_0 = state->dimensions[0]; int n_nodes = n_state_0; bool c_mask[n_nodes][n_nodes]; if (n_mask_0 != n_mask_1 || n_adjacency_0 != n_adjacency_1 || n_adjacency_0 != n_mask_0 || n_adjacency_0 != n_adjacency_1) { return NULL; } for (counter_node = 0; i < n_mask; i++){ *row_start = (array->data + i*array->strides[0]); }
Thanks!
source share