summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2011-01-21 09:35:03 -0800
committerMark Wiebe <mwwiebe@gmail.com>2011-01-21 09:35:03 -0800
commit9317b745856b4bb956426b199d3422a6ef71e269 (patch)
treebaf3965602b5d44b51ffa253f2bd483fa0dbe746 /numpy/core
parent87596cf6a0e6becccea111727435605fa3615e49 (diff)
downloadnumpy-9317b745856b4bb956426b199d3422a6ef71e269.tar.gz
BUG: iter: Fix 0-size edge case with trivial iteration macros
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/multiarray/dtype_transfer.c4
-rw-r--r--numpy/core/src/multiarray/lowlevel_strided_loops.h2
-rw-r--r--numpy/core/src/umath/ufunc_object.c18
-rw-r--r--numpy/core/tests/test_regression.py5
4 files changed, 25 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c
index 084683f96..8fdcd8a5d 100644
--- a/numpy/core/src/multiarray/dtype_transfer.c
+++ b/numpy/core/src/multiarray/dtype_transfer.c
@@ -17,8 +17,8 @@
#define NPY_LOWLEVEL_BUFFER_BLOCKSIZE 128
-#define DTYPE_TRANSFER_REFTRACE(x, y)
-/*#define DTYPE_TRANSFER_REFTRACE printf*/
+#define DTYPE_TRANSFER_REFTRACE(...)
+/*#define DTYPE_TRANSFER_REFTRACE(...) printf(__VA_ARGS__)*/
/*
* Returns a transfer function which DECREFs any references in src_type.
diff --git a/numpy/core/src/multiarray/lowlevel_strided_loops.h b/numpy/core/src/multiarray/lowlevel_strided_loops.h
index 6e17e3fd7..1a6482398 100644
--- a/numpy/core/src/multiarray/lowlevel_strided_loops.h
+++ b/numpy/core/src/multiarray/lowlevel_strided_loops.h
@@ -330,6 +330,7 @@ PyArray_TransferStridedToNDim(npy_intp ndim,
npy_intp size1 = PyArray_SIZE(arr1); \
npy_intp size2 = PyArray_SIZE(arr2); \
count = size1 > size2 ? size1 : size2; \
+ if (size1 == 0 || size2 == 0) count = 0; \
data1 = PyArray_BYTES(arr1); \
data2 = PyArray_BYTES(arr2); \
stride1 = (size1 == 1 ? 0 : \
@@ -374,6 +375,7 @@ PyArray_TransferStridedToNDim(npy_intp ndim,
npy_intp size3 = PyArray_SIZE(arr3); \
count = size1 > size2 ? size1 : size2; \
if (size3 > count) count = size3; \
+ if (size1 == 0 || size2 == 0 || size2 == 0) count = 0; \
data1 = PyArray_BYTES(arr1); \
data2 = PyArray_BYTES(arr2); \
data3 = PyArray_BYTES(arr3); \
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 2e52f568f..d1ef4dae4 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -43,8 +43,15 @@
#define USE_USE_DEFAULTS 1
-/*#define NPY_UFUNC_DBG_PRINTF(...) printf(__VA_ARGS__)*/
+/********************/
+#if 0
+#define NPY_UFUNC_DBG_PRINTF(...) printf(__VA_ARGS__)
+#else
#define NPY_UFUNC_DBG_PRINTF(...)
+#endif
+
+#define USE_NEW_ITERATOR_GENFUNC 1
+/********************/
/* ---------------------------------------------------------------- */
@@ -5336,9 +5343,12 @@ static struct PyMethodDef ufunc_methods[] = {
{"outer",
(PyCFunction)ufunc_outer,
METH_VARARGS | METH_KEYWORDS, NULL},
- {"f", /* old generic call */
+ {"of", /* old generic call */
(PyCFunction)ufunc_generic_call,
METH_VARARGS | METH_KEYWORDS, NULL},
+ {"nf", /* new generic call */
+ (PyCFunction)ufunc_generic_call_iter,
+ METH_VARARGS | METH_KEYWORDS, NULL},
{NULL, NULL, 0, NULL} /* sentinel */
};
@@ -5564,7 +5574,11 @@ NPY_NO_EXPORT PyTypeObject PyUFunc_Type = {
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
+#if USE_NEW_ITERATOR_GENFUNC
(ternaryfunc)ufunc_generic_call_iter, /* tp_call */
+#else
+ (ternaryfunc)ufunc_generic_call, /* tp_call */
+#endif
(reprfunc)ufunc_repr, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 06055b2cd..04fd9210e 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1441,5 +1441,10 @@ class TestRegression(TestCase):
a = a.byteswap().newbyteorder()
assert_equal(a.nonzero()[0], [1]) # [0] if nonzero() ignores swap
+ def test_empty_mul(self):
+ a = np.array([1.])
+ a[1:1] *= 2
+ assert_equal(a, [1.])
+
if __name__ == "__main__":
run_module_suite()