473,574 Members | 17,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1931
Se******@SeeBel ow.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******** ************@po wergate.ca...
Se******@SeeBel ow.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******** ************@po wergate.ca...
Se******@SeeBel ow.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******@SeeBe low.Nut> wrote in message news:40******** *******@shaw.ca ...
Terry Reedy wrote:

"Peter Hansen" <pe***@engcorp. com> wrote in message
news:ju******** ************@po wergate.ca...
Se******@SeeBel ow.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******@SeeBel ow.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******@SeeBel ow.Nut wrote in message news:<40******* ********@shaw.c a>...
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
2028
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 fairly fluent with C but it hurts to think about writing in C when Python is *so* much more appropriate for these operations. I'd like to keep my...
1
1666
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 on "Optimizing Python code with Pyrex" PDF: http://www.prescod.net/pyrex/OptimizingPythonWithPyrex.pdf PPT:...
4
2068
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 and certainly distract me from the computer vision aspects. I like using Python these days and Pyrex looked like a good solution. (BTW, on the...
1
3575
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 seems to have changed. When I try to build the examples from Pyrex I get a TypeError: c:\Pyrex-0.9.3\Demos> python Setup.py build_ext --inplace
4
4250
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 define a step for the i variable. How can I do it?
7
1505
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? Sincerely Yours, pujo
27
3957
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
1976
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
2037
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 clear how to do this.
0
7820
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8081
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8258
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6486
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5635
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5325
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3777
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.