<p dir="auto">Hello,</p>
<p dir="auto">When i run this simple portion of code</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
import numpy as np
from scipy.spatial import SphericalVoronoi, distance
from scipy.spatial import _spherical_voronoi as spherical_voronoi

test = np.array([[-0.1382177 , -0.66701253,  0.36649207],
       [-0.33718559, -0.0515926 ,  0.7109696 ],
       [-0.13633904, -0.65712506,  0.3830903 ],
       [ 0.04510981,  0.72285262,  0.35677763],
       [-0.14008791, -0.65997704,  0.37445958],
       [-0.7253343 , -0.26837762,  0.00655405],
       [-0.58085674, -0.40511863, -0.36093304],
       [ 0.2780397 ,  0.72729778,  0.24511902],
       [-0.33315233, -0.16453994, -0.6972229 ],
       [-0.46532148,  0.35901168, -0.45935981],
       [-0.72827086, -0.25884677, -0.00137087],
       [-0.72758263, -0.25989862,  0.00278446],
       [-0.70204518, -0.31395337, -0.0467136 ],
       [-0.71771464, -0.28226784, -0.01436788],
       [-0.72884793, -0.25239507,  0.01278218],
       [-0.72528059, -0.26018933, -0.00931674],
       [ 0.23175783, -0.68754004,  0.24004559],
       [ 0.69090723, -0.2371959 , -0.19492292],
       [ 0.40653046, -0.63173528, -0.25505239],
       [ 0.53203067, -0.52945865, -0.14520801],
       [ 0.52527016, -0.53501648, -0.2155609 ],
       [ 0.56226738, -0.31942141, -0.39975375]])
	   
sv = SphericalVoronoi(test)
sv.sort_vertices_of_regions()"><pre class="notranslate"><code class="notranslate">
import numpy as np
from scipy.spatial import SphericalVoronoi, distance
from scipy.spatial import _spherical_voronoi as spherical_voronoi

test = np.array([[-0.1382177 , -0.66701253,  0.36649207],
       [-0.33718559, -0.0515926 ,  0.7109696 ],
       [-0.13633904, -0.65712506,  0.3830903 ],
       [ 0.04510981,  0.72285262,  0.35677763],
       [-0.14008791, -0.65997704,  0.37445958],
       [-0.7253343 , -0.26837762,  0.00655405],
       [-0.58085674, -0.40511863, -0.36093304],
       [ 0.2780397 ,  0.72729778,  0.24511902],
       [-0.33315233, -0.16453994, -0.6972229 ],
       [-0.46532148,  0.35901168, -0.45935981],
       [-0.72827086, -0.25884677, -0.00137087],
       [-0.72758263, -0.25989862,  0.00278446],
       [-0.70204518, -0.31395337, -0.0467136 ],
       [-0.71771464, -0.28226784, -0.01436788],
       [-0.72884793, -0.25239507,  0.01278218],
       [-0.72528059, -0.26018933, -0.00931674],
       [ 0.23175783, -0.68754004,  0.24004559],
       [ 0.69090723, -0.2371959 , -0.19492292],
       [ 0.40653046, -0.63173528, -0.25505239],
       [ 0.53203067, -0.52945865, -0.14520801],
       [ 0.52527016, -0.53501648, -0.2155609 ],
       [ 0.56226738, -0.31942141, -0.39975375]])
	   
sv = SphericalVoronoi(test)
sv.sort_vertices_of_regions()
</code></pre></div>
<p dir="auto">I get the following error :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Python 2.7.12 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:42:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; from scipy.spatial import SphericalVoronoi, distance
&gt;&gt;&gt; from scipy.spatial import _spherical_voronoi as spherical_voronoi
&gt;&gt;&gt;
&gt;&gt;&gt; test = np.array([[-0.1382177 , -0.66701253,  0.36649207],
...        [-0.33718559, -0.0515926 ,  0.7109696 ],
...        [-0.13633904, -0.65712506,  0.3830903 ],
...        [ 0.04510981,  0.72285262,  0.35677763],
...        [-0.14008791, -0.65997704,  0.37445958],
...        [-0.7253343 , -0.26837762,  0.00655405],
...        [-0.58085674, -0.40511863, -0.36093304],
...        [ 0.2780397 ,  0.72729778,  0.24511902],
...        [-0.33315233, -0.16453994, -0.6972229 ],
...        [-0.46532148,  0.35901168, -0.45935981],
...        [-0.72827086, -0.25884677, -0.00137087],
...        [-0.72758263, -0.25989862,  0.00278446],
...        [-0.70204518, -0.31395337, -0.0467136 ],
...        [-0.71771464, -0.28226784, -0.01436788],
...        [-0.72884793, -0.25239507,  0.01278218],
...        [-0.72528059, -0.26018933, -0.00931674],
...        [ 0.23175783, -0.68754004,  0.24004559],
...        [ 0.69090723, -0.2371959 , -0.19492292],
...        [ 0.40653046, -0.63173528, -0.25505239],
...        [ 0.53203067, -0.52945865, -0.14520801],
...        [ 0.52527016, -0.53501648, -0.2155609 ],
...        [ 0.56226738, -0.31942141, -0.39975375]])
&gt;&gt;&gt; 
&gt;&gt;&gt; sv = SphericalVoronoi(test)
&gt;&gt;&gt; sv.sort_vertices_of_regions()
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/env/export/cns_n02_agc/agc/home/ggautrea/anaconda2/lib/python2.7/site-packages/scipy/spatial/_spherical_voronoi.py&quot;, line 319, in sort_vertices_of_regions
    ][0]
IndexError: list index out of range"><pre class="notranslate"><code class="notranslate">Python 2.7.12 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:42:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; from scipy.spatial import SphericalVoronoi, distance
&gt;&gt;&gt; from scipy.spatial import _spherical_voronoi as spherical_voronoi
&gt;&gt;&gt;
&gt;&gt;&gt; test = np.array([[-0.1382177 , -0.66701253,  0.36649207],
...        [-0.33718559, -0.0515926 ,  0.7109696 ],
...        [-0.13633904, -0.65712506,  0.3830903 ],
...        [ 0.04510981,  0.72285262,  0.35677763],
...        [-0.14008791, -0.65997704,  0.37445958],
...        [-0.7253343 , -0.26837762,  0.00655405],
...        [-0.58085674, -0.40511863, -0.36093304],
...        [ 0.2780397 ,  0.72729778,  0.24511902],
...        [-0.33315233, -0.16453994, -0.6972229 ],
...        [-0.46532148,  0.35901168, -0.45935981],
...        [-0.72827086, -0.25884677, -0.00137087],
...        [-0.72758263, -0.25989862,  0.00278446],
...        [-0.70204518, -0.31395337, -0.0467136 ],
...        [-0.71771464, -0.28226784, -0.01436788],
...        [-0.72884793, -0.25239507,  0.01278218],
...        [-0.72528059, -0.26018933, -0.00931674],
...        [ 0.23175783, -0.68754004,  0.24004559],
...        [ 0.69090723, -0.2371959 , -0.19492292],
...        [ 0.40653046, -0.63173528, -0.25505239],
...        [ 0.53203067, -0.52945865, -0.14520801],
...        [ 0.52527016, -0.53501648, -0.2155609 ],
...        [ 0.56226738, -0.31942141, -0.39975375]])
&gt;&gt;&gt; 
&gt;&gt;&gt; sv = SphericalVoronoi(test)
&gt;&gt;&gt; sv.sort_vertices_of_regions()
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/env/export/cns_n02_agc/agc/home/ggautrea/anaconda2/lib/python2.7/site-packages/scipy/spatial/_spherical_voronoi.py", line 319, in sort_vertices_of_regions
    ][0]
IndexError: list index out of range
</code></pre></div>
<p dir="auto">I use scipy 0.18.1.<br>
Can you help me ?</p>
<p dir="auto">Thank you.</p>
<p dir="auto">Hi all,</p>
<p dir="auto">It seems nquad has a memory leak when integrating a function implemented using ctypes. Here is the code that can be used to replicate this issue:</p>
<p dir="auto">Save this as testlib.c:</p>
<p dir="auto"><code class="notranslate">//testlib.c</code><br>
<code class="notranslate"># include &lt;math.h&gt;</code><br>
<code class="notranslate">double f(int n, double args[n]){</code><br>
<code class="notranslate">return pow(args[0], 2) - exp(args[1]) * args[2]; //corresponds to x0 - x1 * x2</code><br>
<code class="notranslate">}</code></p>
<p dir="auto">Compile the function:</p>
<p dir="auto"><code class="notranslate">gcc -shared -o testlib.so -fPIC testlib.c</code></p>
<p dir="auto">Run this in Python:</p>
<p dir="auto"><code class="notranslate">import ctypes</code><br>
<code class="notranslate">from scipy import integrate</code></p>
<p dir="auto"><code class="notranslate">lib = ctypes.CDLL('./testlib.so')</code><br>
<code class="notranslate">func = lib.f</code><br>
<code class="notranslate">func.restype = ctypes.c_double</code><br>
<code class="notranslate">func.argtypes = (ctypes.c_int, ctypes.c_double)</code></p>
<p dir="auto"><code class="notranslate">while True:</code><br>
<code class="notranslate">integrate.nquad(func, [[0, 10], [-10, 0], [-1, 1]])</code></p>
<p dir="auto">and use "top" to watch how the memory usage grows.</p>
<p dir="auto">Any chance for a quick fix?</p>
<p dir="auto">Cheers,</p>
<p dir="auto">Brani</p>