Hello, I'm a new scipy user, and I'm trying to speed up some array code with weave. I'm running xp with gcc from cgywin, and scipy.weave.test() returns an OK status.
I'm trying to speed up the code below. I've found a couple of examples of weave on the web, and I think it should be straight forward, but I keep getting the following error when calling weave.blitz(expr). It's complaining about the variable being assigned, I've tried listing it in the blitz call with no luck. Any help is appreciated. PS I've also posted to scipy.org Thank you, Frank ***ERROR*** Traceback (most recent call last): File "D:/Documents/Homework/MTMG310/Project/hw6r3VectorizeWeave.py", line 436, in -toplevel- prof.runcall(main) File "C:\Python24\Lib\hotshot\__init__.py", line 76, in runcall return self._prof.runcall(func, args, kw) File "D:/Documents/Homework/MTMG310/Project/hw6r3VectorizeWeave.py", line 383, in main findw(w,wprior,phiprior,uprior,vprior) File "D:/Documents/Homework/MTMG310/Project/hw6r3VectorizeWeave.py", line 136, in findw weave.blitz(expr) File "C:\Python24\Lib\site-packages\scipy\weave\blitz_tools.py", line 35, in blitz if check_size and not size_check.check_expr(expr,local_dict,global_dict): File "C:\Python24\Lib\site-packages\scipy\weave\size_check.py", line 51, in check_expr exec(expr,values) File "<string>", line 1 wnext[1:grows-1,1:gcols-1] =( alpha * w[1:grows-1,1:gcols-1] + ax * (w[1:grows-1,0:gcols-2] + w[1:grows-1,2:gcols]) + ^ SyntaxError: invalid syntax ***CODE*** def findw(wnext,wprior,phiprior,uprior,vprior): #format here is x[i,j] where i's are rows, j's columns, use flipud() to get the #print out consistent with the spacial up-down directions #assign local names that are more #inline with the class notation w = wprior phi = phiprior u = uprior v = vprior #three of the BC are known so just set them #symetry plane wnext[0,0:gcols] = 0.0 #upper wall wnext[gN,0:gcols] = 2.0/gdy**2 * (phi[gN,0:gcols] - phi[gN-1,0:gcols]) #inlet, off the walls wnext[1:grows-1,0] = 0.0 upos = where(u>0) vpos = where(v>0) Sx = ones_like(u) Sx[upos] = 0.0 xSx = 1.0 - Sx Sy = ones_like(v) Sy[vpos] = 0.0 ySy = 1.0 - Sy uw = u*w vw = v*w ax = gnu*gdt/gdx**2 ay = gnu*gdt/gdy**2 dtdx = gdt/gdx dtdy = gdt/gdy alpha = (1.0 - 2.0*ax - 2.0*ay) #interior nodes expr = """ \ wnext[1:grows-1,1:gcols-1] =( alpha * w[1:grows-1,1:gcols-1] + ax * (w[1:grows-1,0:gcols-2] + w[1:grows-1,2:gcols]) + ay * (w[0:grows-2,1:gcols-1] + w[2:grows,1:gcols-1]) - dtdx * (xSx[1:grows-1,1:gcols-1] * (uw[1:grows-1,1:gcols-1] - uw[1:grows-1,0:gcols-2]) - Sx[1:grows-1,1:gcols-1] * (uw[1:grows-1,2:gcols] - uw[1:grows-1,1:gcols-1])) - dtdy * (ySy[1:grows-1,1:gcols-1] * (vw[1:grows-1,1:gcols-1] - vw[1:grows-1,0:gcols-2]) - Sy[1:grows-1,1:gcols-1] * (vw[1:grows-1,2:gcols] - vw[1:grows-1,1:gcols-1])) ) """ #weave.inline(expr,['wnext','w','Sx','xSx','Sy','ySy','uw','vw','ax','ay','dtdx','dtdy','alpha','grows','gcols']) #weave.inline(expr,['wnext'],compiler='gcc',verbose=2) #weave.blitz(expr,['wnext','w','Sx','xSx','Sy','ySy','uw','vw','ax','ay','dtdx','dtdy','alpha','grows','gcols']) #weave.blitz(expr,size_check=1) #weave.inline(expr,['wnext']) weave.blitz(expr) ## for j in range(1,gasizej-1): ## for i in range(1,gasizei-1): ## ## wnext[i,j] =( w[i,j] + gnu*gdt/gdx**2 * (w[i,j-1] - 2.0*w[i,j] + w[i,j+1]) + ## gnu*gdt/gdy**2 * (w[i-1,j] - 2.0*w[i,j] + w[i+1,j]) - ## (1.0 - Sx[i,j]) * gdt/gdx * (uw[i,j] - uw[i,j-1]) - ## Sx[i,j] * gdt/gdx * (uw[i,j+1] - uw[i,j]) - ## (1.0 - Sy[i,j]) * gdt/gdy * (vw[i,j] - vw[i-1,j]) - ## Sy[i,j] * gdt/gdy * (vw[i+1,j] - vw[i,j]) ) ## print "***wnext****" ## print "i: ", i, "j: ", j, "wnext[i,j]: ", wnext[i,j] #final BC at outlet, off walls wnext[1:grows-1,gM] = wnext[1:grows-1,gM-1] -- http://mail.python.org/mailman/listinfo/python-list