From 2695ada8b9f99d7d087672f142eebffd325886a4 Mon Sep 17 00:00:00 2001 From: Chris Jordan-Squire Date: Mon, 15 Aug 2011 11:30:16 -0500 Subject: Changed to follow PEP 7 --- doc/source/user/c-info.ufunc-tutorial.rst | 298 +++++++++++++++--------------- numpy/testing/utils.py | 2 +- 2 files changed, 145 insertions(+), 155 deletions(-) diff --git a/doc/source/user/c-info.ufunc-tutorial.rst b/doc/source/user/c-info.ufunc-tutorial.rst index d1d344099..f1adef59a 100644 --- a/doc/source/user/c-info.ufunc-tutorial.rst +++ b/doc/source/user/c-info.ufunc-tutorial.rst @@ -84,42 +84,46 @@ the module. #include /* - spammodule.c - This is the C code for a non-numpy Python extension to - define the logit function, where logit(p) = log(p/(1-p)). - This function will not work on numpy arrays automatically. - numpy.vectorize must be called in python to generate - a numpy-friendly function. - - Details explaining the Python-C API can be found under - 'Extending and Embedding' and 'Python/C API' at - docs.python.org . - */ + * spammodule.c + * This is the C code for a non-numpy Python extension to + * define the logit function, where logit(p) = log(p/(1-p)). + * This function will not work on numpy arrays automatically. + * numpy.vectorize must be called in python to generate + * a numpy-friendly function. + * + * Details explaining the Python-C API can be found under + * 'Extending and Embedding' and 'Python/C API' at + * docs.python.org . + */ /* This declares the logit function */ static PyObject* spam_logit(PyObject *self, PyObject *args); - /* This tells Python what methods this module has */ + /* + * This tells Python what methods this module has. + * See the Python-C API for more information. + */ static PyMethodDef SpamMethods[] = { - {"logit", spam_logit, METH_VARARGS, - "compute logit"}, + {"logit", + spam_logit, + METH_VARARGS, "compute logit"}, {NULL, NULL, 0, NULL} }; /* - This actually defines the logit function for - input args from Python. - */ - - static PyObject* spam_logit(PyObject *self, PyObject *args){ + * This actually defines the logit function for + * input args from Python. + */ + static PyObject* spam_logit(PyObject *self, PyObject *args) + { double p; /* This parses the Python argument into a double */ - if(!PyArg_ParseTuple(args, "d", &p)){ + if(!PyArg_ParseTuple(args, "d", &p)) { return NULL; } @@ -133,14 +137,14 @@ the module. /* This initiates the module using the above definitions. */ - PyMODINIT_FUNC initspam(void){ + PyMODINIT_FUNC initspam(void) + { PyObject *m; m = Py_InitModule("spam", SpamMethods); - if( m==NULL){ + if (m == NULL) { return; } - } To use the setup.py file, place setup.py and spammodule.c in the same @@ -224,39 +228,39 @@ the primary thing that must be changed to create your own ufunc. #include "numpy/halffloat.h" /* - single_type_logit.c - This is the C code for creating your own - Numpy ufunc for a logit function. - - In this code we only define the ufunc for - a single dtype. The computations that must - be replaced to create a ufunc for - a different funciton are marked with BEGIN - and END. - - Details explaining the Python-C API can be found under - 'Extending and Embedding' and 'Python/C API' at - docs.python.org . - - */ + * single_type_logit.c + * This is the C code for creating your own + * Numpy ufunc for a logit function. + * + * In this code we only define the ufunc for + * a single dtype. The computations that must + * be replaced to create a ufunc for + * a different funciton are marked with BEGIN + * and END. + * + * Details explaining the Python-C API can be found under + * 'Extending and Embedding' and 'Python/C API' at + * docs.python.org . + */ static PyMethodDef LogitMethods[] = { {NULL, NULL, 0, NULL} }; + /* The loop definition must precede the PyMODINIT_FUNC. */ static void double_logit(char **args, npy_intp *dimensions, - npy_intp* steps, void* data){ - + npy_intp* steps, void* data) + { npy_intp i; - npy_intp n=dimensions[0]; - char *in=args[0], *out=args[1]; - npy_intp in_step=steps[0], out_step=steps[1]; + npy_intp n = dimensions[0]; + char *in = args[0], *out = args[1]; + npy_intp in_step = steps[0], out_step = steps[1]; double tmp; - for(i=0; i