From 867898b02816af01c8543512e8b1c6012858690a Mon Sep 17 00:00:00 2001 From: vernepenn Date: Fri, 12 Jul 2019 22:53:34 +0800 Subject: [PATCH] =?UTF-8?q?python3=E8=AF=AD=E6=B3=95=E5=92=8Cgsl=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E8=B0=83=E6=95=B4=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Linux/LargeVismodule.cpp | 17 ++++++++++++----- Linux/setup.py | 2 +- Windows/LargeVismodule.cpp | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Linux/LargeVismodule.cpp b/Linux/LargeVismodule.cpp index bbc50d9..bb59cc1 100644 --- a/Linux/LargeVismodule.cpp +++ b/Linux/LargeVismodule.cpp @@ -94,7 +94,7 @@ static PyObject *LoadFromList(PyObject *self, PyObject *args) } for (long long j = 0; j < n_dim; ++j) { - real x = atof(PyString_AsString(PyObject_Str(PyList_GetItem(vec, j)))); + real x = atof(PyBytes_AsString(PyUnicode_AsUTF8String(PyObject_Str(PyList_GetItem(vec, j)) ))); data[ll + j] = x; } } @@ -123,9 +123,16 @@ static PyMethodDef PyExtMethods[] = { "save", SaveToFile, METH_VARARGS, "save(str filename)\nSave data to file." }, { NULL, NULL, 0, NULL } }; +static struct PyModuleDef LargeVismodule = +{ + PyModuleDef_HEAD_INIT, + "LargeVis", + NULL, + -1, + PyExtMethods +}; -PyMODINIT_FUNC initLargeVis() +PyMODINIT_FUNC PyInit_LargeVis(void) { - printf("LargeVis successfully imported!\n"); - Py_InitModule("LargeVis", PyExtMethods); -} + return PyModule_Create(&LargeVismodule); +}; diff --git a/Linux/setup.py b/Linux/setup.py index 029c8f5..026349c 100644 --- a/Linux/setup.py +++ b/Linux/setup.py @@ -3,7 +3,7 @@ LargeVis = Extension('LargeVis', sources = ['LargeVis.cpp', 'LargeVismodule.cpp'], depends=['LargeVis.h'], - include_dirs = ['/usr/local/include'], + include_dirs = ['/usr/local/include/gsl'], library_dirs = ['/usr/local/lib'], libraries=['gsl', 'gslcblas'], extra_compile_args=['-lm -pthread -lgsl -lgslcblas -Ofast -march=native -ffast-math']) diff --git a/Windows/LargeVismodule.cpp b/Windows/LargeVismodule.cpp index bbc50d9..bb59cc1 100644 --- a/Windows/LargeVismodule.cpp +++ b/Windows/LargeVismodule.cpp @@ -94,7 +94,7 @@ static PyObject *LoadFromList(PyObject *self, PyObject *args) } for (long long j = 0; j < n_dim; ++j) { - real x = atof(PyString_AsString(PyObject_Str(PyList_GetItem(vec, j)))); + real x = atof(PyBytes_AsString(PyUnicode_AsUTF8String(PyObject_Str(PyList_GetItem(vec, j)) ))); data[ll + j] = x; } } @@ -123,9 +123,16 @@ static PyMethodDef PyExtMethods[] = { "save", SaveToFile, METH_VARARGS, "save(str filename)\nSave data to file." }, { NULL, NULL, 0, NULL } }; +static struct PyModuleDef LargeVismodule = +{ + PyModuleDef_HEAD_INIT, + "LargeVis", + NULL, + -1, + PyExtMethods +}; -PyMODINIT_FUNC initLargeVis() +PyMODINIT_FUNC PyInit_LargeVis(void) { - printf("LargeVis successfully imported!\n"); - Py_InitModule("LargeVis", PyExtMethods); -} + return PyModule_Create(&LargeVismodule); +};