Python crash after using weave inline

Peter Wang misterwang at gmail.com
Wed Apr 18 16:07:00 EDT 2007


Soren,

For future reference, you might want to direct weave-related questions
to the scipy-user at scipy.org 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




More information about the Python-list mailing list