summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMark Wiebe <mwiebe@enthought.com>2011-06-06 11:42:31 -0500
committerMark Wiebe <mwiebe@enthought.com>2011-06-22 09:09:07 -0500
commitc149545d31e9fb9ba28075fc0a58cb836eab0f8a (patch)
tree3c8de4822c4e8d0e7a1156df0956352c42a7dbbd /numpy
parentbd85dfffca8629a7e57f5f9397168e0c7dc4e677 (diff)
downloadnumpy-c149545d31e9fb9ba28075fc0a58cb836eab0f8a.tar.gz
ENH: core: Change the ones_like ufunc so it doesn't do type checking
Since ones_like is a ufunc (unlike zeros_like and empty_like), it by default checks the casting rule. This disables that check completely.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/generate_umath.py2
-rw-r--r--numpy/core/src/umath/ufunc_object.c21
-rw-r--r--numpy/core/src/umath/ufunc_object.h9
3 files changed, 31 insertions, 1 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 957607f40..296f4683d 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -333,7 +333,7 @@ defdict = {
'ones_like' :
Ufunc(1, 1, None,
docstrings.get('numpy.core.umath.ones_like'),
- 'PyUFunc_SimpleUnaryOperationTypeResolution',
+ 'PyUFunc_OnesLikeTypeResolution',
TD(noobj),
TD(O, f='Py_get_one'),
),
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index b26221e23..69f9afecf 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -2012,6 +2012,27 @@ PyUFunc_SimpleUnaryOperationTypeResolution(PyUFuncObject *ufunc,
}
/*
+ * The ones_like function shouldn't really be a ufunc, but while it
+ * still is, this provides type resolution that always forces UNSAFE
+ * casting.
+ */
+NPY_NO_EXPORT int
+PyUFunc_OnesLikeTypeResolution(PyUFuncObject *ufunc,
+ NPY_CASTING NPY_UNUSED(casting),
+ PyArrayObject **operands,
+ PyObject *type_tup,
+ PyArray_Descr **out_dtypes,
+ PyUFuncGenericFunction *out_innerloop,
+ void **out_innerloopdata)
+{
+ return PyUFunc_SimpleUnaryOperationTypeResolution(ufunc,
+ NPY_UNSAFE_CASTING,
+ operands, type_tup, out_dtypes,
+ out_innerloop, out_innerloopdata);
+}
+
+
+/*
* This function applies special type resolution rules for the case
* where all the functions have the pattern XX->X, using
* PyArray_ResultType instead of a linear search to get the best
diff --git a/numpy/core/src/umath/ufunc_object.h b/numpy/core/src/umath/ufunc_object.h
index 2a5fd63a1..59754380c 100644
--- a/numpy/core/src/umath/ufunc_object.h
+++ b/numpy/core/src/umath/ufunc_object.h
@@ -26,6 +26,15 @@ PyUFunc_SimpleUnaryOperationTypeResolution(PyUFuncObject *ufunc,
void **out_innerloopdata);
NPY_NO_EXPORT int
+PyUFunc_OnesLikeTypeResolution(PyUFuncObject *ufunc,
+ NPY_CASTING casting,
+ PyArrayObject **operands,
+ PyObject *type_tup,
+ PyArray_Descr **out_dtypes,
+ PyUFuncGenericFunction *out_innerloop,
+ void **out_innerloopdata);
+
+NPY_NO_EXPORT int
PyUFunc_SimpleBinaryOperationTypeResolution(PyUFuncObject *ufunc,
NPY_CASTING casting,
PyArrayObject **operands,