8000 ENH: implement nep 0015: merge multiarray and umath by mattip · Pull Request #10915 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: implement nep 0015: merge multiarray and umath #10915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MAINT: move scalar math intialization to before setup_scalartypes
  • Loading branch information
mattip committed Aug 21, 2018
commit 92f01dd0f900f2013e11080061711e5d47fc1c93
38 changes: 35 additions & 3 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "structmember.h"

#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _UMATHMODULE 10000
#define _MULTIARRAYMODULE
#include <numpy/npy_common.h>
#include "numpy/arrayobject.h"
Expand Down Expand Up @@ -68,6 +69,19 @@ NPY_NO_EXPORT int NPY_NUMUSERTYPES = 0;

#include "numpy/ufuncobject.h"
#include "ufunc_object.h"
/*
*****************************************************************************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be more logical to have this contained in a separate umathmodule.h file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there may be unused includes, reworking

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cleaned this up by removing many uneeded include directives

** INCLUDE GENERATED CODE **
*****************************************************************************
*/
#include "funcs.inc"
#include "loops.h"
#include "ufunc_object.h"
#include "ufunc_type_resolution.h"
#include "__umath_generated.c"
#include "__ufunc_api.c"

NPY_NO_EXPORT int initscalarmath(PyObject *);

/*
* global variable to determine if legacy printing is enabled, accessible from
Expand Down Expand Up @@ -4402,9 +4416,6 @@ static struct PyMethodDef array_module_methods[] = {
static int
setup_scalartypes(PyObject *NPY_UNUSED(dict))
{
initialize_casting_tables();
initialize_numeric_types();

if (PyType_Ready(&PyBool_Type) < 0) {
return -1;
}
Expand Down Expand Up @@ -4704,6 +4715,17 @@ PyMODINIT_FUNC init_multiarray_umath(void) {
* static structure slots with functions from the Python C_API.
*/
PyArray_Type.tp_hash = PyObject_HashNotImplemented;

/* Load the ufunc operators into the array module's namespace */
if (InitOperators(d) < 0) {
goto err;
}

initialize_casting_tables();
initialize_numeric_types();
if(initscalarmath(m) < 0)
goto err;

if (PyType_Ready(&PyArray_Type) < 0) {
goto err;
}
Expand Down Expand Up @@ -4750,6 +4772,16 @@ PyMODINIT_FUNC init_multiarray_umath(void) {
PyDict_SetItemString(d, "_ARRAY_API", c_api);
Py_DECREF(c_api);

c_api = NpyCapsule_FromVoidPtr((void *)PyUFunc_API, NULL);
if (c_api == NULL) {
goto err;
}
PyDict_SetItemString(d, "_UFUNC_API", c_api);
Py_DECREF(c_api);
if (PyErr_Occurred()) {
goto err;
}

/*
* PyExc_Exception should catch all the standard errors that are
* now raised instead of the string exception "multiarray.error"
Expand Down
33 changes: 1 addition & 32 deletions numpy/core/src/umath/umathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@

#include "numpy/npy_math.h"

/*
*****************************************************************************
** INCLUDE GENERATED CODE **
*****************************************************************************
*/
#include "funcs.inc"
#include "loops.h"
#include "ufunc_object.h"
#include "ufunc_type_resolution.h"
#include "__umath_generated.c"
#include "__ufunc_api.c"

NPY_NO_EXPORT int initscalarmath(PyObject *);

static PyUFuncGenericFunction pyfunc_functions[] = {PyUFunc_On_Om};

static int
Expand Down Expand Up @@ -294,7 +280,7 @@ static struct PyMethodDef methods[] = {

int initumath(PyObject *m)
{
PyObject *d, *s, *s2, *c_api;
PyObject *d, *s, *s2;
int UFUNC_FLOATING_POINT_SUPPORT = 1;

#ifdef NO_UFUNC_FLOATING_POINT_SUPPORT
Expand All @@ -317,21 +303,6 @@ int initumath(PyObject *m)
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);

c_api = NpyCapsule_FromVoidPtr((void *)PyUFunc_API, NULL);
if (PyErr_Occurred()) {
goto err;
}
PyDict_SetItemString(d, "_UFUNC_API", c_api);
Py_DECREF(c_api);
if (PyErr_Occurred()) {
goto err;
}

/* Load the ufunc operators into the array module's namespace */
if (InitOperators(d) < 0) {
goto err;
}

PyDict_SetItemString(d, "pi", s = PyFloat_FromDouble(NPY_PI));
Py_DECREF(s);
PyDict_SetItemString(d, "e", s = PyFloat_FromDouble(NPY_E));
Expand Down Expand Up @@ -388,8 +359,6 @@ int initumath(PyObject *m)
PyDict_SetItemString(d, "conj", s);
PyDict_SetItemString(d, "mod", s2);

initscalarmath(m);

if (!intern_strings()) {
goto err;
}
Expand Down
0