Kamilche wrote:
Jakub Piotr Cłapa wrote:
Kamilche wrote:
I make heavy use of Numeric in my sprite engine.
When I did the following, I was able to 'drop in' numpy as a replacement, but it took 3x longer to load my complex graphics! :-O

Maybe you could offer a reduced test case so we could check this? I'm sure numpy developers would also be interested...


Sure, here it is. It's a total hack using global variables, but it works. Numeric takes 1 second, numpy takes 2.6, doing the same operations to the same picture.

--Kamilche




import Numeric
import numpy
[snip some code]

def TestNumeric():
    global pic2
    pic2 = GetPic()
    array = pygame.surfarray.array3d(pic2).astype(Numeric.Int)
    alphaarray = pygame.surfarray.array_alpha(pic).astype(Numeric.UInt8)
    starttime = time.time()
    for i in range(10):
        array[:, :] = Numeric.clip(array + [20, 0, 0], 0, 255)
        pygame.surfarray.blit_array(pic2, array)
        pygame.surfarray.pixels_alpha(pic2)[:, :] = alphaarray
        Update()
    print 'Numeric time: %f seconds' % (time.time() - starttime)

def TestNumpy():
    global pic2
    pic2 = GetPic()
    array = pygame.surfarray.array3d(pic2).astype(numpy.int)
alphaarray = pygame.surfarray.array_alpha(pic).astype(numpy.unsignedinteger)
    starttime = time.time()
    for i in range(10):
        array[:, :] = numpy.clip(array + [20, 0, 0], 0, 255)
        pygame.surfarray.blit_array(pic2, array)
        pygame.surfarray.pixels_alpha(pic2)[:, :] = alphaarray
        Update()
    print 'numpy time:   %f seconds' % (time.time() - starttime)

Check out the types of array and alphaarray in TestNumpy(). Very informative. They are both Numeric arrays. All that is accomplished is that numpy.clip is called on one. It probably just treats it as an iterable.

--
Lenard Lindstrom
<[EMAIL PROTECTED]>

Reply via email to