473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
6 1918
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

"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
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

<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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Kyler Laird | last post by:
I need to submit C/C++ code for a class. (It's not a programming class. The choice of language is inertial. I think that it mostly serves to distract students from the course subject.) I'm...
1
by: Paul Prescod | last post by:
PyCon 2004 Slides on "Extending Python with Pyrex" PDF: http://www.prescod.net/pyrex/ExtendingPythonWithPyrex.pdf PPT: http://www.prescod.net/pyrex/ExtendingPythonWithPyrex.ppt Pycon 2004 Slides...
4
by: Kyler Laird | last post by:
I mentioned earlier that I started using Pyrex because I'm taking a computer vision course that requires all assignments to be submitted as C(++). While I could write C it would hurt me to do so...
1
by: Martin Bless | last post by:
Now that I've got my extension building machine using the VC++ Toolkit 2003 up and running I'm keen on using Pyrex (Pyrex-0.9.3, Python-2.4.0). But the definition of the swig_sources() method...
4
by: Luis P. Mendes | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'm trying to improve speed in a module and substituted the pythonic 'for in range()' for 'for i from min < i < max:' But, I need to...
7
by: ajikoe | last post by:
Hello, I have an idea to build python module to speed up python code in some of field where pyrex shines such as numeric, code which needs a lot of looping etc. What do you think? ...
27
by: Julien Fiore | last post by:
Do you wand to install Pyrex on Windows ? Here is a step-by-step guide explaining: A) how to install Pyrex on Windows XP. B) how to compile a Pyrex module. Julien Fiore, U. of Geneva
11
by: Jim Lewis | last post by:
Has anyone found a good link on exactly how to speed up code using pyrex? I found various info but the focus is usually not on code speedup.
7
by: Jim Lewis | last post by:
I'm trying to move a function into pyrex for speed. The python side needs to pass a list to the pyrex function. Do I need to convert to array or something so pyrex can generate tight code? I'm not...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.