python3 setup.py build
Output: build/lib.macosx-10.11-x86_64-3.5/hello.cpython-35m-darwin.so
$ cd build/lib.macosx-10.11-x86_64-3.5
$ python3
>>> import hello
>>> hello.hello_world()
Hello, world!
>>> hello.hello('world')
Hello, world!
Tested on OS X 10.11.5, Python 3.5.2.
It's working good.
Hi ...i am not very familiar with c extension for python.I have some array calculation coding with c extension.but That's not working fine .am got some error when compile that code .anyone can help me...
I am currently trying to implement array multiplication with some formula in c .but don't really know how I would create empty array with input dimension and how to return from c function to extension main function.
My c code return array to main function.
#include "chie.h"
double chie(double m, double b, double *x, double *y, double *yerr, int N,double *result) {
int n;
double diff;
//double result = 0.0;
//static double result[5];
for (n = 0; n < N; n++) {
diff = (y[n] - (m * x[n] + b)) / yerr[n];
result[n]= diff * diff;
}
}
then how to i catch the c array returned data to empty array.
this is my c extension main code.
#include <Python.h>
#include <numpy/arrayobject.h>
#include "chie.h"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
static char module_docstring[] =
"This module provides an interface for calculating chi-squared using C.";
static char chie_docstring[] =
"Calculate the chi-squared of some data given a model.";
static PyObject *chi2_chi2(PyObject *self, PyObject *args);
static PyObject *chi2_chi2(PyObject *self, PyObject *args)
{
double m, b;
PyObject *x_obj, *y_obj, *yerr_obj;
double *result[5];
}
static PyMethodDef module_methods[] = {
{"chie", chi2_chi2, METH_VARARGS, chie_docstring},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef cieModule = {
PyModuleDef_HEAD_INIT,
"cieModule",
"example Module",
-1,
module_methods
};
/*PyMODINIT_FUNC PyInit_myexamp_Module(void)
{
return PyModule_Create(&myexamp_Module);
import_array();
}
*/
PyMODINIT_FUNC PyInit_cieModule(void)
{
PyObject *m;
m = PyModule_Create(&cieModule);
if (!m) {
return NULL;
}
import_array();
return m;
}