summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-07-10 10:00:35 -0700
committerCharles Harris <charlesr.harris@gmail.com>2013-07-10 10:00:35 -0700
commit12c5fc01e37d2235713c59ac0b1346294a8e8688 (patch)
treef4aabcc469dd51856301104ea90f257407697bdd
parent49a587cd786242b05fcfd22d5cda961d733b68d4 (diff)
parent6815f865678e88dab68c00c34fb1c9e7166f8f3c (diff)
downloadnumpy-12c5fc01e37d2235713c59ac0b1346294a8e8688.tar.gz
Merge pull request #3509 from arinkverma/gsoc_performance
ENH: added short path scalar array in get_ufunc_arguments from ufunc_object.c
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c6
-rw-r--r--numpy/core/src/multiarray/ctors.c8
-rw-r--r--numpy/core/src/umath/ufunc_object.c33
3 files changed, 33 insertions, 14 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index 2dae2f88d..fa88fa31a 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -743,7 +743,11 @@ can_cast_scalar_to(PyArray_Descr *scal_type, char *scal_data,
/* An aligned memory buffer large enough to hold any type */
npy_longlong value[4];
- if (casting == NPY_UNSAFE_CASTING) {
+ /*
+ * If the two dtypes are actually references to the same object
+ * or if casting type is forced unsafe then always OK.
+ */
+ if (scal_type == to || casting == NPY_UNSAFE_CASTING ) {
return 1;
}
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 41a56431b..ace147ca5 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1815,6 +1815,14 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
oldtype = PyArray_DESCR(arr);
if (newtype == NULL) {
+ /*
+ * Check if object is of array with Null newtype.
+ * If so return it directly instead of checking for casting.
+ */
+ if (flags == 0) {
+ Py_INCREF(arr);
+ return (PyObject *)arr;
+ }
newtype = oldtype;
Py_INCREF(oldtype);
}
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 85c0069c3..2b5f38d25 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -753,22 +753,29 @@ static int get_ufunc_arguments(PyUFuncObject *ufunc,
/* Get input arguments */
for (i = 0; i < nin; ++i) {
obj = PyTuple_GET_ITEM(args, i);
- if (!PyArray_Check(obj) && !PyArray_IsScalar(obj, Generic)) {
- /*
- * TODO: There should be a comment here explaining what
- * context does.
- */
- context = Py_BuildValue("OOi", ufunc, args, i);
- if (context == NULL) {
- return -1;
- }
+
+ if (PyArray_Check(obj)) {
+ out_op[i] = (PyArrayObject *)PyArray_FromArray(obj,NULL,0);
}
else {
- context = NULL;
- }
- out_op[i] = (PyArrayObject *)PyArray_FromAny(obj,
+ if (!PyArray_IsScalar(obj, Generic)) {
+ /*
+ * TODO: There should be a comment here explaining what
+ * context does.
+ */
+ context = Py_BuildValue("OOi", ufunc, args, i);
+ if (context == NULL) {
+ return -1;
+ }
+ }
+ else {
+ context = NULL;
+ }
+ out_op[i] = (PyArrayObject *)PyArray_FromAny(obj,
NULL, 0, 0, 0, context);
- Py_XDECREF(context);
+ Py_XDECREF(context);
+ }
+
if (out_op[i] == NULL) {
return -1;
}