[SciPy-dev] Bugfix for weave's catalog.

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu Jun 16 23:04:21 CDT 2005


>>>>> "Fernando" == Fernando Perez <Fernando.Perez at colorado.edu> writes:

    Fernando> Actually, I just checked and that stuff never made it to
    Fernando> SVN, so I don't have it.  Could you either commit it or
    Fernando> mail it to me so I can test and see if my fix also works
    Fernando> for your code?

Here is the script that shows the bug.  It is designed to compare the
performance of weave blitz versus numeric for repeated adds of a 2D
array

  x + x
  x + x + x
  x + x + x + x   ....and so on

On the second iteration through the loop (x+x+x), it issues a
"repairing catalog by removing key" and recompiles the extensions --
it doesn't do this for any other of the repeated add lines in this
loop.  This happens repeatedly if you rerun the script, so the cache
is being ignored.  Unfortunately, I only see this on my G4 powerbook
and not on my linux box, so it might be hard for others to use as a
test script.

Tomorrow I'll try and update scipy weave on my powerbook from CVS and
try it with and w/o your patch.

JDH

from __future__ import division
import sys, time
from Numeric import zeros, Float
from MLab import rand
import weave
from pylab import subplot, plot, show, legend, xlabel, ylabel, title


shape = 200,200
x = rand(*shape)


def repeat_nadds(Nadds, Nevals, useWeave):
    """
    Time the addition of i=2,Nadds arrays.  Evaluate each expression
    Nevals times to produce accurate timing results.  If useWeave is
    True, use weave to inline the addition, else use Numeric

    return value is n,t where n is a list of the the number of arrays
    added and t is the average time it took to add the arrays
    """
    results = []
    for i in range(2,Nadds):
        s = 'result = %s' % '+'.join(['x']*i)
        print 'evaluating: %s with weave=%s' % (s,useWeave)
        tstart = time.time()

        # only weave needs to predefine result array
        if useWeave: result= zeros(shape, typecode=Float)
        for j in range(Nevals):
            if useWeave:
                weave.blitz(s)
            else:
                exec(s)
        elapsed = (time.time()-tstart)/Nevals
        print '\tNadds=%d  Elapsed=%1.2f' % (i, elapsed)
        results.append( (i, elapsed) )
    return zip(*results)
        
Nadds = 7
Nevals = 20

# evaluate weave 
nw, tw = repeat_nadds(Nadds, Nevals, useWeave=True)
# evaluate Numeric
nn, tn = repeat_nadds(Nadds, Nevals, useWeave=False)

# plot weave versus Numeric
ax = subplot(111)
plot(nw, tw, 'go', nn, tn, 'bs')
legend( ('Weave', 'Numeric') )
xlabel('num adds')
ylabel('time (s)')
title('Numeric vs weave; repeated adds')
ax.set_xlim( (0, Nadds+1))
show()       









More information about the Scipy-dev mailing list