I did the first one. I just wanted to make sure that it was resolved at compile time.<br><br>THANKS!<br>--v<br><br><div class="gmail_quote">On Mon, Apr 6, 2009 at 12:19 PM, Lisandro Dalcin <span dir="ltr">&lt;<a href="mailto:dalcinl@gmail.com">dalcinl@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I would do this (at de module-level):<br>
<br>
import math<br>
cdef double PI = math.pi<br>
<br>
of perhaps<br>
<br>
cdef double PI = 3.14...<br>
<br>
and just use &quot;PI&quot; on you cdef functions...<br>
<div><div></div><div class="h5"><br>
On Sun, Apr 5, 2009 at 1:28 AM, Vic Kelson &lt;<a href="mailto:vic.kelson@gmail.com">vic.kelson@gmail.com</a>&gt; wrote:<br>
&gt; Another question: If I need the constant pi, and I use math.pi or numpy.pi<br>
&gt; in a C function (or a C method of a C class), does it add an inefficiency<br>
&gt; (Python lookup)?<br>
&gt; Just wondering...<br>
&gt; --v<br>
&gt;<br>
&gt; On Sat, Apr 4, 2009 at 2:57 PM, Robert Bradshaw<br>
&gt; &lt;<a href="mailto:robertwb@math.washington.edu">robertwb@math.washington.edu</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On Apr 4, 2009, at 9:09 AM, Vic Kelson wrote:<br>
&gt;&gt;<br>
&gt;&gt; &gt; Robert,<br>
&gt;&gt; &gt; Thatnks for your helpful note. I can&#39;t seem to make it work with gcc<br>
&gt;&gt; &gt; on OS X.<br>
&gt;&gt;<br>
&gt;&gt; Hmm... that&#39;s the same platform I use.<br>
&gt;&gt;<br>
&gt;&gt; &gt; I keep getting an error from gcc. I haven&#39;t had time to sort<br>
&gt;&gt; &gt; through it yet. I think I&#39;ll build a little test problem (I tried<br>
&gt;&gt; &gt; embedding your cod in my existing code and I might have created<br>
&gt;&gt; &gt; another error).<br>
&gt;&gt;<br>
&gt;&gt; Maybe you could post a snippet of the error you&#39;re getting?<br>
&gt;&gt;<br>
&gt;&gt; &gt; Just to be sure, when I use your code to make a cdouble, the real and<br>
&gt;&gt; &gt; imaginary parts are the same size as a python float, right?<br>
&gt;&gt;<br>
&gt;&gt; Yes. Python floats are wrappers of double (and Python complexes wrap<br>
&gt;&gt; a pair of doubles).<br>
&gt;&gt;<br>
&gt;&gt; &gt; Thanks!<br>
&gt;&gt; &gt; --v<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On 4/4/09, Robert Bradshaw &lt;<a href="mailto:robertwb@math.washington.edu">robertwb@math.washington.edu</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt; On Apr 3, 2009, at 10:21 PM, Vic Kelson wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Greetings all,<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Sorry for the incomplete message, I&#39;m re-sending it.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I&#39;m in need of fast computations on complex numbers from Cython.<br>
&gt;&gt; &gt;&gt;&gt; I&#39;ve been converting a Python groundwater flow model code to<br>
&gt;&gt; &gt;&gt;&gt; Cython, but I&#39;m reaching the point where I&#39;d really prefer to have<br>
&gt;&gt; &gt;&gt;&gt; native C complex math. Up to now, I&#39;ve used some little C routines<br>
&gt;&gt; &gt;&gt;&gt; that I can call with multiple floats (the C code converts to/from<br>
&gt;&gt; &gt;&gt;&gt; complex for my purposes). However, I&#39;m nearly to the point where<br>
&gt;&gt; &gt;&gt;&gt; I&#39;ll need to store series coefficients for performance purposes,<br>
&gt;&gt; &gt;&gt;&gt; and then I&#39;ll either need to hide them in float arrays (and that&#39;s<br>
&gt;&gt; &gt;&gt;&gt; extremely nasty), or something like that.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I&#39;d like to say something like<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; cdef class Foo:<br>
&gt;&gt; &gt;&gt;&gt;     cdef cfloat z<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;     def __cinit__(self, float x, float y):<br>
&gt;&gt; &gt;&gt;&gt;         self.z = cfloat(x, y)<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;     cdef cfloat func(Foo self, float x, float y):<br>
&gt;&gt; &gt;&gt;&gt;         return-some-gnarly-function of x, y, and self.z<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Or something like that, where &#39;cfloat&#39; maps to the appropriate type<br>
&gt;&gt; &gt;&gt;&gt; in the C compiler, e.g. &quot;double _Complex&quot; in gcc.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I&#39;ve seen this discussed in the archives. Has it been implemented?<br>
&gt;&gt; &gt;&gt;&gt; Is there some pre-release code that essentially works? I only need<br>
&gt;&gt; &gt;&gt;&gt; the four math functions, conjugate, abs, and log.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Yes, I&#39;ve started this, as it comes up in my research too (number<br>
&gt;&gt; &gt;&gt; theory, computing values of L-functions). I hope to have something<br>
&gt;&gt; &gt;&gt; releasable soon. In the meantime, you can do<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; cdef extern from &quot;complex.h&quot;:<br>
&gt;&gt; &gt;&gt;      ctypedef double cdouble &quot;double complex&quot;<br>
&gt;&gt; &gt;&gt;      cdef double creal(cdouble)<br>
&gt;&gt; &gt;&gt;      cdef double cimag(cdouble)<br>
&gt;&gt; &gt;&gt;      cdef cdouble _Complex_I<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; cdef inline cdouble  new_cdouble(double x, double y):<br>
&gt;&gt; &gt;&gt;      return x + _Complex_I*y<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Of course, the ctypedef is wrong, it will think it can go back to<br>
&gt;&gt; &gt;&gt; doubles (and Python objects) without any problem, but it works for<br>
&gt;&gt; &gt;&gt; now.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; THANKS! I think Cython will revolutionize my research work!<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; That&#39;s the goal :) Please cite us if it does.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; - Robert<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; Cython-dev mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:Cython-dev@codespeak.net">Cython-dev@codespeak.net</a><br>
&gt;&gt; &gt;&gt; <a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; Sent from my mobile device<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Vic Kelson<br>
&gt;&gt; &gt; <a href="mailto:vic.kelson@gmail.com">vic.kelson@gmail.com</a><br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; Cython-dev mailing list<br>
&gt;&gt; &gt; <a href="mailto:Cython-dev@codespeak.net">Cython-dev@codespeak.net</a><br>
&gt;&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;&gt; _______________________________________________<br>
&gt;&gt; Cython-dev mailing list<br>
&gt;&gt; <a href="mailto:Cython-dev@codespeak.net">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;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Vic Kelson<br>
&gt; <a href="mailto:vic.kelson@gmail.com">vic.kelson@gmail.com</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Cython-dev mailing list<br>
&gt; <a href="mailto:Cython-dev@codespeak.net">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>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
--<br>
</div></div>Lisandro Dalcín<br>
---------------<br>
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)<br>
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)<br>
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)<br>
PTLC - Güemes 3450, (3000) Santa Fe, Argentina<br>
Tel/Fax: +54-(0)342-451.1594<br>
<div><div></div><div class="h5">_______________________________________________<br>
Cython-dev mailing list<br>
<a href="mailto:Cython-dev@codespeak.net">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">vic.kelson@gmail.com</a><br>