Question

In a C extension, I am accessing two arrays passed to the function:

PyObject *xw_array = PyArray_FROM_OTF(xw_obj, NPY_DOUBLE, NPY_IN_ARRAY);
PyObject *x1_array = PyArray_FROM_OTF(x1_obj, NPY_DOUBLE, NPY_IN_ARRAY);

and I then want to use PyArray_SearchSorted with these two arrays - I am currently doing:

PyObject *ix_array = PyArray_SearchSorted(xw_array, x1_array);

But this leads to the following error:

propagate_pure.c:123:138: error: too few arguments to function call, expected 4, have 2
PyObject *ix_array = (*(PyObject * (*)(PyArrayObject *, PyObject *, NPY_SEARCHSIDE, PyObject *)) PyArray_API[131])(xw_array, x1_array);
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                   ^

What is the correct way to use PyArray_SearchSorted? What are the four arguments required? The documentation only mentions two.

Was it helpful?

Solution

The full declaration of PyArray_SearchSorted is here:

NPY_NO_EXPORT PyObject *
PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2,
                     NPY_SEARCHSIDE side, PyObject *perm)

You need to provide a side and a perm arguments. The defaults being NPY_SEARCHLEFT and NULL. So the following should work:

PyObject *ix_array = PyArray_SearchSorted(xw_array, x1_array,
                                          NPY_SEARCHLEFT, NULL);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top