[SciPy-user] How to free memory allocated to array in weave.inline?

Gael Varoquaux gael.varoquaux@normalesup....
Sun Aug 26 07:34:10 CDT 2007

On Sun, Aug 26, 2007 at 11:25:37AM +1200, Angus McMorland wrote:
> Thanks Gaël, that sounds like a very sensible suggestion, but I'm
> having trouble getting it to work. The following causes a segfault. Am
> I doing something stupid?

> If I understand the manual correctly, the weave code should alter the
> array in-place, so I don't need to use return_val for that one. Is
> that correct?

Hell, I don't use inline much and I have never read the manual (Uh Oh,
may I should keep that secret).

Here is code that works for me:

from scipy import weave
from numpy import *

def my_array(shape):
    nx, ny = shape
#    ar = empty(shape)
    ar = ones(shape)
    code = """
    for (int i=1; i<nx; ++i) {
        for (int j=1; j<ny; ++j) {
            ar(i, j) = (double) i*j ;
    weave.inline( code, ['ar', 'nx', 'ny'],
                    type_converters=weave.converters.blitz, )
    return ar
a = my_array((4, 4))
print a

What really bothers me is that it does not work if I use empty instead of
ones. It must be due to a type problem, probably the blitz converters not
guessing properly the type of the input array, but I'd really appreciate
some better explaination of that, and some info on the right way to use
empty with inline.



More information about the SciPy-user mailing list