473,746 Members | 2,569 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 1939
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
2038
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 sanity and satisfy the course requirements by programming in Python and converting the code to C. It...
1
1679
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: http://www.prescod.net/pyrex/OptimizingPythonWithPyrex.ppt I hope this helps me. Please report any mistakes.
4
2074
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 last assignment I saw several messages from someone having difficulty with segfaults due to memory...
1
3581
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
4254
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
1512
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
3978
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
1997
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
2048
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
9349
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9218
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8227
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6772
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6060
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4575
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.