summaryrefslogtreecommitdiff
path: root/numpy/lib/src
diff options
context:
space:
mode:
authorDavid Warde-Farley <wardefar@iro.umontreal.ca>2011-09-18 03:29:03 -0400
committerDavid Warde-Farley <wardefar@iro.umontreal.ca>2011-09-18 03:29:03 -0400
commit6e4016fb251ffc20d3f1f57165b20735f368a2e2 (patch)
tree62641ac900130138e7121ed3deb080f1ab8c3adb /numpy/lib/src
parentaded70c4d02eec7a347af9868f1691dc49310f4d (diff)
downloadnumpy-6e4016fb251ffc20d3f1f57165b20735f368a2e2.tar.gz
ENH: release the GIL in some C library functions.
Sandwich certain potentially long running for loops that don't touch any Python objects between NPY_BEGIN_ALLOW_THREADS and NPY_END_ALLOW_THREADS so that the interpreter can potentially schedule another Python thread.
Diffstat (limited to 'numpy/lib/src')
-rw-r--r--numpy/lib/src/_compiled_base.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c
index dd8cea16b..fcb39784c 100644
--- a/numpy/lib/src/_compiled_base.c
+++ b/numpy/lib/src/_compiled_base.c
@@ -159,8 +159,10 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
goto fail;
}
ians = (npy_intp *)(PyArray_DATA(ans));
+ NPY_BEGIN_ALLOW_THREADS;
for (i = 0; i < len; i++)
ians [numbers [i]] += 1;
+ NPY_END_ALLOW_THREADS;
Py_DECREF(lst);
}
else {
@@ -181,9 +183,11 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
goto fail;
}
dans = (double *)PyArray_DATA(ans);
+ NPY_BEGIN_ALLOW_THREADS;
for (i = 0; i < len; i++) {
dans[numbers[i]] += weights[i];
}
+ NPY_END_ALLOW_THREADS;
Py_DECREF(lst);
Py_DECREF(wts);
}
@@ -250,6 +254,7 @@ arr_digitize(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
}
if (lbins == 1) {
+ NPY_BEGIN_ALLOW_THREADS;
for (i = 0; i < lx; i++) {
if (dx [i] >= dbins[0]) {
iret[i] = 1;
@@ -258,18 +263,25 @@ arr_digitize(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
iret[i] = 0;
}
}
+ NPY_END_ALLOW_THREADS;
}
else {
+ NPY_BEGIN_ALLOW_THREADS;
m = monotonic_ (dbins, lbins);
+ NPY_END_ALLOW_THREADS;
if ( m == -1 ) {
+ NPY_BEGIN_ALLOW_THREADS;
for ( i = 0; i < lx; i ++ ) {
iret [i] = decr_slot_ ((double)dx[i], dbins, lbins);
}
+ NPY_END_ALLOW_THREADS;
}
else if ( m == 1 ) {
+ NPY_BEGIN_ALLOW_THREADS;
for ( i = 0; i < lx; i ++ ) {
iret [i] = incr_slot_ ((double)dx[i], dbins, lbins);
}
+ NPY_END_ALLOW_THREADS;
}
else {
PyErr_SetString(PyExc_ValueError,
@@ -548,6 +560,7 @@ arr_interp(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
}
slopes = (double *) PyDataMem_NEW((lenxp - 1)*sizeof(double));
+ NPY_BEGIN_ALLOW_THREADS;
for (i = 0; i < lenxp - 1; i++) {
slopes[i] = (dy[i + 1] - dy[i])/(dx[i + 1] - dx[i]);
}
@@ -567,6 +580,7 @@ arr_interp(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
}
}
+ NPY_END_ALLOW_THREADS;
PyDataMem_FREE(slopes);
Py_DECREF(afp);
Py_DECREF(axp);