From e2c4bb106a6434028b258ffbf0ff95bdc39ad07d Mon Sep 17 00:00:00 2001 From: Chris Jordan-Squire Date: Wed, 17 Aug 2011 01:31:31 -0400 Subject: style changes and bugs removed from docs --- doc/source/user/c-info.ufunc-tutorial.rst | 102 ++++++++++++++++++------------ 1 file changed, 63 insertions(+), 39 deletions(-) (limited to 'doc') diff --git a/doc/source/user/c-info.ufunc-tutorial.rst b/doc/source/user/c-info.ufunc-tutorial.rst index 2eb479463..7d6e3f579 100644 --- a/doc/source/user/c-info.ufunc-tutorial.rst +++ b/doc/source/user/c-info.ufunc-tutorial.rst @@ -137,6 +137,29 @@ the module. /* This initiates the module using the above definitions. */ + #if PY_VERSION_HEX >= 0x03000000 + static struct PyModuleDef moduledef = { + PyModuleDef HEAT_INIT, + "spam", + NULL, + -1, + SpamMethods, + NULL, + NULL, + NULL, + NULL + }; + + PyObject *PyInit__npspam(void) + { + PyObject *m; + m = PyModule_Create(&moduledef); + if (!m) { + return NULL; + } + return m; + } + #else PyMODINIT_FUNC initspam(void) { PyObject *m; @@ -146,6 +169,7 @@ the module. return; } } + #endif To use the setup.py file, place setup.py and spammodule.c in the same folder. Then python setup.py build will build the module to import, @@ -275,11 +299,11 @@ the primary thing that must be changed to create your own ufunc. PyUFuncGenericFunction funcs[1] = {&double_logit}; /* These are the input and return dtypes of logit.*/ - char types[2] = {NPY_DOUBLE, NPY_DOUBLE}; + static char types[2] = {NPY_DOUBLE, NPY_DOUBLE}; - void *data[1] = {NULL}; + static void *data[1] = {NULL}; - #if defined(NPY_PY3K) + #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef moduledef = { PyModuleDef HEAT_INIT, "npspam", @@ -291,10 +315,9 @@ the primary thing that must be changed to create your own ufunc. NULL, NULL }; - #endif - #if defined(NPY_PY3K) - PyObject *PyInit__npspam(void) { + PyObject *PyInit__npspam(void) + { PyObject *m; m = PyModule_Create(&moduledef); if (!m) { @@ -373,7 +396,9 @@ or installed to site-packages via python setup.py install. import numpy from numpy.distutils.misc_util import Configuration - config = Configuration('npspam_directory', parent_package, top_path) + config = Configuration('npspam_directory', + parent_package, + top_path) config.add_extension('npspam', ['single_type_logit.c']) return config @@ -546,13 +571,13 @@ the primary thing that must be changed to create your own ufunc. &double_logit, &long_double_logit}; - char types[8] = {NPY_HALF, NPY_HALF, + static char types[8] = {NPY_HALF, NPY_HALF, NPY_FLOAT, NPY_FLOAT, NPY_DOUBLE,NPY_DOUBLE, NPY_LONGDOUBLE, NPY_LONGDOUBLE}; - void *data[4] = {NULL, NULL, NULL, NULL}; + static void *data[4] = {NULL, NULL, NULL, NULL}; - #if defined(NPY_PY3K) + #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef moduledef = { PyModuleDef HEAT_INIT, "npspam", @@ -564,10 +589,9 @@ the primary thing that must be changed to create your own ufunc. NULL, NULL }; - #endif - #if defined(NPY_PY3K) - PyObject *PyInit__npspam(void) { + PyObject *PyInit__npspam(void) + { PyObject *m; m = PyModule_Create(&moduledef); if (!m) { @@ -765,12 +789,13 @@ as well as all other properties of a ufunc. /* These are the input and return dtypes of logit.*/ - char types[4] = {NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE}; + static char types[4] = {NPY_DOUBLE, NPY_DOUBLE, + NPY_DOUBLE, NPY_DOUBLE}; - void *data[1] = {NULL}; + static void *data[1] = {NULL}; - #if defined(NPY_PY3K) + #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef moduledef = { PyModuleDef HEAT_INIT, "npspam", @@ -782,10 +807,9 @@ as well as all other properties of a ufunc. NULL, NULL }; - #endif - #if defined(NPY_PY3K) - PyObject *PyInit__npspam(void) { + PyObject *PyInit__npspam(void) + { PyObject *m; m = PyModule_Create(&moduledef); if (!m) { @@ -884,13 +908,15 @@ automatically generates a ufunc from a C function with the correct signature. void *extra) { npy_intp i; - npy_intp is1=steps[0], is2=steps[1]; - npy_intp os=steps[2], n=dimensions[0]; - char *i1=args[0], *i2=args[1], *op=args[2]; - for (i=0; i