#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <Python.h>
#include <numpy/arrayobject.h>
#include <stdio.h>
extern void inc_array(PyArrayObject*, double);
extern void not_inc_array(PyArrayObject*, double);
static PyObject* py_inc_array(PyObject* self, PyObject* args) {
PyObject *obj = NULL;
double inc = 0.0;
if (!PyArg_ParseTuple(args, "Od", &obj, &inc))
return NULL;
PyArrayObject *arr = (PyArrayObject *)PyArray_FROM_OTF(obj, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
if (arr == NULL)
return NULL;
inc_array(arr, inc);
Py_DECREF(arr);
Py_RETURN_NONE;
}
static PyObject* py_not_inc_array(PyObject* self, PyObject* args) {
PyObject *obj = NULL;
double inc = 0.0;
if (!PyArg_ParseTuple(args, "Od", &obj, &inc))
return NULL;
PyArrayObject *arr = (PyArrayObject *)PyArray_FROM_OTF(obj, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
if (arr == NULL)
return NULL;
not_inc_array(arr, inc);
Py_DECREF(arr);
Py_RETURN_NONE;
}
static PyMethodDef MyMethods[] = {
{"inc_array", py_inc_array, METH_VARARGS, "Increace the values of numpy array"},
{"not_inc_array", py_not_inc_array, METH_VARARGS, "Not increase the values of numpy array"},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef c_module = {
PyModuleDef_HEAD_INIT,
"c_module",
NULL,
-1,
MyMethods
};
PyMODINIT_FUNC PyInit_c_module(void) {
import_array();
return PyModule_Create(&c_module);
}