Skip to content

Instantly share code, notes, and snippets.

View MarcCote's full-sized avatar

Marc-Alexandre Côté MarcCote

View GitHub Profile
@MarcCote
MarcCote / cumsum_leak.py
Last active August 29, 2015 13:56
Gist showing a potential memory leak when using the 'out' parameter of PyArray_CumSum of the numpy's C-api.
import resource
import numpy as np
from scipy import weave
x = np.ones(1e6, dtype=np.float32)
# There is no memory leak, when we let PyArray_CumSum creates the output array, i.e. when out=NULL.
code_good = r"""
npy_intp shape[1] = { PyArray_SIZE(x_array) };
int dtype = PyArray_DTYPE(x_array)->type_num;