Re: Python crash after using weave inline
On Apr 18, 10:07 pm, Peter Wang <[EMAIL PROTECTED]> wrote: > Soren, > > For future reference, you might want to direct weave-related questions > to the [EMAIL PROTECTED] mailing list. > > > def cartPolFast(xlen, ylen, x_c, y_c): > > > res = zeros((xlen,ylen)) > > > code = """ > > { > > int xlen, ylen, x_c, y_c; > > This line is unnecessary, because weave exposes those variables inside > the local scope of your code. This also makes the braces at the top > and bottom of the code block unnecessary. > > > for( x = 0; x == xlen; x++) > >for( y = 0; y == ylen; y++) > > rel_x = x-x_c; > > rel_y = y_c-y; > > > res(x,y) = rel_y*rel_y; > > } > > Two things: > 1. You need to put curly braces around the three lines of the inner > loop. > 2. You need to change "x == xlen" and "y == ylen" to "x < xlen" and "y > < ylen". > > I made these modifications to your code and it runs fine on my machine > (macbook pro, OS 10.4, scipy 0.5.2.dev2314). > > -peter Thanks alot Peter! I'm a bit rusty on the C! :) Soren -- http://mail.python.org/mailman/listinfo/python-list
Re: Python crash after using weave inline
Soren, For future reference, you might want to direct weave-related questions to the [EMAIL PROTECTED] mailing list. > def cartPolFast(xlen, ylen, x_c, y_c): > > res = zeros((xlen,ylen)) > > code = """ > { > int xlen, ylen, x_c, y_c; This line is unnecessary, because weave exposes those variables inside the local scope of your code. This also makes the braces at the top and bottom of the code block unnecessary. > for( x = 0; x == xlen; x++) >for( y = 0; y == ylen; y++) > rel_x = x-x_c; > rel_y = y_c-y; > > res(x,y) = rel_y*rel_y; > } Two things: 1. You need to put curly braces around the three lines of the inner loop. 2. You need to change "x == xlen" and "y == ylen" to "x < xlen" and "y < ylen". I made these modifications to your code and it runs fine on my machine (macbook pro, OS 10.4, scipy 0.5.2.dev2314). -peter -- http://mail.python.org/mailman/listinfo/python-list
Python crash after using weave inline
Hi, I have a strange and very annoying problem when using weave in scipy.. when I run the code below.. the first time it needs to compile.. it says and then python.exe crashes! and no result is shown.. the second time i run it, it does not compile but gives the completely wrong answer.. prints a matrix of all zeros except for point 1,1 in the matrix which seems to have some random high number like -5.39403959e+08. !!?? Basicly I run through a 10 by 10 matrix do some calculations with respect to some center values x_c and y_c and insert the result into the empty numpy matrix array "res". Any help is appreciated! Thanks, Sroren from numpy import * from scipy import weave from scipy.weave import converters def cartPolFast(xlen, ylen, x_c, y_c): res = zeros((xlen,ylen)) code = """ { int xlen, ylen, x_c, y_c; double rel_x, rel_y; int x, y; for( x = 0; x == xlen; x++) for( y = 0; y == ylen; y++) rel_x = x-x_c; rel_y = y_c-y; res(x,y) = rel_y*rel_y; } """ weave.inline(code,['xlen','ylen','x_c','y_c','res'], type_converters=converters.blitz, compiler="gcc") return res if __name__ == "__main__": tst = cartPolFast(10,10,5,5) print tst -- http://mail.python.org/mailman/listinfo/python-list