diff --git a/src/numpy_init.hpp b/src/numpy_init.hpp deleted file mode 100644 index 2cf7fe0760ea8e37618960eae240c0ff5b329bd6..0000000000000000000000000000000000000000 --- a/src/numpy_init.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Numpy import/init -// -// Copyright (C) 2009 Andreas Kloeckner -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. - - -#ifndef _FAYHVVAAA_PYOPENCL_HEADER_SEEN_NUMPY_INIT_HPP -#define _FAYHVVAAA_PYOPENCL_HEADER_SEEN_NUMPY_INIT_HPP - - -// #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION -#include -#include - - -namespace -{ - static struct pyublas_array_importer - { - static bool do_import_array() - { -#ifdef PYPY_VERSION - import_array(); -#else - import_array1(false); -#endif - return true; - } - - pyublas_array_importer() - { - if (!do_import_array()) - throw std::runtime_error("numpy failed to initialize"); - } - } _array_importer; -} - - - - -#endif diff --git a/src/tools.hpp b/src/tools.hpp index 7fd906ef3263376304d8c05dda28156976a67976..f64f443fd98bca9b0ddd0c66cedaa01c276521df 100644 --- a/src/tools.hpp +++ b/src/tools.hpp @@ -31,8 +31,7 @@ #include #include -#include "numpy_init.hpp" - +#include diff --git a/src/wrap_cl.cpp b/src/wrap_cl.cpp index 2ea3d5913524a2000d03f719165a6208e5d1381a..b9393ed0f4963968d7006d686e72c349eebc20ad 100644 --- a/src/wrap_cl.cpp +++ b/src/wrap_cl.cpp @@ -24,6 +24,8 @@ // OTHER DEALINGS IN THE SOFTWARE. +#define PY_ARRAY_UNIQUE_SYMBOL pyopencl_ARRAY_API + #include "wrap_cl.hpp" @@ -39,8 +41,21 @@ extern void pyopencl_expose_part_1(py::module &m); extern void pyopencl_expose_part_2(py::module &m); extern void pyopencl_expose_mempool(py::module &m); +static bool import_numpy_helper() +{ +#ifdef PYPY_VERSION + import_array(); +#else + import_array1(false); +#endif + return true; +} + PYBIND11_MODULE(_cl, m) { + if (!import_numpy_helper()) + throw py::error_already_set(); + pyopencl_expose_constants(m); pyopencl_expose_part_1(m); pyopencl_expose_part_2(m); diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index ae59fa25b2302740936d9e6262e415fc5151deea..71e3d067971bdf843fa723f32cec77e9ec3e45a7 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -84,7 +84,7 @@ #include #include #include "wrap_helpers.hpp" -#include "numpy_init.hpp" +#include #include "tools.hpp" #ifdef PYOPENCL_PRETEND_CL_VERSION diff --git a/src/wrap_cl_part_1.cpp b/src/wrap_cl_part_1.cpp index a87158f95344ba3e0c1edcffbffc98966bf22c81..541201e38bde65625ffe527ebd225d466e4025c8 100644 --- a/src/wrap_cl_part_1.cpp +++ b/src/wrap_cl_part_1.cpp @@ -24,6 +24,9 @@ // OTHER DEALINGS IN THE SOFTWARE. +#define NO_IMPORT_ARRAY +#define PY_ARRAY_UNIQUE_SYMBOL pyopencl_ARRAY_API + #include "wrap_cl.hpp" diff --git a/src/wrap_cl_part_2.cpp b/src/wrap_cl_part_2.cpp index 4ef6afca9244a0f9e4bacca026e899d9519a1637..5ca5efcf658bc7a81f2c67c265427486d6c4dfc4 100644 --- a/src/wrap_cl_part_2.cpp +++ b/src/wrap_cl_part_2.cpp @@ -24,6 +24,9 @@ // OTHER DEALINGS IN THE SOFTWARE. +#define NO_IMPORT_ARRAY +#define PY_ARRAY_UNIQUE_SYMBOL pyopencl_ARRAY_API + #include "wrap_cl.hpp" diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp index 48a165c08afbef8b11648e4cad3c979fb727ea3e..258df2781283a4ee3834aa72b68b011402ac93f9 100644 --- a/src/wrap_constants.cpp +++ b/src/wrap_constants.cpp @@ -24,6 +24,9 @@ // OTHER DEALINGS IN THE SOFTWARE. +#define NO_IMPORT_ARRAY +#define PY_ARRAY_UNIQUE_SYMBOL pyopencl_ARRAY_API + #include "wrap_cl.hpp" diff --git a/src/wrap_mempool.cpp b/src/wrap_mempool.cpp index 31cae81e3e5f3df58e7acf7d2e89e720e6de79a5..e29110ec25caf46cbf8d11a4d653772e6068789a 100644 --- a/src/wrap_mempool.cpp +++ b/src/wrap_mempool.cpp @@ -28,6 +28,9 @@ // first to prevent OS X from overriding a bunch of macros. (e.g. isspace) #include +#define NO_IMPORT_ARRAY +#define PY_ARRAY_UNIQUE_SYMBOL pyopencl_ARRAY_API + #include #include #include "wrap_helpers.hpp"