By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,538 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,538 IT Pros & Developers. It's quick & easy.

Pyrex gets a perfect score.

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
....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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.