[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Need Help with Distance Algorithm in Numeric



Kamilche <klachemin@xxxxxxxxxxx>:
>
> Wow, well, that did work, thanks! And it's about 3x faster! I'm so 
> bummed that I can't use it though, because for large amounts of data, it 
> fails with a 'couldn't allocate memory' error! Dang!

Yeah... Not sure if I mentioned that explicitly, but it's not really
efficient; the distance checks of everything-against-everything
allocates a matrix with n*m elements (where n is the number of
elements in one and m is the number of elements in the other). Not
scalable at all.

I've been trying to do similar things with numpy before, and you often
end up with this sort of thing. It's really not an algorithmic
catch-all package -- it has rather specific applications.

I guess using pyrex, psyco, blitz/weave, swig or simply hand-coding a
C extension/ufunc for your arrays would be the best thing, if speed is
important. (The easiest would quite certainly be using psyco, if
you're guaranteed to work only on x86 platforms. It seems to work very
well with arrays and integers.) You just have to install it and import
it, basically. (You could even import/activate it in a try/except
clause, to that users who don't have it only get a slightly slower
program.)

> I'm going to keep it around as reference though... maybe someday my
> data will be small enough to use this algorithm instead of doing it
> the hard way.

OK :)

> Thanks again, Magnus!

No problem.

-- 
Magnus Lie Hetland                    Fall seven times, stand up eight
http://hetland.org                                  [Japanese proverb]