473,581 Members | 6,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pyrex gets a perfect score.

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 allocation problems.
Grrr... Time spent messing with pointers is not advancing one's
understanding of computer vision.)

Here's one reaction I got on the subject:
1. How is your teacher going to react when you hand in obfuscated-ish
C code that depends on the whole Python interpreter _and_ PIL?


The bottom line is that I got a perfect score on all (seven) of my
homework assignments. At first, I spent way too much time on them -
figuring out how to use Pyrex and also just having fun exploring
possibilities that I wouldn't have considered if I'd used C. Later,
however, I found that I could start on the assignment the night
before it's due and complete it in time. In terms of time, it was
still a good investment over this short period.

Most important, I had fun doing these assignments and I learned a
lot from them. I am confident that I would not have accomplished
as much with C (from scratch).

Our project is going to require fast decoding of an image. My
homework solutions have been agonizingly slow. There's a lot of
room for optimizations and I'm looking forward to using Pyrex to
prototype in Python and then replace pieces with C as needed.

I can certainly see how Pyrex could serve nicely beyond academic
settings. Is it a way to sneak Python into projects that are
"strictly C"? Sure, it can work. Can it free the developer to
quickly experiment with new concepts without spending excessive
effort on programming? Definitely. Is speed and ease of
development sometimes more important than execution speed. Yup.
Can Pyrex be used effectively as a path to a native C solution?
We'll see, but I'm confident that it can.

Thank you, Pyrex!

--kyler
Jul 18 '05 #1
4 2068
....just curious...did you look at Elmer
(http://elmer.sourceforge.net)? Elmer generates a C interface to a
Python module. No knowledge of the Python/C API is necessary, and the
resulting C interface resembles (as close as possible) the underlying
Python interface. Take a look at:

http://elmer.sourceforge.net/examples.html

The Elmer examples in this presentation might be helpful too:

http://elmer.sourceforge.net/PyCon04/elmer_pycon04.html

...as well as the source code for the examples:

http://elmer.sourceforge.net/PyCon04/Elmer_PyCon04.tgz

Like you mentioned, since the underlying code is Python, it will
not be as fast as C. However, Elmer allows you to easily prototype
new functionality in Python and later re-write it in C for speed,
similar to what you said. The C interface looks "native", and the
generated header file can even be re-used in most cases when/if you
re-write in C.

The presentation & example code has a C++ example, showing how
Python classes and types can be used "seamlessly " in C++ too.
Kyler Laird <Ky***@news.Lai rds.org> wrote in message news:<lh******* *****@snout.lai rds.org>...
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 allocation problems.
Grrr... Time spent messing with pointers is not advancing one's
understanding of computer vision.)

Here's one reaction I got on the subject:
1. How is your teacher going to react when you hand in obfuscated-ish
C code that depends on the whole Python interpreter _and_ PIL?


The bottom line is that I got a perfect score on all (seven) of my
homework assignments. At first, I spent way too much time on them -
figuring out how to use Pyrex and also just having fun exploring
possibilities that I wouldn't have considered if I'd used C. Later,
however, I found that I could start on the assignment the night
before it's due and complete it in time. In terms of time, it was
still a good investment over this short period.

Most important, I had fun doing these assignments and I learned a
lot from them. I am confident that I would not have accomplished
as much with C (from scratch).

Our project is going to require fast decoding of an image. My
homework solutions have been agonizingly slow. There's a lot of
room for optimizations and I'm looking forward to using Pyrex to
prototype in Python and then replace pieces with C as needed.

I can certainly see how Pyrex could serve nicely beyond academic
settings. Is it a way to sneak Python into projects that are
"strictly C"? Sure, it can work. Can it free the developer to
quickly experiment with new concepts without spending excessive
effort on programming? Definitely. Is speed and ease of
development sometimes more important than execution speed. Yup.
Can Pyrex be used effectively as a path to a native C solution?
We'll see, but I'm confident that it can.

Thank you, Pyrex!

--kyler

Jul 18 '05 #2
rl******@silico nmetrics.com (Rick Ratzel) writes:
...just curious...did you look at Elmer
(http://elmer.sourceforge.net)?


I hadn't. (I'm partial to Debian packages.)

The description "Elmer is not a Python-to-C or Python-to-Tcl
translator" makes me think that it's not appropriate for what I need
right now - the ability to submit only C code.

It does look like it would be useful for later work though. I think
it's likely to provide cleaner interfaces than what I was able to
generate using Pyrex.

Thank you.

--kyler
Jul 18 '05 #3
Kyler Laird wrote:
rl******@silico nmetrics.com (Rick Ratzel) writes:

...just curious...did you look at Elmer
(http://elmer.sourceforge.net)?

I hadn't. (I'm partial to Debian packages.)

The description "Elmer is not a Python-to-C or Python-to-Tcl
translator" makes me think that it's not appropriate for what I need
right now - the ability to submit only C code.

It does look like it would be useful for later work though. I think
it's likely to provide cleaner interfaces than what I was able to
generate using Pyrex.

Thank you.

--kyler


Does it help ?

http://sourceforge.net/projects/py2cmod

Yermat

Jul 18 '05 #4
Kyler Laird <Ky***@news.Lai rds.org> wrote in message news:<qr******* *****@snout.lai rds.org>...
The description "Elmer is not a Python-to-C or Python-to-Tcl
translator" makes me think that it's not appropriate for what I need
right now - the ability to submit only C code.
Thats a good point. In that case, you would use the "-frozen" flag
for Elmer, which uses freeze.py (if available on your system) to
freeze the Python sources into C strings, which are compiled into your
executable/archive. I emphasized that it is not a translator since
the Python interpreter is still required in all cases. While the
Elmer-generated C code is readable, the C files consisting of strings
of Python op codes that freeze generates are not...so that may be a
problem if you have to deliver readable code. I've never had that
problem since I only deliver .a files.

I once delivered a Python module to a C user (who has no working
knowledge of Python...a similar sounding situation to what you had, I
think) by using "Elmer -frozen" and combining the frozen C code,
Elmer-generated C code, and Python library all into a single archive.
They simply #included the generated header and linked in the archive
and were off and running...they didn't know they were using Python
until I told them...well, they may have been clued in by the fact that
I could deliver a platform-independent and easy-to-maintain module in
record time ;)
It does look like it would be useful for later work though. I think
it's likely to provide cleaner interfaces than what I was able to
generate using Pyrex.


The idea was that a Python developer could share their code with
C/C++ and Tcl users with minimal effort. The API to their Python
module in C or Tcl resembles, as close as possible, the same API they
use in Python. Please let me know if you do decide to use it in a
future project as I would love the feedback. Thanks!
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2287
by: Gary Stephenson | last post by:
I'm getting a clean generate, compile and link from my .pyx script, but when I attempt to run the resultant .exe, I get: "The procedure entry point Py_NoneStruct could not be located in the dynamic link library python23.dll" Can anybody provide me with a clue here? I've already cut down my script to remove all references to None,...
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:...
6
1932
by: SeeBelow | last post by:
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. ...
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
1635
by: Carl | last post by:
I have recently started to use Pyrex and am amazed by it's useability. Are there any alternatives to Pyrex? One thing that I haven't figured out is how to embed pure C/C++ source code into Pyrex. For example, if you have a bunch of C files that you want to use together with some Python code snippets, how do you practically achieve this...
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
1977
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
2038
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
7854
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
8134
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. ...
1
7880
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8157
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...
0
6539
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
5665
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
3807
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1394
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.