diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-04-26 01:01:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-26 01:01:32 -0700 |
commit | 8f4f7d93cda0189655e829bfb93ad8592ea69e6e (patch) | |
tree | cd75be73800e3390c02025b822eb4648ba9ed656 | |
parent | fa9c78c9cb0597b95496d282e6def3ca9ff61ebf (diff) | |
parent | b453e901b519f62eca19a34735533d53884779c8 (diff) | |
download | numpy-8f4f7d93cda0189655e829bfb93ad8592ea69e6e.tar.gz |
Merge pull request #10953 from tylerjereddy/remove_extraneous_tuple_checks
MAINT: address extraneous shape tuple checks in descriptor.c
-rw-r--r-- | numpy/core/src/multiarray/descriptor.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c index c1c1ce568..bb3cc9d4e 100644 --- a/numpy/core/src/multiarray/descriptor.c +++ b/numpy/core/src/multiarray/descriptor.c @@ -18,6 +18,7 @@ #include "templ_common.h" /* for npy_mul_with_overflow_intp */ #include "descriptor.h" #include "alloc.h" +#include "assert.h" /* * offset: A starting offset. @@ -1938,33 +1939,26 @@ arraydescr_shape_get(PyArray_Descr *self) if (!PyDataType_HASSUBARRAY(self)) { return PyTuple_New(0); } - /*TODO - * self->subarray->shape should always be a tuple, - * so this check should be unnecessary - */ - if (PyTuple_Check(self->subarray->shape)) { - Py_INCREF(self->subarray->shape); - return (PyObject *)(self->subarray->shape); - } - return Py_BuildValue("(O)", self->subarray->shape); + assert(PyTuple_Check(self->subarray->shape)); + Py_INCREF(self->subarray->shape); + return self->subarray->shape; } static PyObject * arraydescr_ndim_get(PyArray_Descr *self) { + Py_ssize_t ndim; + if (!PyDataType_HASSUBARRAY(self)) { return PyInt_FromLong(0); } - /*TODO - * self->subarray->shape should always be a tuple, - * so this check should be unnecessary + + /* + * PyTuple_Size has built in check + * for tuple argument */ - if (PyTuple_Check(self->subarray->shape)) { - Py_ssize_t ndim = PyTuple_Size(self->subarray->shape); - return PyInt_FromLong(ndim); - } - /* consistent with arraydescr_shape_get */ - return PyInt_FromLong(1); + ndim = PyTuple_Size(self->subarray->shape); + return PyInt_FromLong(ndim); } |