I did the first one. I just wanted to make sure that it was resolved at
compile time.

THANKS!
--v

On Mon, Apr 6, 2009 at 12:19 PM, Lisandro Dalcin <[email protected]> wrote:

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



-- 
Vic Kelson
[email protected]
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to