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