3

I'm trying to use PyArray_SearchSorted using NumPy's C API from Cython.

When call it like PyArray_SearchSorted(values, point, NPY_SEARCHLEFT) I get the GCC error: error: too few arguments to function call, expected 4, have 3.

On the other hand, when I call it like PyArray_SearchSorted(values, point, NPY_SEARCHLEFT, NULL), Cython supplies an error: Call with wrong number of arguments (expected 3, got 4).

Looking more closely, it appears there is a discrepancy between the function signature as currently defined in NumPy and as defined in Cython's includes.

I know the sorter argument for searchsorted only appeared in NumPy 1.7.0, but isn't backwards compatibility one of the guarantees with the NumPy C API? Or is this just a Cython bug?

In case it matters, I'm using Cython 0.21.1, NumPy 1.9.1 and Python 2.7 from conda on OS X.

shoyer
  • 9,165
  • 1
  • 37
  • 55

1 Answers1

3

It looks like this change occurred between release 1.6 and 1.7, in this commit:

https://github.com/numpy/numpy/commit/313fe46046a7192cbdba2e679a104777301bc7cf#diff-70664f05e46e0882b0ebe8914bea85b4L1611

I believe this is definitely a bug, but unfortunately this particular kind of bug can easily slip in even with a high standard of diligence. Something like a rigorous ABI conformance test suite would be needed to catch these consistently.

mwiebe
  • 275
  • 1
  • 7
  • To clarify, this is/was a NumPy bug, yes? Though at this point it might make more sense to change the Cython includes than NumPy? – shoyer Jan 28 '15 at 03:55
  • 1
    Yes, it's a NumPy bug. I don't think it would be desirable to do something about it in NumPy this long after it happened, as 1.7, 1.8, and 1.9 are all consistent. Probably the right thing to do is update Cython, and add a documentation warning note about it in the NumPy API docs. – mwiebe Jan 28 '15 at 04:01