summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-02-09 00:31:41 -0800
committerEric Wieser <wieser.eric@gmail.com>2018-02-09 01:16:10 -0800
commit860cc39dbf1e1b40004c7a128c9c83bf7671b278 (patch)
tree7d91a835c4176aa9db03346b5698b83a8ceaebff /numpy
parentff2e1bc0976210076d309f1cee4323352017d1fd (diff)
downloadnumpy-860cc39dbf1e1b40004c7a128c9c83bf7671b278.tar.gz
MAINT: Push variables and return statements in PyArray_ResultType to innermost scopes
This makes extracting helper functions easier
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index 00cb07335..140f793dc 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -1705,12 +1705,11 @@ PyArray_ResultType(npy_intp narrs, PyArrayObject **arr,
npy_intp ndtypes, PyArray_Descr **dtypes)
{
npy_intp i;
- int use_min_scalar = 0;
- PyArray_Descr *ret = NULL;
- int ret_is_small_unsigned = 0;
+ int use_min_scalar;
/* If there's just one type, pass it through */
if (narrs + ndtypes == 1) {
+ PyArray_Descr *ret = NULL;
if (narrs == 1) {
ret = PyArray_DESCR(arr[0]);
}
@@ -1726,28 +1725,30 @@ PyArray_ResultType(npy_intp narrs, PyArrayObject **arr,
* the maximum "kind" of the scalars surpasses the maximum
* "kind" of the arrays
*/
+ use_min_scalar = 0;
if (narrs > 0) {
- int all_scalars, max_scalar_kind = -1, max_array_kind = -1;
- int kind;
+ int all_scalars;
+ int max_scalar_kind = -1;
+ int max_array_kind = -1;
all_scalars = (ndtypes > 0) ? 0 : 1;
/* Compute the maximum "kinds" and whether everything is scalar */
for (i = 0; i < narrs; ++i) {
if (PyArray_NDIM(arr[i]) == 0) {
- kind = dtype_kind_to_simplified_ordering(
+ int kind = dtype_kind_to_simplified_ordering(
PyArray_DESCR(arr[i])->kind);
if (kind > max_scalar_kind) {
max_scalar_kind = kind;
}
}
else {
- all_scalars = 0;
- kind = dtype_kind_to_simplified_ordering(
+ int kind = dtype_kind_to_simplified_ordering(
PyArray_DESCR(arr[i])->kind);
if (kind > max_array_kind) {
max_array_kind = kind;
}
+ all_scalars = 0;
}
}
/*
@@ -1755,7 +1756,7 @@ PyArray_ResultType(npy_intp narrs, PyArrayObject **arr,
* finish computing the max array kind
*/
for (i = 0; i < ndtypes; ++i) {
- kind = dtype_kind_to_simplified_ordering(dtypes[i]->kind);
+ int kind = dtype_kind_to_simplified_ordering(dtypes[i]->kind);
if (kind > max_array_kind) {
max_array_kind = kind;
}
@@ -1769,6 +1770,8 @@ PyArray_ResultType(npy_intp narrs, PyArrayObject **arr,
/* Loop through all the types, promoting them */
if (!use_min_scalar) {
+ PyArray_Descr *ret;
+
/* Build a single array of all the dtypes */
PyArray_Descr **all_dtypes = PyArray_malloc(
sizeof(*all_dtypes) * (narrs + ndtypes));
@@ -1783,11 +1786,12 @@ PyArray_ResultType(npy_intp narrs, PyArrayObject **arr,
}
ret = PyArray_PromoteTypeSequence(all_dtypes, narrs + ndtypes);
PyArray_free(all_dtypes);
- if (ret == NULL) {
- return NULL;
- }
+ return ret;
}
else {
+ int ret_is_small_unsigned = 0;
+ PyArray_Descr *ret = NULL;
+
for (i = 0; i < narrs; ++i) {
int tmp_is_small_unsigned;
PyArray_Descr *tmp = PyArray_MinScalarType_internal(
@@ -1833,14 +1837,14 @@ PyArray_ResultType(npy_intp narrs, PyArrayObject **arr,
}
}
}
- }
+ /* None of the above loops ran */
+ if (ret == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "no arrays or types available to calculate result type");
+ }
- if (ret == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "no arrays or types available to calculate result type");
+ return ret;
}
-
- return ret;
}
/*NUMPY_API