title: call Cython function from C++
body: <p>I have a C++ library that has a Python wrapper (written with SWIG). This library allows executing small user-defined code (a callback), such as element-wise operations on a vector. I.e. instead of just a + you can do whatever arbitrary binary function. Right now this is accomplished by accepting a callable Python object for the binary function and calling it. It works, but is about 80 times slower than code that doesn't have to bounce up and down into Python at every iteration.</p>
  
  <p>How would I write/build/import a Cython function could be passed into my C++ library so that it can be called directly by the C++ library?</p>
  
  <p><strong>Edit:</strong>
  If I just stuck to C then I would write something like </p>
  
  <pre><code>EWise(double (*callback)(double, double))
  </code></pre>
  
  <p>EWise would then <code>callback(10, 20);</code> or such. I want <code>callback</code> to be written in Cython, using whatever name the user wants, and a pointer to it has to be passed to my C++ library through Python somehow. That somehow is where I'm unclear.</p>