Pyrex praise (repeat)

Fernando Perez fperez528 at
Tue Aug 6 23:50:56 CEST 2002

Terry Hancock wrote:

> 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!

It may be possible to write the operations you need in Numeric, though it's 
hard to say without knowing the details. Another option (much easier than 
writing raw extensions) is using weave from scipy. It's amazing and 
incredibly easy to use.

Those are just options to consider in addition to pyrex, only you can make 
the final call as to which one suits your problem best.



More information about the Python-list mailing list