File: capi

package info (click to toggle)
python-numpy 1%3A1.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,336 kB
  • ctags: 18,503
  • sloc: ansic: 149,662; python: 85,440; cpp: 968; makefile: 367; f90: 164; sh: 130; fortran: 125; perl: 58
file content (91 lines) | stat: -rwxr-xr-x 2,251 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
set -efu

PYS=$(pyversions -r 2>/dev/null)" "$(py3versions -r 2>/dev/null)

cd "$ADTTMP"

cat << EOF > setup.py
def configuration(parent_package='', top_path=None):
    from numpy.distutils.misc_util import Configuration

    config = Configuration('npufunc_directory', parent_package, top_path)
    config.add_extension('npufunc', ['ufunc.c'])

    return config

if __name__ == "__main__":
    from numpy.distutils.core import setup
    setup(configuration=configuration)
EOF


cat << EOF > ufunc.c
#include "Python.h"
#include "numpy/ndarraytypes.h"
#include "numpy/ufuncobject.h"

static PyMethodDef LogitMethods[] = {
        {NULL, NULL, 0, NULL}
};

static void double_logit(char **args, npy_intp *dimensions,
                         npy_intp* steps, void* data)
{
}

PyUFuncGenericFunction funcs[1] = {&double_logit};
static char types[4] = {NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE};
static void *data[1] = {NULL};

static void setupmodule(PyObject * m)
{
    PyObject * logit, * d;
    import_array();
    import_umath();
    logit = PyUFunc_FromFuncAndData(funcs, data, types, 4, 3, 1,
                                    PyUFunc_Zero, "logit",
                                    "logit_docstring", 0);
    d = PyModule_GetDict(m);
    PyDict_SetItemString(d, "logit", logit);
    Py_DECREF(logit);
}

#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef moduledef = {
    PyModuleDef_HEAD_INIT,
    "npufunc", NULL, -1,
    LogitMethods, NULL, NULL, NULL, NULL
};

PyMODINIT_FUNC PyInit_npufunc(void)
{
    PyObject * m = PyModule_Create(&moduledef);
    if (m == NULL) {
        return;
    }
    setupmodule(m);
    return m;
}
#else
PyMODINIT_FUNC initnpufunc(void)
{
    PyObject *m = Py_InitModule("npufunc", LogitMethods);
    if (m == NULL) {
        return;
    }
    setupmodule(m);
}
#endif
EOF

for py in $PYS; do
    echo "=== $py ==="
    $py setup.py build 2>&1
    $py-dbg setup.py build 2>&1
    $py setup.py install --prefix $PWD/inst 2>&1
    $py-dbg setup.py install --prefix $PWD/inst 2>&1
    export PYTHONPATH=$PWD/inst/lib/$py/site-packages/npufunc_directory
    $py -c "import npufunc; print(npufunc.logit(1,2,3))" 2>&1
    $py-dbg -c "import npufunc; print(npufunc.logit(1,2,3))" 2>&1
done