Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48498b8

Browse files
authored
Merge pull request #15289 from sethtroisi/PY3K_post
MAINT: C code simplifications
2 parents 3b7aac3 + 9de7170 commit 48498b8

File tree

7 files changed

+19
-86
lines changed

7 files changed

+19
-86
lines changed

doc/Py3K.rst.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ A #define in config.h, defined when building for Py3.
225225
Currently, this is generated as a part of the config.
226226
Is this sensible (we could also use Py_VERSION_HEX)?
227227

228-
This is being cleaned up in the C code.
229-
230228

231229
private/npy_3kcompat.h
232230
----------------------

numpy/core/code_generators/generate_umath.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,6 @@ def english_upper(s):
302302
],
303303
TD(O, f='PyNumber_Multiply'),
304304
),
305-
'divide':
306-
Ufunc(2, 1, None, # One is only a unit to the right, not the left
307-
docstrings.get('numpy.core.umath.divide'),
308-
'PyUFunc_MixedDivisionTypeResolver',
309-
TD(intfltcmplx),
310-
[TypeDescription('m', FullTypeDescr, 'mq', 'm'),
311-
TypeDescription('m', FullTypeDescr, 'md', 'm'),
312-
TypeDescription('m', FullTypeDescr, 'mm', 'd'),
313-
],
314-
TD(O, f='PyNumber_Divide'),
315-
),
316305
'floor_divide':
317306
Ufunc(2, 1, None, # One is only a unit to the right, not the left
318307
docstrings.get('numpy.core.umath.floor_divide'),
@@ -953,10 +942,6 @@ def english_upper(s):
953942
),
954943
}
955944

956-
if sys.version_info[0] >= 3:
957-
# Will be aliased to true_divide in umathmodule.c.src:InitOtherOperators
958-
del defdict['divide']
959-
960945
def indent(st, spaces):
961946
indentation = ' '*spaces
962947
indented = indentation + st.replace('\n', '\n'+indentation)

numpy/core/src/multiarray/flagsobject.c

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -727,47 +727,25 @@ arrayflags_print(PyArrayFlagsObject *self)
727727
);
728728
}
729729

730-
static int
731-
arrayflags_compare(PyArrayFlagsObject *self, PyArrayFlagsObject *other)
732-
{
733-
if (self->flags == other->flags) {
734-
return 0;
735-
}
736-
else if (self->flags < other->flags) {
737-
return -1;
738-
}
739-
else {
740-
return 1;
741-
}
742-
}
743-
744-
745730
static PyObject*
746731
arrayflags_richcompare(PyObject *self, PyObject *other, int cmp_op)
747732
{
748-
PyObject *result = Py_NotImplemented;
749-
int cmp;
750-
751-
if (cmp_op != Py_EQ && cmp_op != Py_NE) {
752-
PyErr_SetString(PyExc_TypeError,
753-
"undefined comparison for flag object");
754-
return NULL;
733+
if (!PyObject_TypeCheck(other, &PyArrayFlags_Type)) {
734+
Py_RETURN_NOTIMPLEMENTED;
755735
}
756736

757-
if (PyObject_TypeCheck(other, &PyArrayFlags_Type)) {
758-
cmp = arrayflags_compare((PyArrayFlagsObject *)self,
759-
(PyArrayFlagsObject *)other);
737+
npy_bool eq = ((PyArrayFlagsObject*) self)->flags ==
738+
((PyArrayFlagsObject*) other)->flags;
760739

761-
if (cmp_op == Py_EQ) {
762-
result = (cmp == 0) ? Py_True : Py_False;
763-
}
764-
else if (cmp_op == Py_NE) {
765-
result = (cmp != 0) ? Py_True : Py_False;
766-
}
740+
if (cmp_op == Py_EQ) {
741+
return PyBool_FromLong(eq);
742+
}
743+
else if (cmp_op == Py_NE) {
744+
return PyBool_FromLong(!eq);
745+
}
746+
else {
747+
Py_RETURN_NOTIMPLEMENTED;
767748
}
768-
769-
Py_INCREF(result);
770-
return result;
771749
}
772750

773751
static PyMappingMethods arrayflags_as_mapping = {

numpy/core/src/umath/scalarmath.c.src

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,8 +1291,6 @@ static PyObject *
12911291

12921292
/**end repeat**/
12931293

1294-
#define NONZERO_NAME(prefix) prefix##bool
1295-
12961294
#define _IS_NONZERO(x) (x != 0)
12971295
/**begin repeat
12981296
*
@@ -1308,7 +1306,7 @@ static PyObject *
13081306
* #nonzero = _IS_NONZERO*10, !npy_half_iszero, _IS_NONZERO*6#
13091307
*/
13101308
static int
1311-
NONZERO_NAME(@name@_)(PyObject *a)
1309+
@name@_bool(PyObject *a)
13121310
{
13131311
int ret;
13141312
@type@ arg1;
@@ -1317,7 +1315,7 @@ NONZERO_NAME(@name@_)(PyObject *a)
13171315
if (PyErr_Occurred()) {
13181316
return -1;
13191317
}
1320-
return PyGenericArrType_Type.tp_as_number->NONZERO_NAME(nb_)(a);
1318+
return PyGenericArrType_Type.tp_as_number->nb_bool(a);
13211319
}
13221320

13231321
/*

numpy/core/src/umath/ufunc_type_resolution.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,23 +1347,6 @@ PyUFunc_TrueDivisionTypeResolver(PyUFuncObject *ufunc,
13471347
return PyUFunc_DivisionTypeResolver(ufunc, casting, operands,
13481348
type_tup, out_dtypes);
13491349
}
1350-
/*
1351-
* Function to check and report floor division warning when python2.x is
1352-
* invoked with -3 switch
1353-
* See PEP238 and #7949 for numpy
1354-
* This function will not be hit for py3 or when __future__ imports division.
1355-
* See generate_umath.py for reason
1356-
*/
1357-
NPY_NO_EXPORT int
1358-
PyUFunc_MixedDivisionTypeResolver(PyUFuncObject *ufunc,
1359-
NPY_CASTING casting,
1360-
PyArrayObject **operands,
1361-
PyObject *type_tup,
1362-
PyArray_Descr **out_dtypes)
1363-
{
1364-
return PyUFunc_DivisionTypeResolver(ufunc, casting, operands,
1365-
type_tup, out_dtypes);
1366-
}
13671350

13681351
static int
13691352
find_userloop(PyUFuncObject *ufunc,

numpy/core/src/umath/ufunc_type_resolution.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ PyUFunc_MultiplicationTypeResolver(PyUFuncObject *ufunc,
7171
PyObject *type_tup,
7272
PyArray_Descr **out_dtypes);
7373

74-
NPY_NO_EXPORT int
75-
PyUFunc_MixedDivisionTypeResolver(PyUFuncObject *ufunc,
76-
NPY_CASTING casting,
77-
PyArrayObject **operands,
78-
PyObject *type_tup,
79-
PyArray_Descr **out_dtypes);
80-
8174
NPY_NO_EXPORT int
8275
PyUFunc_TrueDivisionTypeResolver(PyUFuncObject *ufunc,
8376
NPY_CASTING casting,

numpy/f2py/src/fortranobject.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,11 @@ fortran_getattr(PyFortranObject *fp, char *name) {
312312
return NULL;
313313
return cobj;
314314
}
315-
if (1) {
316-
PyObject *str, *ret;
317-
str = PyUnicode_FromString(name);
318-
ret = PyObject_GenericGetAttr((PyObject *)fp, str);
319-
Py_DECREF(str);
320-
return ret;
321-
}
315+
PyObject *str, *ret;
316+
str = PyUnicode_FromString(name);
317+
ret = PyObject_GenericGetAttr((PyObject *)fp, str);
318+
Py_DECREF(str);
319+
return ret;
322320
}
323321

324322
static int

0 commit comments

Comments
 (0)