title: Complex conversion to Python Complex
body: <p>I'm currently writing a wrapper for a C++ project that use <code>std::complex&lt;double&gt;</code>, available in cython as <code>libcpp.complex.complex[double]</code>.</p>
  
  <p>However there is no implicit conversion between this and Python complex, I'm trying to find the best way to do this conversion.</p>
  
  <p>The obvious is to use</p>
  
  <pre><code>cdef libcpp.complex.complex[double] x = ...
  X = complex(x.real(),x.imag()
  </code></pre>
  
  <p>And</p>
  
  <pre><code>cdef complex Y = ...
  cdef libcpp.complex.complex[double] y = libcpp.complex.complex[double](Y.real, Y.imag)
  </code></pre>
  
  <p>And</p>
  
  <pre><code>cdef libcpp.complex.complex[double] z
  cdef complex Z = ...
  z.real(Z.real)
  z.imag(Z.imag)
  </code></pre>
  
  <p>But is there a better way, preferably to make cython do the conversion automatically.</p>
  
  <p>For one this occurs in some <code>cpdef</code> functions, and I would like to avoid using Python complex in calls from cython for improved speed.</p>
  
  <p>However as far as I can tell cython can't do this conversion implicitly, and thus I can't avoid using the Python complex for code that can be called from Python or C++.</p>