Hi all,<br><br>What is currently the correct way of defining an enum? I am trying to call a NumPy function with an enum as its third argument, and the following does not compile:<br><br><span style="font-family: courier new,monospace;">cimport numpy as np</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">np.import_array()</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cdef enum NPY_SEARCHSIDE:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> NPY_SEARCHLEFT = 0</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> NPY_SEARCHRIGHT = 1</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cdef sort_something():</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> cdef np.ndarray[double, ndim=1] sample_prob = np.empty(5, np.float64)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> cdef np.ndarray[double, ndim=1] cum_prob = np.empty(5, np.float64)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> cdef NPY_SEARCHSIDE side = NPY_SEARCHRIGHT</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> results = np.PyArray_SearchSorted(cum_prob, sample_prob, side)</span><br>
<br>It fails with:<br><br><span style="font-family: courier new,monospace;">enum.c:1081:3: error: incompatible type for argument 3 of ‘(struct PyObject * (*)(struct PyArrayObject *, struct PyObject *, enum NPY_SEARCHSIDE))*(PyArray_API + 1048u)’</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">enum.c:1081:3: note: expected ‘NPY_SEARCHSIDE’ but argument is of type ‘struct PyObject *’</span><br><br>I tried different ways of defining the enum, e.g.<br><br><span style="font-family: courier new,monospace;">cdef extern from "ndarraytypes.h":</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> cpdef enum NPY_SEARCHSIDE:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> NPY_SEARCHLEFT = 0</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> NPY_SEARCHRIGHT = 1</span><br style="font-family: courier new,monospace;"><br>But that doesn't work either. Any suggestions would be appreciated.<br><br>Regards<br>
Stéfan<br><br>