By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,738 Members | 1,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,738 IT Pros & Developers. It's quick & easy.

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

P: n/a
I just read "about Pyrex" at
http://www.cosc.canterbury.ac.nz/~gr...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
Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Se******@SeeBelow.Nut wrote:
I just read "about Pyrex" at
http://www.cosc.canterbury.ac.nz/~gr...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
Jul 18 '05 #2

P: n/a

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:ju********************@powergate.ca...
Se******@SeeBelow.Nut 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


Jul 18 '05 #3

P: n/a
Terry Reedy wrote:

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:ju********************@powergate.ca...
Se******@SeeBelow.Nut 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
Jul 18 '05 #4

P: n/a

<Se******@SeeBelow.Nut> wrote in message news:40***************@shaw.ca...
Terry Reedy wrote:

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:ju********************@powergate.ca...
Se******@SeeBelow.Nut 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


Jul 18 '05 #5

P: n/a
Se******@SeeBelow.Nut 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
Jul 18 '05 #6

P: n/a
Se******@SeeBelow.Nut wrote in message news:<40***************@shaw.ca>...
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
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.