Robert,<div><br></div><div>Well, as I suspected, it&#39;s all my fault! I have  built a tiny module with your code, a C function and a C class, and it all works! Now to get the larger code going... Then I&#39;ll do some performance testing against some older Fortran code. If I get 80%, I&#39;m staying with Cython/Python!</div>
<div><br></div><div>THANKS!</div><div>--v<br><br><div class="gmail_quote">On Sat, Apr 4, 2009 at 2:57 PM, Robert Bradshaw <span dir="ltr">&lt;<a href="mailto:robertwb@math.washington.edu" target="_blank">robertwb@math.washington.edu</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Apr 4, 2009, at 9:09 AM, Vic Kelson wrote:<br>
<br>
&gt; Robert,<br>
&gt; Thatnks for your helpful note. I can&#39;t seem to make it work with gcc<br>
&gt; on OS X.<br>
<br>
</div>Hmm... that&#39;s the same platform I use.<br>
<div><br>
&gt; I keep getting an error from gcc. I haven&#39;t had time to sort<br>
&gt; through it yet. I think I&#39;ll build a little test problem (I tried<br>
&gt; embedding your cod in my existing code and I might have created<br>
&gt; another error).<br>
<br>
</div>Maybe you could post a snippet of the error you&#39;re getting?<br>
<div><br>
&gt; Just to be sure, when I use your code to make a cdouble, the real and<br>
&gt; imaginary parts are the same size as a python float, right?<br>
<br>
</div>Yes. Python floats are wrappers of double (and Python complexes wrap<br>
a pair of doubles).<br>
<div><div></div><div><br>
&gt; Thanks!<br>
&gt; --v<br>
&gt;<br>
&gt;<br>
&gt; On 4/4/09, Robert Bradshaw &lt;<a href="mailto:robertwb@math.washington.edu" target="_blank">robertwb@math.washington.edu</a>&gt; wrote:<br>
&gt;&gt; On Apr 3, 2009, at 10:21 PM, Vic Kelson wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; Greetings all,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Sorry for the incomplete message, I&#39;m re-sending it.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I&#39;m in need of fast computations on complex numbers from Cython.<br>
&gt;&gt;&gt; I&#39;ve been converting a Python groundwater flow model code to<br>
&gt;&gt;&gt; Cython, but I&#39;m reaching the point where I&#39;d really prefer to have<br>
&gt;&gt;&gt; native C complex math. Up to now, I&#39;ve used some little C routines<br>
&gt;&gt;&gt; that I can call with multiple floats (the C code converts to/from<br>
&gt;&gt;&gt; complex for my purposes). However, I&#39;m nearly to the point where<br>
&gt;&gt;&gt; I&#39;ll need to store series coefficients for performance purposes,<br>
&gt;&gt;&gt; and then I&#39;ll either need to hide them in float arrays (and that&#39;s<br>
&gt;&gt;&gt; extremely nasty), or something like that.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I&#39;d like to say something like<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; cdef class Foo:<br>
&gt;&gt;&gt;     cdef cfloat z<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     def __cinit__(self, float x, float y):<br>
&gt;&gt;&gt;         self.z = cfloat(x, y)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     cdef cfloat func(Foo self, float x, float y):<br>
&gt;&gt;&gt;         return-some-gnarly-function of x, y, and self.z<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Or something like that, where &#39;cfloat&#39; maps to the appropriate type<br>
&gt;&gt;&gt; in the C compiler, e.g. &quot;double _Complex&quot; in gcc.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I&#39;ve seen this discussed in the archives. Has it been implemented?<br>
&gt;&gt;&gt; Is there some pre-release code that essentially works? I only need<br>
&gt;&gt;&gt; the four math functions, conjugate, abs, and log.<br>
&gt;&gt;<br>
&gt;&gt; Yes, I&#39;ve started this, as it comes up in my research too (number<br>
&gt;&gt; theory, computing values of L-functions). I hope to have something<br>
&gt;&gt; releasable soon. In the meantime, you can do<br>
&gt;&gt;<br>
&gt;&gt; cdef extern from &quot;complex.h&quot;:<br>
&gt;&gt;      ctypedef double cdouble &quot;double complex&quot;<br>
&gt;&gt;      cdef double creal(cdouble)<br>
&gt;&gt;      cdef double cimag(cdouble)<br>
&gt;&gt;      cdef cdouble _Complex_I<br>
&gt;&gt;<br>
&gt;&gt; cdef inline cdouble  new_cdouble(double x, double y):<br>
&gt;&gt;      return x + _Complex_I*y<br>
&gt;&gt;<br>
&gt;&gt; Of course, the ctypedef is wrong, it will think it can go back to<br>
&gt;&gt; doubles (and Python objects) without any problem, but it works for<br>
&gt;&gt; now.<br>
&gt;&gt;<br>
&gt;&gt;&gt; THANKS! I think Cython will revolutionize my research work!<br>
&gt;&gt;<br>
&gt;&gt; That&#39;s the goal :) Please cite us if it does.<br>
&gt;&gt;<br>
&gt;&gt; - Robert<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Cython-dev mailing list<br>
&gt;&gt; <a href="mailto:Cython-dev@codespeak.net" target="_blank">Cython-dev@codespeak.net</a><br>
&gt;&gt; <a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
&gt;&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Sent from my mobile device<br>
&gt;<br>
&gt; Vic Kelson<br>
&gt; <a href="mailto:vic.kelson@gmail.com" target="_blank">vic.kelson@gmail.com</a><br>
&gt; _______________________________________________<br>
&gt; Cython-dev mailing list<br>
&gt; <a href="mailto:Cython-dev@codespeak.net" target="_blank">Cython-dev@codespeak.net</a><br>
&gt; <a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
<br>
_______________________________________________<br>
Cython-dev mailing list<br>
<a href="mailto:Cython-dev@codespeak.net" target="_blank">Cython-dev@codespeak.net</a><br>
<a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Vic Kelson<br><a href="mailto:vic.kelson@gmail.com" target="_blank">vic.kelson@gmail.com</a><br>
</div>