473,320 Members | 2,104 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,320 software developers and data experts.

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 2047
....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.Lairds.org> wrote in message news:<lh************@snout.lairds.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******@siliconmetrics.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******@siliconmetrics.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.Lairds.org> wrote in message news:<qr************@snout.lairds.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
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...
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...
6
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...
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: 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...
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.