Pyrex praise (repeat)

Terry Hancock hancock at anansispaceworks.com
Tue Aug 6 22:07:11 CEST 2002


"Mike Rovner" <mike at bindkey.com>
> "François Pinard" <pinard at iro.umontreal.ca> wrote in message
> news:oq7kj4yx81.fsf at titan.progiciels-bpi.ca...
> ...
> > A final point, which looks important to me, is that any good wrapping of a
> > pre-existing C library is best done while giving a Python flavour to the
> > interface, would it be only for a nicer and natural object orientation.
> ...
> 
> That is completely true.
> Pyrex is my language of choice for wrapping pretty complex set of C
> interfaces written in a totally not-OO style in a nifty OO Python interface.
> I choose Pyrex for that very reasons Francois described. It gave me total
> control and uniformity of my program.
> The only small addition I made is handling array of structures and I believe
> that soon can be handled inside Pyrex itself. Greg is doing very good job.

I'm wondering if Pyrex is for me --

For a game AI project I was working on awhile back I was
trying to implement a theoretical model of character agent
emotions. Anyway, it involved "fusing" a set of emotions
(i.e. a Python list containing emotion objects, which are
4-vectors in the model, presumeably tuples of floats, or
perhaps tuples of a saturating "vague number" type, like a
fuzzy logic value).  "Fusing" is basically "summing",
except the procedure is non-linear (they don't follow
simple vector addition, and the elements are not treated
symmetrically -- I think this rules out Numeric, though
I haven't proven that to myself yet).

I tried a pure-python implementation, but there didn't
seem to be any way to do it without just looping through all
the list members, and this took an awful long time to run.
(Too long for the game).

So I started working on a C implementation, but it's a real
pain.  It's conceptually very object-oriented, with tiny
snippets of math code required, but the overhead of using
something like C++ seems prohibitive (why write all of that
in C++ when I'm only going to use it in Python?).  Also,
I've written maybe 200 lines of C++ in my life, and so
many people bad-mouth it, I'm wondering if I should bother
with it.

Also, I need to do a fast loop through the Python list, I
think, so I need it to integrate well with Python, and I
don't really want to recode any basic Python types!

So I tried to get a handle on the Python/C API, but I don't
quite see it yet -- I've read some of the documentation,
but it hasn't really become clear to me how to get started,
and I have the feeling the result is going to be kind of
clunky (from the development point of view -- lots of lines
of code).

Should I chuck it, and learn Pyrex instead?  I've seen
a few snippets of pyrex, and it looks kind of promising. My
impression is that it might be good for this project --
embedding small amounts of C code into a Python object
model.  Or should I just plow through my resistance on
the Python/C API? (Maybe the wall's not as thick as it
looks?).  What does either of them do to your build/distribution
complexity?  (I.e. can I use distutils with either --
I've never used it, but I plan to someday :-) ).

I kind of dropped the project, but if I saw an easier way
to proceed, I might want to pick it up again.

Obviously this is all subjective -- just looking for
some opinions.

Thanks,
Terry

-- 
------------------------------------------------------
Terry Hancock
hancock at anansispaceworks.com       
Anansi Spaceworks                 
http://www.anansispaceworks.com 
P.O. Box 60583                     
Pasadena, CA 91116-6583
------------------------------------------------------




More information about the Python-list mailing list