diff options
author | Nathaniel J. Smith <njs@pobox.com> | 2015-08-27 00:02:17 -0700 |
---|---|---|
committer | Nathaniel J. Smith <njs@pobox.com> | 2015-10-01 16:03:18 -0700 |
commit | 899325ec043688c751001662f5e7226e7e92e04e (patch) | |
tree | a309b1a2a7c2d8b7480eb5ecc7ddd6f49539c375 | |
parent | 1765438b5f68eeb5c9b920e8df2760dc8e908cae (diff) | |
download | numpy-899325ec043688c751001662f5e7226e7e92e04e.tar.gz |
MAINT: cleanup dead code/arguments/fields from ufuncs
The check_return argument and ufunc object field was never used; ditto
for the "new" inner loop selector (which was never implemented), along
with associated typedefs. Since I was looking at this code anyway trying
to figure out which parts were actually in use, I figured I'd clear up
some of the brush to make it easier next time...
-rw-r--r-- | doc/release/1.11.0-notes.rst | 10 | ||||
-rw-r--r-- | doc/source/reference/c-api.types-and-structures.rst | 7 | ||||
-rw-r--r-- | doc/source/reference/c-api.ufunc.rst | 11 | ||||
-rw-r--r-- | doc/source/user/c-info.ufunc-tutorial.rst | 7 | ||||
-rw-r--r-- | numpy/core/include/numpy/ufuncobject.h | 30 | ||||
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 30 | ||||
-rw-r--r-- | numpy/core/src/umath/umathmodule.c | 1 |
7 files changed, 33 insertions, 63 deletions
diff --git a/doc/release/1.11.0-notes.rst b/doc/release/1.11.0-notes.rst index 9afe6e866..990562604 100644 --- a/doc/release/1.11.0-notes.rst +++ b/doc/release/1.11.0-notes.rst @@ -35,6 +35,16 @@ Deprecated to error e.g., in reshape, take, and specifying reduce axis. +C API +~~~~~ + +Removed the ``check_return`` and ``inner_loop_selector`` members of +the ``PyUFuncObject`` struct (replacing them with ``reserved`` slots +to preserve struct layout). These were never used for anything, so +it's unlikely that any third-party code is using them either, but we +mention it here for completeness. + + New Features ============ diff --git a/doc/source/reference/c-api.types-and-structures.rst b/doc/source/reference/c-api.types-and-structures.rst index 35ffc2d1e..d7342bd9e 100644 --- a/doc/source/reference/c-api.types-and-structures.rst +++ b/doc/source/reference/c-api.types-and-structures.rst @@ -681,7 +681,7 @@ PyUFunc_Type PyUFuncGenericFunction *functions; void **data; int ntypes; - int check_return; + int reserved1; const char *name; char *types; const char *doc; @@ -748,11 +748,6 @@ PyUFunc_Type specifies how many different 1-d loops (of the builtin data types) are available. - .. c:member:: int PyUFuncObject.check_return - - Obsolete and unused. However, it is set by the corresponding entry in - the main ufunc creation routine: :c:func:`PyUFunc_FromFuncAndData` (...). - .. c:member:: char *PyUFuncObject.name A string name for the ufunc. This is used dynamically to build diff --git a/doc/source/reference/c-api.ufunc.rst b/doc/source/reference/c-api.ufunc.rst index ee1822122..892ccbdc7 100644 --- a/doc/source/reference/c-api.ufunc.rst +++ b/doc/source/reference/c-api.ufunc.rst @@ -67,7 +67,7 @@ Functions .. c:function:: PyObject* PyUFunc_FromFuncAndData(PyUFuncGenericFunction* func, void** data, char* types, int ntypes, int nin, int nout, int identity, - char* name, char* doc, int check_return) + char* name, char* doc, int unused) Create a new broadcasting universal function from required variables. Each ufunc builds around the notion of an element-by-element @@ -121,15 +121,12 @@ Functions dynamically determined from the object and available when accessing the **__doc__** attribute of the ufunc. - :param check_return: - Unused and present for backwards compatibility of the C-API. A - corresponding *check_return* integer does exist in the ufunc - structure and it does get set with this value when the ufunc - object is created. + :param unused: + Unused and present for backwards compatibility of the C-API. .. c:function:: PyObject* PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction* func, void** data, char* types, int ntypes, int nin, int nout, int identity, - char* name, char* doc, int check_return, char *signature) + char* name, char* doc, int unused, char *signature) This function is very similar to PyUFunc_FromFuncAndData above, but has an extra *signature* argument, to define generalized universal functions. diff --git a/doc/source/user/c-info.ufunc-tutorial.rst b/doc/source/user/c-info.ufunc-tutorial.rst index db25568b9..109e6adb5 100644 --- a/doc/source/user/c-info.ufunc-tutorial.rst +++ b/doc/source/user/c-info.ufunc-tutorial.rst @@ -1060,7 +1060,7 @@ automatically generates a ufunc from a C function with the correct signature. .. c:function:: PyObject *PyUFunc_FromFuncAndData( PyUFuncGenericFunction* func, void** data, char* types, int ntypes, int nin, int nout, int identity, - char* name, char* doc, int check_return) + char* name, char* doc, int unused) *func* @@ -1170,10 +1170,9 @@ automatically generates a ufunc from a C function with the correct signature. response to ``{ufunc_name}.__doc__``). Do not include the function signature or the name as this is generated automatically. - *check_return* + *unused* - Not presently used, but this integer value does get set in the - structure-member of similar name. + Unused; kept for compatiblity. Just set it to zero. .. index:: pair: ufunc; adding new diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h index a24a0d837..1cca64b75 100644 --- a/numpy/core/include/numpy/ufuncobject.h +++ b/numpy/core/include/numpy/ufuncobject.h @@ -20,17 +20,6 @@ typedef void (*PyUFuncGenericFunction) /* * The most generic one-dimensional inner loop for - * a standard element-wise ufunc. This typedef is also - * more consistent with the other NumPy function pointer typedefs - * than PyUFuncGenericFunction. - */ -typedef void (PyUFunc_StridedInnerLoopFunc)( - char **dataptrs, npy_intp *strides, - npy_intp count, - NpyAuxData *innerloopdata); - -/* - * The most generic one-dimensional inner loop for * a masked standard element-wise ufunc. "Masked" here means that it skips * doing calculations on any items for which the maskptr array has a true * value. @@ -112,13 +101,6 @@ typedef int (PyUFunc_LegacyInnerLoopSelectionFunc)( PyUFuncGenericFunction *out_innerloop, void **out_innerloopdata, int *out_needs_api); -typedef int (PyUFunc_InnerLoopSelectionFunc)( - struct _tagPyUFuncObject *ufunc, - PyArray_Descr **dtypes, - npy_intp *fixed_strides, - PyUFunc_StridedInnerLoopFunc **out_innerloop, - NpyAuxData **out_innerloopdata, - int *out_needs_api); typedef int (PyUFunc_MaskedInnerLoopSelectionFunc)( struct _tagPyUFuncObject *ufunc, PyArray_Descr **dtypes, @@ -148,8 +130,8 @@ typedef struct _tagPyUFuncObject { /* The number of elements in 'functions' and 'data' */ int ntypes; - /* Does not appear to be used */ - int check_return; + /* Used to be unused field 'check_return' */ + int reserved1; /* The name of the ufunc */ const char *name; @@ -204,11 +186,11 @@ typedef struct _tagPyUFuncObject { */ PyUFunc_LegacyInnerLoopSelectionFunc *legacy_inner_loop_selector; /* - * A function which returns an inner loop for the new mechanism - * in NumPy 1.7 and later. If provided, this is used, otherwise - * if NULL the legacy_inner_loop_selector is used instead. + * This was blocked off to be the "new" inner loop selector in 1.7, + * but this was never implemented. (This is also why the above + * selector is called the "legacy" selector.) */ - PyUFunc_InnerLoopSelectionFunc *inner_loop_selector; + void *reserved2; /* * A function which returns a masked inner loop for the ufunc. */ diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 779773101..4bc9582b4 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -2623,22 +2623,9 @@ PyUFunc_GenericFunction(PyUFuncObject *ufunc, else { NPY_UF_DBG_PRINT("Executing legacy inner loop\n"); - if (ufunc->legacy_inner_loop_selector != NULL) { - retval = execute_legacy_ufunc_loop(ufunc, trivial_loop_ok, - op, dtypes, order, - buffersize, arr_prep, arr_prep_args); - } - else { - /* - * TODO: When this is supported, it should be preferred over - * the legacy_inner_loop_selector - */ - PyErr_SetString(PyExc_RuntimeError, - "usage of the new inner_loop_selector isn't " - "implemented yet"); - retval = -1; - goto fail; - } + retval = execute_legacy_ufunc_loop(ufunc, trivial_loop_ok, + op, dtypes, order, + buffersize, arr_prep, arr_prep_args); } if (retval < 0) { goto fail; @@ -4480,10 +4467,10 @@ NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data, char *types, int ntypes, int nin, int nout, int identity, - const char *name, const char *doc, int check_return) + const char *name, const char *doc, int unused) { return PyUFunc_FromFuncAndDataAndSignature(func, data, types, ntypes, - nin, nout, identity, name, doc, check_return, NULL); + nin, nout, identity, name, doc, 0, NULL); } /*UFUNC_API*/ @@ -4492,7 +4479,7 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data, char *types, int ntypes, int nin, int nout, int identity, const char *name, const char *doc, - int check_return, const char *signature) + int unused, const char *signature) { PyUFuncObject *ufunc; @@ -4510,6 +4497,9 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data, } PyObject_Init((PyObject *)ufunc, &PyUFunc_Type); + ufunc->reserved1 = 0; + ufunc->reserved2 = NULL; + ufunc->nin = nin; ufunc->nout = nout; ufunc->nargs = nin+nout; @@ -4519,7 +4509,6 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data, ufunc->data = data; ufunc->types = types; ufunc->ntypes = ntypes; - ufunc->check_return = check_return; ufunc->ptr = NULL; ufunc->obj = NULL; ufunc->userloops=NULL; @@ -4527,7 +4516,6 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data, /* Type resolution and inner loop selection functions */ ufunc->type_resolver = &PyUFunc_DefaultTypeResolver; ufunc->legacy_inner_loop_selector = &PyUFunc_DefaultLegacyInnerLoopSelector; - ufunc->inner_loop_selector = NULL; ufunc->masked_inner_loop_selector = &PyUFunc_DefaultMaskedInnerLoopSelector; if (name == NULL) { diff --git a/numpy/core/src/umath/umathmodule.c b/numpy/core/src/umath/umathmodule.c index b1da2aeed..d19d5b9d2 100644 --- a/numpy/core/src/umath/umathmodule.c +++ b/numpy/core/src/umath/umathmodule.c @@ -123,7 +123,6 @@ ufunc_frompyfunc(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *NPY_UNUS self->identity = PyUFunc_None; self->functions = pyfunc_functions; self->ntypes = 1; - self->check_return = 0; /* generalized ufunc */ self->core_enabled = 0; |