summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorTyler Reddy <tyler.je.reddy@gmail.com>2018-04-25 10:24:31 -0600
committerTyler Reddy <tyler.je.reddy@gmail.com>2018-04-25 10:24:31 -0600
commitb453e901b519f62eca19a34735533d53884779c8 (patch)
treeab63a895f5b7d8ca617553f01b6b00a1050080df /numpy
parenta043c3ed2a08fc42fd2eff6669a862c5cb045bfc (diff)
downloadnumpy-b453e901b519f62eca19a34735533d53884779c8.tar.gz
MAINT: addressed extraneous shape tuple checks in descriptor.c
* C source comments flag two extraneous checks for the object type of self->subarray->shape in descriptor.c * pertinent code has been adjusted to assert the presence of the tuple object where needed & remove a fallback return call along with an extraneous casting
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/descriptor.c30
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);
}