diff options
Diffstat (limited to 'boost/python/numpy')
-rw-r--r-- | boost/python/numpy/config.hpp | 78 | ||||
-rw-r--r-- | boost/python/numpy/dtype.hpp | 7 | ||||
-rw-r--r-- | boost/python/numpy/invoke_matching.hpp | 6 | ||||
-rw-r--r-- | boost/python/numpy/matrix.hpp | 4 | ||||
-rw-r--r-- | boost/python/numpy/ndarray.hpp | 79 | ||||
-rw-r--r-- | boost/python/numpy/numpy_object_mgr_traits.hpp | 4 | ||||
-rw-r--r-- | boost/python/numpy/scalars.hpp | 2 | ||||
-rw-r--r-- | boost/python/numpy/ufunc.hpp | 9 |
8 files changed, 145 insertions, 44 deletions
diff --git a/boost/python/numpy/config.hpp b/boost/python/numpy/config.hpp new file mode 100644 index 0000000000..6f39d3ce86 --- /dev/null +++ b/boost/python/numpy/config.hpp @@ -0,0 +1,78 @@ +// (C) Copyright Samuli-Petrus Korhonen 2017. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// The author gratefully acknowleges the support of NMR Solutions, Inc., in +// producing this work. + +// Revision History: +// 15 Feb 17 Initial version + +#ifndef CONFIG_NUMPY20170215_H_ +# define CONFIG_NUMPY20170215_H_ + +# include <boost/config.hpp> + +/***************************************************************************** + * + * Set up dll import/export options: + * + ****************************************************************************/ + +// backwards compatibility: +#ifdef BOOST_NUMPY_STATIC_LIB +# define BOOST_NUMPY_STATIC_LINK +# elif !defined(BOOST_NUMPY_DYNAMIC_LIB) +# define BOOST_NUMPY_DYNAMIC_LIB +#endif + +#if defined(BOOST_NUMPY_DYNAMIC_LIB) +# if defined(BOOST_SYMBOL_EXPORT) +# if defined(BOOST_NUMPY_SOURCE) +# define BOOST_NUMPY_DECL BOOST_SYMBOL_EXPORT +# define BOOST_NUMPY_DECL_FORWARD BOOST_SYMBOL_FORWARD_EXPORT +# define BOOST_NUMPY_DECL_EXCEPTION BOOST_EXCEPTION_EXPORT +# define BOOST_NUMPY_BUILD_DLL +# else +# define BOOST_NUMPY_DECL BOOST_SYMBOL_IMPORT +# define BOOST_NUMPY_DECL_FORWARD BOOST_SYMBOL_FORWARD_IMPORT +# define BOOST_NUMPY_DECL_EXCEPTION BOOST_EXCEPTION_IMPORT +# endif +# endif + +#endif + +#ifndef BOOST_NUMPY_DECL +# define BOOST_NUMPY_DECL +#endif + +#ifndef BOOST_NUMPY_DECL_FORWARD +# define BOOST_NUMPY_DECL_FORWARD +#endif + +#ifndef BOOST_NUMPY_DECL_EXCEPTION +# define BOOST_NUMPY_DECL_EXCEPTION +#endif + +// enable automatic library variant selection ------------------------------// + +#if !defined(BOOST_NUMPY_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_NUMPY_NO_LIB) +// +// Set the name of our library, this will get undef'ed by auto_link.hpp +// once it's done with it: +// +#define BOOST_LIB_NAME boost_numpy +// +// If we're importing code from a dll, then tell auto_link.hpp about it: +// +#ifdef BOOST_NUMPY_DYNAMIC_LIB +# define BOOST_DYN_LINK +#endif +// +// And include the header that does the work: +// +#include <boost/config/auto_link.hpp> +#endif // auto-linking disabled + +#endif // CONFIG_NUMPY20170215_H_ diff --git a/boost/python/numpy/dtype.hpp b/boost/python/numpy/dtype.hpp index 1284f9e5d8..b9e95f9beb 100644 --- a/boost/python/numpy/dtype.hpp +++ b/boost/python/numpy/dtype.hpp @@ -14,6 +14,7 @@ #include <boost/python.hpp> #include <boost/python/numpy/numpy_object_mgr_traits.hpp> +#include <boost/python/numpy/config.hpp> #include <boost/mpl/for_each.hpp> #include <boost/type_traits/add_pointer.hpp> @@ -25,7 +26,7 @@ namespace boost { namespace python { namespace numpy { * * @todo This could have a lot more interesting accessors. */ -class dtype : public object { +class BOOST_NUMPY_DECL dtype : public object { static python::detail::new_reference convert(object::object_cref arg, bool align); public: @@ -55,7 +56,7 @@ public: * This is more permissive than equality tests. For instance, if long and int are the same * size, the dtypes corresponding to each will be equivalent, but not equal. */ - friend bool equivalent(dtype const & a, dtype const & b); + friend BOOST_NUMPY_DECL bool equivalent(dtype const & a, dtype const & b); /** * @brief Register from-Python converters for NumPy's built-in array scalar types. @@ -69,7 +70,7 @@ public: }; -bool equivalent(dtype const & a, dtype const & b); +BOOST_NUMPY_DECL bool equivalent(dtype const & a, dtype const & b); namespace detail { diff --git a/boost/python/numpy/invoke_matching.hpp b/boost/python/numpy/invoke_matching.hpp index 90ec8ae2cb..095ca3a8db 100644 --- a/boost/python/numpy/invoke_matching.hpp +++ b/boost/python/numpy/invoke_matching.hpp @@ -19,7 +19,7 @@ namespace boost { namespace python { namespace numpy { namespace detail { -struct add_pointer_meta +struct BOOST_NUMPY_DECL add_pointer_meta { template <typename T> struct apply @@ -29,8 +29,8 @@ struct add_pointer_meta }; -struct dtype_template_match_found {}; -struct nd_template_match_found {}; +struct BOOST_NUMPY_DECL dtype_template_match_found {}; +struct BOOST_NUMPY_DECL nd_template_match_found {}; template <typename Function> struct dtype_template_invoker diff --git a/boost/python/numpy/matrix.hpp b/boost/python/numpy/matrix.hpp index af20e8f9be..829f544af5 100644 --- a/boost/python/numpy/matrix.hpp +++ b/boost/python/numpy/matrix.hpp @@ -14,6 +14,8 @@ #include <boost/python.hpp> #include <boost/python/numpy/numpy_object_mgr_traits.hpp> #include <boost/python/numpy/ndarray.hpp> +#include <boost/python/numpy/config.hpp> + namespace boost { namespace python { namespace numpy { @@ -27,7 +29,7 @@ namespace boost { namespace python { namespace numpy { * bad things happen when Python shuts down. I think this solution is safe, but I'd * love to get that confirmed. */ -class matrix : public ndarray +class BOOST_NUMPY_DECL matrix : public ndarray { static object construct(object_cref obj, dtype const & dt, bool copy); static object construct(object_cref obj, bool copy); diff --git a/boost/python/numpy/ndarray.hpp b/boost/python/numpy/ndarray.hpp index 2985907b5b..e5b6a9e94b 100644 --- a/boost/python/numpy/ndarray.hpp +++ b/boost/python/numpy/ndarray.hpp @@ -16,6 +16,8 @@ #include <boost/type_traits/is_integral.hpp> #include <boost/python/numpy/numpy_object_mgr_traits.hpp> #include <boost/python/numpy/dtype.hpp> +#include <boost/python/numpy/config.hpp> + #include <vector> namespace boost { namespace python { namespace numpy { @@ -26,7 +28,8 @@ namespace boost { namespace python { namespace numpy { * @todo This could have a lot more functionality (like boost::python::numeric::array). * Right now all that exists is what was needed to move raw data between C++ and Python. */ -class ndarray : public object + +class BOOST_NUMPY_DECL ndarray : public object { /** @@ -139,32 +142,32 @@ public: /** * @brief Construct a new array with the given shape and data type, with data initialized to zero. */ -ndarray zeros(python::tuple const & shape, dtype const & dt); -ndarray zeros(int nd, Py_intptr_t const * shape, dtype const & dt); +BOOST_NUMPY_DECL ndarray zeros(python::tuple const & shape, dtype const & dt); +BOOST_NUMPY_DECL ndarray zeros(int nd, Py_intptr_t const * shape, dtype const & dt); /** * @brief Construct a new array with the given shape and data type, with data left uninitialized. */ -ndarray empty(python::tuple const & shape, dtype const & dt); -ndarray empty(int nd, Py_intptr_t const * shape, dtype const & dt); +BOOST_NUMPY_DECL ndarray empty(python::tuple const & shape, dtype const & dt); +BOOST_NUMPY_DECL ndarray empty(int nd, Py_intptr_t const * shape, dtype const & dt); /** * @brief Construct a new array from an arbitrary Python sequence. * * @todo This does't seem to handle ndarray subtypes the same way that "numpy.array" does in Python. */ -ndarray array(object const & obj); -ndarray array(object const & obj, dtype const & dt); +BOOST_NUMPY_DECL ndarray array(object const & obj); +BOOST_NUMPY_DECL ndarray array(object const & obj, dtype const & dt); namespace detail { -ndarray from_data_impl(void * data, - dtype const & dt, - std::vector<Py_intptr_t> const & shape, - std::vector<Py_intptr_t> const & strides, - object const & owner, - bool writeable); +BOOST_NUMPY_DECL ndarray from_data_impl(void * data, + dtype const & dt, + std::vector<Py_intptr_t> const & shape, + std::vector<Py_intptr_t> const & strides, + object const & owner, + bool writeable); template <typename Container> ndarray from_data_impl(void * data, @@ -180,12 +183,12 @@ ndarray from_data_impl(void * data, return from_data_impl(data, dt, shape_, strides_, owner, writeable); } -ndarray from_data_impl(void * data, - dtype const & dt, - object const & shape, - object const & strides, - object const & owner, - bool writeable); +BOOST_NUMPY_DECL ndarray from_data_impl(void * data, + dtype const & dt, + object const & shape, + object const & strides, + object const & owner, + bool writeable); } // namespace boost::python::numpy::detail @@ -247,39 +250,53 @@ inline ndarray from_data(void const * data, * @param[in] nd_max Maximum number of dimensions. * @param[in] flags Bitwise OR of flags specifying additional requirements. */ -ndarray from_object(object const & obj, dtype const & dt, - int nd_min, int nd_max, ndarray::bitflag flags=ndarray::NONE); - -inline ndarray from_object(object const & obj, dtype const & dt, - int nd, ndarray::bitflag flags=ndarray::NONE) +BOOST_NUMPY_DECL ndarray from_object(object const & obj, + dtype const & dt, + int nd_min, + int nd_max, + ndarray::bitflag flags=ndarray::NONE); + +BOOST_NUMPY_DECL inline ndarray from_object(object const & obj, + dtype const & dt, + int nd, + ndarray::bitflag flags=ndarray::NONE) { return from_object(obj, dt, nd, nd, flags); } -inline ndarray from_object(object const & obj, dtype const & dt, ndarray::bitflag flags=ndarray::NONE) +BOOST_NUMPY_DECL inline ndarray from_object(object const & obj, + dtype const & dt, + ndarray::bitflag flags=ndarray::NONE) { return from_object(obj, dt, 0, 0, flags); } -ndarray from_object(object const & obj, int nd_min, int nd_max, - ndarray::bitflag flags=ndarray::NONE); +BOOST_NUMPY_DECL ndarray from_object(object const & obj, + int nd_min, + int nd_max, + ndarray::bitflag flags=ndarray::NONE); -inline ndarray from_object(object const & obj, int nd, ndarray::bitflag flags=ndarray::NONE) +BOOST_NUMPY_DECL inline ndarray from_object(object const & obj, + int nd, + ndarray::bitflag flags=ndarray::NONE) { return from_object(obj, nd, nd, flags); } -inline ndarray from_object(object const & obj, ndarray::bitflag flags=ndarray::NONE) +BOOST_NUMPY_DECL inline ndarray from_object(object const & obj, + ndarray::bitflag flags=ndarray::NONE) { return from_object(obj, 0, 0, flags); } -inline ndarray::bitflag operator|(ndarray::bitflag a, ndarray::bitflag b) +BOOST_NUMPY_DECL inline ndarray::bitflag operator|(ndarray::bitflag a, + ndarray::bitflag b) { return ndarray::bitflag(int(a) | int(b)); } -inline ndarray::bitflag operator&(ndarray::bitflag a, ndarray::bitflag b) +BOOST_NUMPY_DECL inline ndarray::bitflag operator&(ndarray::bitflag a, + ndarray::bitflag b) { return ndarray::bitflag(int(a) & int(b)); } diff --git a/boost/python/numpy/numpy_object_mgr_traits.hpp b/boost/python/numpy/numpy_object_mgr_traits.hpp index 8f9f444074..a138f4cd52 100644 --- a/boost/python/numpy/numpy_object_mgr_traits.hpp +++ b/boost/python/numpy/numpy_object_mgr_traits.hpp @@ -7,6 +7,8 @@ #ifndef boost_python_numpy_numpy_object_mgr_traits_hpp_ #define boost_python_numpy_numpy_object_mgr_traits_hpp_ +#include <boost/python/numpy/config.hpp> + /** * @brief Macro that specializes object_manager_traits by requiring a * source-file implementation of get_pytype(). @@ -14,7 +16,7 @@ #define NUMPY_OBJECT_MANAGER_TRAITS(manager) \ template <> \ -struct object_manager_traits<manager> \ +struct BOOST_NUMPY_DECL object_manager_traits<manager> \ { \ BOOST_STATIC_CONSTANT(bool, is_specialized = true); \ static inline python::detail::new_reference adopt(PyObject* x) \ diff --git a/boost/python/numpy/scalars.hpp b/boost/python/numpy/scalars.hpp index 0ba23c41ac..c2a83d8253 100644 --- a/boost/python/numpy/scalars.hpp +++ b/boost/python/numpy/scalars.hpp @@ -22,7 +22,7 @@ namespace boost { namespace python { namespace numpy { * * @todo This could have a lot more functionality. */ -class void_ : public object +class BOOST_NUMPY_DECL void_ : public object { static python::detail::new_reference convert(object_cref arg, bool align); public: diff --git a/boost/python/numpy/ufunc.hpp b/boost/python/numpy/ufunc.hpp index 9262b37840..7e249238af 100644 --- a/boost/python/numpy/ufunc.hpp +++ b/boost/python/numpy/ufunc.hpp @@ -15,6 +15,7 @@ #include <boost/python/numpy/numpy_object_mgr_traits.hpp> #include <boost/python/numpy/dtype.hpp> #include <boost/python/numpy/ndarray.hpp> +#include <boost/python/numpy/config.hpp> namespace boost { namespace python { namespace numpy { @@ -34,7 +35,7 @@ namespace boost { namespace python { namespace numpy { * It's more dangerous than most object managers, however - maybe it actually belongs in * a detail namespace? */ -class multi_iter : public object +class BOOST_NUMPY_DECL multi_iter : public object { public: @@ -61,13 +62,13 @@ public: }; /// @brief Construct a multi_iter over a single sequence or scalar object. -multi_iter make_multi_iter(object const & a1); +BOOST_NUMPY_DECL multi_iter make_multi_iter(object const & a1); /// @brief Construct a multi_iter by broadcasting two objects. -multi_iter make_multi_iter(object const & a1, object const & a2); +BOOST_NUMPY_DECL multi_iter make_multi_iter(object const & a1, object const & a2); /// @brief Construct a multi_iter by broadcasting three objects. -multi_iter make_multi_iter(object const & a1, object const & a2, object const & a3); +BOOST_NUMPY_DECL multi_iter make_multi_iter(object const & a1, object const & a2, object const & a3); /** * @brief Helps wrap a C++ functor taking a single scalar argument as a broadcasting ufunc-like |