diff options
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 43dd101c5..ccf3a3a7d 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -289,37 +289,26 @@ static int { PyArrayObject *ap = vap; Py_complex oop; - PyObject *op2; @type@ temp; int rsize; + if (PyArray_IsZeroDim(op)) { + return convert_to_scalar_and_retry(op, ov, vap, @NAME@_setitem); + } + if (PyArray_IsScalar(op, @kind@)){ temp = ((Py@kind@ScalarObject *)op)->obval; } else { - if (PyArray_IsZeroDim(op)) { - /* - * TODO: Elsewhere in this file we use PyArray_ToScalar. Is this - * better or worse? Possibly an optimization. - */ - op2 = PyArray_DESCR((PyArrayObject *)op)->f->getitem( - PyArray_BYTES((PyArrayObject *)op), - (PyArrayObject *)op); - } - else { - op2 = op; - Py_INCREF(op); - } - if (op2 == Py_None) { + if (op == Py_None) { oop.real = NPY_NAN; oop.imag = NPY_NAN; } else { - oop = PyComplex_AsCComplex (op2); - } - Py_DECREF(op2); - if (PyErr_Occurred()) { - return -1; + oop = PyComplex_AsCComplex (op); + if (PyErr_Occurred()) { + return -1; + } } temp.real = (@ftype@) oop.real; temp.imag = (@ftype@) oop.imag; |