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

S

SeeBelow

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
 
P

Peter Hansen

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
 
T

Terry Reedy

Peter Hansen said:
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
 
S

SeeBelow

Terry said:
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
 
T

Terry Reedy

To repeat: 'and which is in turn compiled to machine code'.
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
 
R

Roel Schroeven

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.
 
G

Giles Brown

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top