@@ -9,31 +9,39 @@ numpy_system(PyObject *self, PyObject *args)
99 int sts;
1010
1111 if (!PyArg_ParseTuple (args, " s" , &command))
12+ {
1213 return NULL ;
14+ }
15+
1316 sts = system (command);
1417 return PyLong_FromLong (sts);
1518}
1619
1720static PyObject *
18- numpy_add (PyObject *self, PyObject *args){
21+ numpy_add (PyObject *self, PyObject *args)
22+ {
1923 PyArrayObject *arr;
2024 PyArg_ParseTuple (args, " O" , &arr);
21- if (PyErr_Occurred ()){
25+ if (PyErr_Occurred ())
26+ {
2227 return NULL ;
2328 }
24- if (!PyArray_Check (arr) || PyArray_TYPE (arr) != NPY_DOUBLE) {
29+ if (!PyArray_Check (arr) || PyArray_TYPE (arr) != NPY_DOUBLE)
30+ {
2531 PyErr_SetString (PyExc_TypeError, " Argument must be a numpy array of type double!" );
2632 return NULL ;
2733 }
2834
2935
30- double *data = ( double *) PyArray_DATA (arr);
36+ double *data = reinterpret_cast < double *>( PyArray_DATA (arr) );
3137 int64_t size = PyArray_SIZE (arr);
3238
33- double total=0 ;
34- for (int i=0 ; i < size; i++){
39+ double total = 0 ;
40+ for (int i = 0 ; i < size; i++)
41+ {
3542 total += data[i];
3643 }
44+
3745 return PyFloat_FromDouble (total);
3846}
3947
@@ -42,13 +50,15 @@ static PyObject *SpamError = NULL;
4250static int
4351numpy_module_exec (PyObject *m)
4452{
45- if (SpamError != NULL ) {
53+ if (SpamError != NULL )
54+ {
4655 PyErr_SetString (PyExc_ImportError,
4756 " cannot initialize numpy module more than once" );
4857 return -1 ;
4958 }
5059 SpamError = PyErr_NewException (" numpy.error" , NULL , NULL );
51- if (PyModule_AddObjectRef (m, " SpamError" , SpamError) < 0 ) {
60+ if (PyModule_AddObjectRef (m, " SpamError" , SpamError) < 0 )
61+ {
5262 return -1 ;
5363 }
5464
@@ -62,7 +72,7 @@ static PyMethodDef numpy_methods[] = {
6272};
6373
6474static PyModuleDef_Slot numpy_module_slots[] = {
65- {Py_mod_exec, ( void *) numpy_module_exec},
75+ {Py_mod_exec, reinterpret_cast < void *>( numpy_module_exec) },
6676 {0 , NULL }
6777};
6878
0 commit comments