summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/code_generators/ufunc_docstrings.py2
-rw-r--r--numpy/core/src/umath/_umath_tests.c.src49
-rw-r--r--numpy/core/src/umath/ufunc_object.c4
-rw-r--r--numpy/lib/_iotools.py4
-rw-r--r--numpy/lib/tests/test__iotools.py5
5 files changed, 47 insertions, 17 deletions
diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py
index bd90d0460..f7d58a26f 100644
--- a/numpy/core/code_generators/ufunc_docstrings.py
+++ b/numpy/core/code_generators/ufunc_docstrings.py
@@ -3365,7 +3365,7 @@ add_newdoc('numpy.core.umath', 'sinh',
add_newdoc('numpy.core.umath', 'sqrt',
"""
- Return the positive square-root of an array, element-wise.
+ Return the non-negative square-root of an array, element-wise.
Parameters
----------
diff --git a/numpy/core/src/umath/_umath_tests.c.src b/numpy/core/src/umath/_umath_tests.c.src
index 76af40439..2a74c1aaa 100644
--- a/numpy/core/src/umath/_umath_tests.c.src
+++ b/numpy/core/src/umath/_umath_tests.c.src
@@ -271,7 +271,7 @@ static char euclidean_pdist_signatures[] = { NPY_FLOAT, NPY_FLOAT,
NPY_DOUBLE, NPY_DOUBLE };
-static void
+static int
addUfuncs(PyObject *dictionary) {
PyObject *f;
@@ -280,6 +280,13 @@ addUfuncs(PyObject *dictionary) {
"inner on the last dimension and broadcast on the rest \n"
" \"(i),(i)->()\" \n",
0, inner1d_signature);
+ /*
+ * yes, this should not happen, but I (MHvK) just spent an hour looking at
+ * segfaults because I screwed up something that seemed totally unrelated.
+ */
+ if (f == NULL) {
+ return -1;
+ }
PyDict_SetItemString(dictionary, "inner1d", f);
Py_DECREF(f);
f = PyUFunc_FromFuncAndDataAndSignature(innerwt_functions, innerwt_data,
@@ -287,6 +294,9 @@ addUfuncs(PyObject *dictionary) {
"inner1d with a weight argument \n"
" \"(i),(i),(i)->()\" \n",
0, innerwt_signature);
+ if (f == NULL) {
+ return -1;
+ }
PyDict_SetItemString(dictionary, "innerwt", f);
Py_DECREF(f);
f = PyUFunc_FromFuncAndDataAndSignature(matrix_multiply_functions,
@@ -295,6 +305,9 @@ addUfuncs(PyObject *dictionary) {
"matrix multiplication on last two dimensions \n"
" \"(m,n),(n,p)->(m,p)\" \n",
0, matrix_multiply_signature);
+ if (f == NULL) {
+ return -1;
+ }
PyDict_SetItemString(dictionary, "matrix_multiply", f);
Py_DECREF(f);
f = PyUFunc_FromFuncAndDataAndSignature(euclidean_pdist_functions,
@@ -303,14 +316,22 @@ addUfuncs(PyObject *dictionary) {
"pairwise euclidean distance on last two dimensions \n"
" \"(n,d)->(p)\" \n",
0, euclidean_pdist_signature);
+ if (f == NULL) {
+ return -1;
+ }
PyDict_SetItemString(dictionary, "euclidean_pdist", f);
Py_DECREF(f);
f = PyUFunc_FromFuncAndDataAndSignature(inner1d_functions, inner1d_data,
inner1d_signatures, 2, 2, 1, PyUFunc_None, "inner1d_no_doc",
NULL,
0, inner1d_signature);
+ if (f == NULL) {
+ return -1;
+ }
PyDict_SetItemString(dictionary, "inner1d_no_doc", f);
Py_DECREF(f);
+
+ return 0;
}
@@ -417,15 +438,14 @@ static struct PyModuleDef moduledef = {
};
#endif
+/* Initialization function for the module */
#if defined(NPY_PY3K)
-#define RETVAL m
-PyMODINIT_FUNC PyInit__umath_tests(void)
+#define RETVAL(x) x
+PyMODINIT_FUNC PyInit__umath_tests(void) {
#else
-#define RETVAL
-PyMODINIT_FUNC
-init_umath_tests(void)
+#define RETVAL(x)
+PyMODINIT_FUNC init_umath_tests(void) {
#endif
-{
PyObject *m;
PyObject *d;
PyObject *version;
@@ -435,9 +455,9 @@ init_umath_tests(void)
#else
m = Py_InitModule("_umath_tests", UMath_TestsMethods);
#endif
- if (m == NULL)
- return RETVAL;
-
+ if (m == NULL) {
+ return RETVAL(NULL);
+ }
import_array();
import_ufunc();
@@ -448,12 +468,13 @@ init_umath_tests(void)
Py_DECREF(version);
/* Load the ufunc operators into the module's namespace */
- addUfuncs(d);
-
- if (PyErr_Occurred()) {
+ if (addUfuncs(d) < 0) {
+ Py_DECREF(m);
+ PyErr_Print();
PyErr_SetString(PyExc_RuntimeError,
"cannot load _umath_tests module.");
+ return RETVAL(NULL);
}
- return RETVAL;
+ return RETVAL(m);
}
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index af415362b..7548ffb87 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -2538,7 +2538,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc,
*/
core_dim_ixs_size = 0;
for (i = 0; i < nop; ++i) {
- core_dim_ixs_size += core_num_dims[i];
+ core_dim_ixs_size += ufunc->core_num_dims[i];
}
inner_strides = (npy_intp *)PyArray_malloc(
NPY_SIZEOF_INTP * (nop+core_dim_ixs_size));
@@ -2550,7 +2550,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc,
/* Copy the strides after the first nop */
idim = nop;
for (i = 0; i < nop; ++i) {
- int num_dims = core_num_dims[i];
+ int num_dims = ufunc->core_num_dims[i];
int core_start_dim = PyArray_NDIM(op[i]) - num_dims;
/*
* Need to use the arrays in the iterator, not op, because
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py
index 27143e5c6..b604b8c52 100644
--- a/numpy/lib/_iotools.py
+++ b/numpy/lib/_iotools.py
@@ -205,7 +205,11 @@ class LineSplitter(object):
#
def __init__(self, delimiter=None, comments='#', autostrip=True, encoding=None):
+ delimiter = _decode_line(delimiter)
+ comments = _decode_line(comments)
+
self.comments = comments
+
# Delimiter is a character
if (delimiter is None) or isinstance(delimiter, basestring):
delimiter = delimiter or None
diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py
index 5f6c29a4d..b4888f1bd 100644
--- a/numpy/lib/tests/test__iotools.py
+++ b/numpy/lib/tests/test__iotools.py
@@ -53,6 +53,11 @@ class TestLineSplitter(object):
test = LineSplitter(',')(strg)
assert_equal(test, ['1', '2', '3', '4', '', '5'])
+ # gh-11028 bytes comment/delimiters should get encoded
+ strg = b" 1,2,3,4,,5 % test"
+ test = LineSplitter(delimiter=b',', comments=b'%')(strg)
+ assert_equal(test, ['1', '2', '3', '4', '', '5'])
+
def test_constant_fixed_width(self):
"Test LineSplitter w/ fixed-width fields"
strg = " 1 2 3 4 5 # test"