Pyrex - The speed of Python with the clarity of C?

Discussion in 'Python' started by SeeBelow@SeeBelow.Nut, May 21, 2004.

  1. Guest

    I just read "about Pyrex" at
    http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/version/Doc/About.html

    It seems that it is not compiled into machine code, as C would be, and
    therefore it does not offer the only valid reason for using C, which is
    for an increase in execution speed. The word "speed" does not appear on
    the above web page.

    Am I wrong about this? Perhaps I don't understand how Pyrex works.

    At ANNEvolve we are beginning to use Python, and we are learning how to
    call C functions, which is a requirement for us, because neuroevolution
    code often must run for many hours, even when it is pure C.

    Mitchell Timin

    --
    "Many are stubborn in pursuit of the path they have chosen, few in
    pursuit of the goal." - Friedrich Nietzsche

    http://annevolve.sourceforge.net is what I'm into nowadays.
    Humans may write to me at this address: zenguy at shaw dot ca
     
    , May 21, 2004
    #1
    1. Advertising

  2. Peter Hansen Guest

    wrote:

    > I just read "about Pyrex" at
    > http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/version/Doc/About.html
    >
    > It seems that it is not compiled into machine code, as C would be, and
    > therefore it does not offer the only valid reason for using C, which is
    > for an increase in execution speed. The word "speed" does not appear on
    > the above web page.
    >
    > Am I wrong about this? Perhaps I don't understand how Pyrex works.


    Look at the primes.pyx example. There's a link just below it
    (above the Language Details section) showing the C code it is
    compiled to (and which is in turn compiled to machine code). True,
    there are many calls to the Python/C interface APIs, but there is
    also "pure" C code in there.

    For ultimate speed (barring assembly, of course, or dedicated
    hardware), you probably still want a C extension or library, but
    Pyrex is much simpler in many cases, and preserves the Pythonesque
    syntax.

    -Peter
     
    Peter Hansen, May 21, 2004
    #2
    1. Advertising

  3. Terry Reedy Guest

    "Peter Hansen" <> wrote in message
    news:...
    > wrote:
    > > Am I wrong about this? Perhaps I don't understand how Pyrex works.

    >
    > Look at the primes.pyx example. There's a link just below it
    > (above the Language Details section) showing the C code it is
    > compiled to (and which is in turn compiled to machine code). True,
    > there are many calls to the Python/C interface APIs, but there is
    > also "pure" C code in there.


    In particular, lines 5-15 of the Python code, the 'guts' of the algorithm,
    are compiled to pure C with no interface calls.

    TJR
     
    Terry Reedy, May 21, 2004
    #3
  4. Guest

    Terry Reedy wrote:
    >
    > "Peter Hansen" <> wrote in message
    > news:...
    > > wrote:
    > > > Am I wrong about this? Perhaps I don't understand how Pyrex works.

    > >
    > > Look at the primes.pyx example. There's a link just below it
    > > (above the Language Details section) showing the C code it is
    > > compiled to (and which is in turn compiled to machine code). True,
    > > there are many calls to the Python/C interface APIs, but there is
    > > also "pure" C code in there.

    >
    > In particular, lines 5-15 of the Python code, the 'guts' of the algorithm,
    > are compiled to pure C with no interface calls.


    But does this C code get compiled into machine code? If so, What
    compiler does that, and when?

    Thanks,

    m

    --
    "Many are stubborn in pursuit of the path they have chosen, few in
    pursuit of the goal." - Friedrich Nietzsche

    http://annevolve.sourceforge.net is what I'm into nowadays.
    Humans may write to me at this address: zenguy at shaw dot ca
     
    , May 22, 2004
    #4
  5. Terry Reedy Guest

    <> wrote in message news:...
    > Terry Reedy wrote:
    > >
    > > "Peter Hansen" <> wrote in message
    > > news:...
    > > > wrote:
    > > > > Am I wrong about this? Perhaps I don't understand how Pyrex works.
    > > >
    > > > Look at the primes.pyx example. There's a link just below it
    > > > (above the Language Details section) showing the C code it is
    > > > compiled to (and which is in turn compiled to machine code).


    To repeat: 'and which is in turn compiled to machine code'.

    > > In particular, lines 5-15 of the Python code, the 'guts' of the

    algorithm,
    > > are compiled to pure C with no interface calls.

    >
    > But does this C code get compiled into machine code?


    I don't understand why you are asking this again when Peter answered so
    clearly. As you said in your first post, there would otherwise be no point
    to the translation to C.

    > If so, What compiler does that, and when?


    Better question. I do not have PyRex, so I do not know the details.
    Either PyRex call a C compiler itself, automatically, or it leave the C
    file for you to invoke the compiler. Or perhaps it gives you a choice.
    *nix systems come with a C compiler. The location should be part of the
    system data somewhere. On other systems, you might have to buy one and
    give PyRex the name and location. PyRex is an alternative to writing C
    code yourself, but not, I believe, an alternative to having a C compiler.

    Terry J. Reedy
     
    Terry Reedy, May 22, 2004
    #5
  6. wrote:

    > But does this C code get compiled into machine code?


    Yes.

    > If so, What compiler does that, and when?


    There's a small getting-started somewhere, I suggest you try that; it
    covers all that. I tried it a few weeks ago, and IIRC Pyrex creates some
    C code that you have to compile into a shared library with your favorite
    C compiler. The shared library can then be imported in Python as a module.

    --
    "Codito ergo sum"
    Roel Schroeven
     
    Roel Schroeven, May 22, 2004
    #6
  7. Giles Brown Guest

    wrote in message news:<>...
    > But does this C code get compiled into machine code? If so, What
    > compiler does that, and when?


    The pyrex installation provides distutils extensions. This lets
    you create a setup.py which compiles your .pyx files into .c files
    and then your .c files into .pyd modules. It really is extremely
    simple, but it does rely on having a C compiler set up that distutils
    can use.

    Best of luck,
    Giles
     
    Giles Brown, May 22, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?Q?Fran=E7ois?= Pinard

    Re: Pyrex without Python (was Re: calling Pyrex results from C)

    =?iso-8859-1?Q?Fran=E7ois?= Pinard, Jan 21, 2004, in forum: Python
    Replies:
    3
    Views:
    335
    A.M. Kuchling
    Jan 21, 2004
  2. Adonis
    Replies:
    11
    Views:
    434
    Dennis Lee Bieber
    Nov 5, 2004
  3. Chris Lambacher
    Replies:
    0
    Views:
    686
    Chris Lambacher
    Jun 8, 2005
  4. Jim Lewis

    Pyrex speed

    Jim Lewis, May 27, 2006, in forum: Python
    Replies:
    11
    Views:
    1,218
  5. Greg Ewing
    Replies:
    2
    Views:
    377
    Dieter Maurer
    Jun 29, 2006
Loading...

Share This Page