somebody stop me

Pete Shinners pete at visionart.com
Wed Jun 14 15:57:44 EDT 2000


Pete Shinners wrote: 
> i have this routine which is running pretty quick
> on my machine. i may be getting overly greedy, but
> if i could shave off more time i'd be pleased
> (btw, this is with numeric python)
> (btw2, WIDTH and SAMPLES are defined elsewhere as global)
> 
> def pumpmeup_func(img):
>     rndpos = RandomArray.uniform(0, WIDTH, SAMPLES).astype(Int)
>     rndcol = RandomArray.uniform(100, 255, SAMPLES).astype(Int)
>     for x, color in map(None, rndpos, rndcol):
>         img[x,-3:-1] = color
> 
> - creating a list/array of the slices and then use numpy
>   to assign the random colors to that?  (like to see this!)
> 
> ...from .045 seconds per call, down to around .013


ok, i'm replying to myself. (ps, not crazy) but i was able
to crunch some more time off function call. the trick was
indeed the "list of slices". here's my latest version, down
from the previous optimized .013 to .009

def pumpmeup_func(img):
    rndpos = RandomArray.uniform(1, WIDTH-2, 100).astype(Int)
    rndcol = RandomArray.uniform(100, 255, 100).astype(Int)
    carved = array(map(lambda x,f=img: f[x,-3:], rndpos))
    carved[:,0] = rndcol
    carved[:,1] = rndcol
  
urgh, how do i clean up those last two lines into one?
i have a feeling the array(map(lambda...))) is doing
some extraneous work. most of my previous optimization ideas
are still open, can anyone drill this down another notch? 

woohoo, i'm my own best guru   :]



More information about the Python-list mailing list