summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2020-01-08 12:53:16 -0600
committerGitHub <noreply@github.com>2020-01-08 12:53:16 -0600
commit48498b8632f91d7d2622b1e67c48c688ea2edccc (patch)
treebc064a6c93b1bfd78f7c97e35f7313f51141a89f /numpy
parent3b7aac3448c9a396569d003c2ac87116859f2bc5 (diff)
parent9de717042d44a4a77ecf8122638370d29b75e71d (diff)
downloadnumpy-48498b8632f91d7d2622b1e67c48c688ea2edccc.tar.gz
Merge pull request #15289 from sethtroisi/PY3K_post
MAINT: C code simplifications
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/generate_umath.py15
-rw-r--r--numpy/core/src/multiarray/flagsobject.c46
-rw-r--r--numpy/core/src/umath/scalarmath.c.src6
-rw-r--r--numpy/core/src/umath/ufunc_type_resolution.c17
-rw-r--r--numpy/core/src/umath/ufunc_type_resolution.h7
-rw-r--r--numpy/f2py/src/fortranobject.c12
6 files changed, 19 insertions, 84 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 6f18d5aa9..f5691d950 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -302,17 +302,6 @@ defdict = {
],
TD(O, f='PyNumber_Multiply'),
),
-'divide':
- Ufunc(2, 1, None, # One is only a unit to the right, not the left
- docstrings.get('numpy.core.umath.divide'),
- 'PyUFunc_MixedDivisionTypeResolver',
- TD(intfltcmplx),
- [TypeDescription('m', FullTypeDescr, 'mq', 'm'),
- TypeDescription('m', FullTypeDescr, 'md', 'm'),
- TypeDescription('m', FullTypeDescr, 'mm', 'd'),
- ],
- TD(O, f='PyNumber_Divide'),
- ),
'floor_divide':
Ufunc(2, 1, None, # One is only a unit to the right, not the left
docstrings.get('numpy.core.umath.floor_divide'),
@@ -953,10 +942,6 @@ defdict = {
),
}
-if sys.version_info[0] >= 3:
- # Will be aliased to true_divide in umathmodule.c.src:InitOtherOperators
- del defdict['divide']
-
def indent(st, spaces):
indentation = ' '*spaces
indented = indentation + st.replace('\n', '\n'+indentation)
diff --git a/numpy/core/src/multiarray/flagsobject.c b/numpy/core/src/multiarray/flagsobject.c
index aa629fdd6..6fe0eff4a 100644
--- a/numpy/core/src/multiarray/flagsobject.c
+++ b/numpy/core/src/multiarray/flagsobject.c
@@ -727,47 +727,25 @@ arrayflags_print(PyArrayFlagsObject *self)
);
}
-static int
-arrayflags_compare(PyArrayFlagsObject *self, PyArrayFlagsObject *other)
-{
- if (self->flags == other->flags) {
- return 0;
- }
- else if (self->flags < other->flags) {
- return -1;
- }
- else {
- return 1;
- }
-}
-
-
static PyObject*
arrayflags_richcompare(PyObject *self, PyObject *other, int cmp_op)
{
- PyObject *result = Py_NotImplemented;
- int cmp;
-
- if (cmp_op != Py_EQ && cmp_op != Py_NE) {
- PyErr_SetString(PyExc_TypeError,
- "undefined comparison for flag object");
- return NULL;
+ if (!PyObject_TypeCheck(other, &PyArrayFlags_Type)) {
+ Py_RETURN_NOTIMPLEMENTED;
}
- if (PyObject_TypeCheck(other, &PyArrayFlags_Type)) {
- cmp = arrayflags_compare((PyArrayFlagsObject *)self,
- (PyArrayFlagsObject *)other);
+ npy_bool eq = ((PyArrayFlagsObject*) self)->flags ==
+ ((PyArrayFlagsObject*) other)->flags;
- if (cmp_op == Py_EQ) {
- result = (cmp == 0) ? Py_True : Py_False;
- }
- else if (cmp_op == Py_NE) {
- result = (cmp != 0) ? Py_True : Py_False;
- }
+ if (cmp_op == Py_EQ) {
+ return PyBool_FromLong(eq);
+ }
+ else if (cmp_op == Py_NE) {
+ return PyBool_FromLong(!eq);
+ }
+ else {
+ Py_RETURN_NOTIMPLEMENTED;
}
-
- Py_INCREF(result);
- return result;
}
static PyMappingMethods arrayflags_as_mapping = {
diff --git a/numpy/core/src/umath/scalarmath.c.src b/numpy/core/src/umath/scalarmath.c.src
index 4cf7ac546..b3826eef4 100644
--- a/numpy/core/src/umath/scalarmath.c.src
+++ b/numpy/core/src/umath/scalarmath.c.src
@@ -1291,8 +1291,6 @@ static PyObject *
/**end repeat**/
-#define NONZERO_NAME(prefix) prefix##bool
-
#define _IS_NONZERO(x) (x != 0)
/**begin repeat
*
@@ -1308,7 +1306,7 @@ static PyObject *
* #nonzero = _IS_NONZERO*10, !npy_half_iszero, _IS_NONZERO*6#
*/
static int
-NONZERO_NAME(@name@_)(PyObject *a)
+@name@_bool(PyObject *a)
{
int ret;
@type@ arg1;
@@ -1317,7 +1315,7 @@ NONZERO_NAME(@name@_)(PyObject *a)
if (PyErr_Occurred()) {
return -1;
}
- return PyGenericArrType_Type.tp_as_number->NONZERO_NAME(nb_)(a);
+ return PyGenericArrType_Type.tp_as_number->nb_bool(a);
}
/*
diff --git a/numpy/core/src/umath/ufunc_type_resolution.c b/numpy/core/src/umath/ufunc_type_resolution.c
index 7b05c4166..0e71305b6 100644
--- a/numpy/core/src/umath/ufunc_type_resolution.c
+++ b/numpy/core/src/umath/ufunc_type_resolution.c
@@ -1347,23 +1347,6 @@ PyUFunc_TrueDivisionTypeResolver(PyUFuncObject *ufunc,
return PyUFunc_DivisionTypeResolver(ufunc, casting, operands,
type_tup, out_dtypes);
}
-/*
- * Function to check and report floor division warning when python2.x is
- * invoked with -3 switch
- * See PEP238 and #7949 for numpy
- * This function will not be hit for py3 or when __future__ imports division.
- * See generate_umath.py for reason
-*/
-NPY_NO_EXPORT int
-PyUFunc_MixedDivisionTypeResolver(PyUFuncObject *ufunc,
- NPY_CASTING casting,
- PyArrayObject **operands,
- PyObject *type_tup,
- PyArray_Descr **out_dtypes)
-{
- return PyUFunc_DivisionTypeResolver(ufunc, casting, operands,
- type_tup, out_dtypes);
-}
static int
find_userloop(PyUFuncObject *ufunc,
diff --git a/numpy/core/src/umath/ufunc_type_resolution.h b/numpy/core/src/umath/ufunc_type_resolution.h
index a4e670a8e..1d6ad3358 100644
--- a/numpy/core/src/umath/ufunc_type_resolution.h
+++ b/numpy/core/src/umath/ufunc_type_resolution.h
@@ -72,13 +72,6 @@ PyUFunc_MultiplicationTypeResolver(PyUFuncObject *ufunc,
PyArray_Descr **out_dtypes);
NPY_NO_EXPORT int
-PyUFunc_MixedDivisionTypeResolver(PyUFuncObject *ufunc,
- NPY_CASTING casting,
- PyArrayObject **operands,
- PyObject *type_tup,
- PyArray_Descr **out_dtypes);
-
-NPY_NO_EXPORT int
PyUFunc_TrueDivisionTypeResolver(PyUFuncObject *ufunc,
NPY_CASTING casting,
PyArrayObject **operands,
diff --git a/numpy/f2py/src/fortranobject.c b/numpy/f2py/src/fortranobject.c
index 81fc50f2e..8ec5b510f 100644
--- a/numpy/f2py/src/fortranobject.c
+++ b/numpy/f2py/src/fortranobject.c
@@ -312,13 +312,11 @@ fortran_getattr(PyFortranObject *fp, char *name) {
return NULL;
return cobj;
}
- if (1) {
- PyObject *str, *ret;
- str = PyUnicode_FromString(name);
- ret = PyObject_GenericGetAttr((PyObject *)fp, str);
- Py_DECREF(str);
- return ret;
- }
+ PyObject *str, *ret;
+ str = PyUnicode_FromString(name);
+ ret = PyObject_GenericGetAttr((PyObject *)fp, str);
+ Py_DECREF(str);
+ return ret;
}
static int