diff --git a/include/boost/python/numpy/dtype.hpp b/include/boost/python/numpy/dtype.hpp index 32bb3d4a0..5d68c0ba6 100644 --- a/include/boost/python/numpy/dtype.hpp +++ b/include/boost/python/numpy/dtype.hpp @@ -56,7 +56,7 @@ class BOOST_NUMPY_DECL dtype : public object { * 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. @@ -70,37 +70,37 @@ class BOOST_NUMPY_DECL dtype : public object { }; -bool equivalent(dtype const & a, dtype const & b); +BOOST_NUMPY_DECL bool equivalent(dtype const & a, dtype const & b); namespace detail { -template dtype get_int_dtype(); - -template dtype get_float_dtype(); +template ::value> struct builtin_dtype; -template dtype get_complex_dtype(); +//INT INT INT INT INT INT INT INT INT INT INT INT INT INT INT INT INT INT -template ::value> -struct builtin_dtype; +template struct builtin_int_dtype; +template dtype get_int_dtype(); -template -struct builtin_dtype { +template struct builtin_dtype { static dtype get() { return get_int_dtype< 8*sizeof(T), boost::is_unsigned::value >(); } }; -template <> -struct builtin_dtype { - static dtype get(); -}; +//FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT + +template struct builtin_float_dtype; +template dtype get_float_dtype(); -template -struct builtin_dtype { +template struct builtin_dtype { static dtype get() { return get_float_dtype< 8*sizeof(T) >(); } }; -template -struct builtin_dtype< std::complex, false > { +//COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX + +template struct builtin_complex_dtype; +template dtype get_complex_dtype(); + +template struct builtin_dtype< std::complex, false > { static dtype get() { return get_complex_dtype< 16*sizeof(T) >(); } }; diff --git a/include/boost/python/numpy/invoke_matching.hpp b/include/boost/python/numpy/invoke_matching.hpp index 90ec8ae2c..893776117 100644 --- a/include/boost/python/numpy/invoke_matching.hpp +++ b/include/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 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 struct dtype_template_invoker diff --git a/include/boost/python/numpy/matrix.hpp b/include/boost/python/numpy/matrix.hpp index 43335e1fd..829f544af 100644 --- a/include/boost/python/numpy/matrix.hpp +++ b/include/boost/python/numpy/matrix.hpp @@ -61,7 +61,7 @@ class BOOST_NUMPY_DECL matrix : public ndarray * return a numpy.matrix instead. */ template -struct BOOST_NUMPY_DECL as_matrix : Base +struct as_matrix : Base { static PyObject * postcall(PyObject *, PyObject * result) { diff --git a/include/boost/python/numpy/ndarray.hpp b/include/boost/python/numpy/ndarray.hpp index 9ad0f20e4..870e0ade2 100644 --- a/include/boost/python/numpy/ndarray.hpp +++ b/include/boost/python/numpy/ndarray.hpp @@ -142,27 +142,27 @@ class BOOST_NUMPY_DECL ndarray : public object /** * @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, +BOOST_NUMPY_DECL ndarray from_data_impl(void * data, dtype const & dt, std::vector const & shape, std::vector const & strides, @@ -183,7 +183,7 @@ ndarray from_data_impl(void * data, return from_data_impl(data, dt, shape_, strides_, owner, writeable); } -ndarray from_data_impl(void * data, +BOOST_NUMPY_DECL ndarray from_data_impl(void * data, dtype const & dt, object const & shape, object const & strides, @@ -250,39 +250,39 @@ 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, +BOOST_NUMPY_DECL 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, +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, +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/include/boost/python/numpy/numpy_object_mgr_traits.hpp b/include/boost/python/numpy/numpy_object_mgr_traits.hpp index 8f9f44407..c526edba7 100644 --- a/include/boost/python/numpy/numpy_object_mgr_traits.hpp +++ b/include/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 + /** * @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 \ +struct BOOST_NUMPY_DECL object_manager_traits \ { \ BOOST_STATIC_CONSTANT(bool, is_specialized = true); \ static inline python::detail::new_reference adopt(PyObject* x) \ diff --git a/include/boost/python/numpy/scalars.hpp b/include/boost/python/numpy/scalars.hpp index 0ba23c41a..c2a83d825 100644 --- a/include/boost/python/numpy/scalars.hpp +++ b/include/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/include/boost/python/numpy/ufunc.hpp b/include/boost/python/numpy/ufunc.hpp index 4c2331c90..7502d5a23 100644 --- a/include/boost/python/numpy/ufunc.hpp +++ b/include/boost/python/numpy/ufunc.hpp @@ -62,13 +62,13 @@ class BOOST_NUMPY_DECL multi_iter : public object }; /// @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 @@ -94,7 +94,7 @@ multi_iter make_multi_iter(object const & a1, object const & a2, object const & template -struct unary_ufunc +struct BOOST_NUMPY_DECL unary_ufunc { /** @@ -158,7 +158,7 @@ template -struct binary_ufunc +struct BOOST_NUMPY_DECL binary_ufunc { static object diff --git a/src/numpy/dtype.cpp b/src/numpy/dtype.cpp index 13904ddde..44d12f3b9 100644 --- a/src/numpy/dtype.cpp +++ b/src/numpy/dtype.cpp @@ -10,31 +10,6 @@ #define BOOST_PYTHON_NUMPY_INTERNAL #include -#define DTYPE_FROM_CODE(code) \ - dtype(python::detail::new_reference(reinterpret_cast(PyArray_DescrFromType(code)))) - -#define BUILTIN_INT_DTYPE(bits) \ - template <> struct builtin_int_dtype< bits, false > { \ - static dtype get() { return DTYPE_FROM_CODE(NPY_INT ## bits); } \ - }; \ - template <> struct builtin_int_dtype< bits, true > { \ - static dtype get() { return DTYPE_FROM_CODE(NPY_UINT ## bits); } \ - }; \ - template dtype get_int_dtype< bits, false >(); \ - template dtype get_int_dtype< bits, true >() - -#define BUILTIN_FLOAT_DTYPE(bits) \ - template <> struct builtin_float_dtype< bits > { \ - static dtype get() { return DTYPE_FROM_CODE(NPY_FLOAT ## bits); } \ - }; \ - template dtype get_float_dtype< bits >() - -#define BUILTIN_COMPLEX_DTYPE(bits) \ - template <> struct builtin_complex_dtype< bits > { \ - static dtype get() { return DTYPE_FROM_CODE(NPY_COMPLEX ## bits); } \ - }; \ - template dtype get_complex_dtype< bits >() - namespace boost { namespace python { namespace converter { NUMPY_OBJECT_MANAGER_TRAITS_IMPL(PyArrayDescr_Type, numpy::dtype) } // namespace boost::python::converter @@ -42,36 +17,79 @@ NUMPY_OBJECT_MANAGER_TRAITS_IMPL(PyArrayDescr_Type, numpy::dtype) namespace numpy { namespace detail { -dtype builtin_dtype::get() { return DTYPE_FROM_CODE(NPY_BOOL); } +#define DTYPE_FROM_CODE(code) \ + dtype(python::detail::new_reference(reinterpret_cast(PyArray_DescrFromType(code)))) + + +//BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL -template struct builtin_int_dtype; -template struct builtin_float_dtype; -template struct builtin_complex_dtype; +template <> struct BOOST_NUMPY_DECL builtin_dtype { + static dtype get() { return DTYPE_FROM_CODE(NPY_BOOL); } +}; -template dtype get_int_dtype() { - return builtin_int_dtype::get(); +//INT INT INT INT INT INT INT INT INT INT INT INT INT INT INT INT INT INT + +#define BUILTIN_INT_DTYPE(bits) \ + template<> struct BOOST_NUMPY_DECL builtin_int_dtype< bits, false > { \ + static dtype get() { return DTYPE_FROM_CODE(NPY_INT ## bits); } \ + }; \ + template<> BOOST_NUMPY_DECL dtype get_int_dtype< bits, false >() { \ + return builtin_int_dtype< bits, false >::get(); \ + }; \ + template<> struct BOOST_NUMPY_DECL builtin_int_dtype< bits, true > { \ + static dtype get() { return DTYPE_FROM_CODE(NPY_UINT ## bits); } \ + }; \ + template<> BOOST_NUMPY_DECL dtype get_int_dtype< bits, true >() { \ + return builtin_int_dtype< bits, true >::get(); \ } -template dtype get_float_dtype() { return builtin_float_dtype::get(); } -template dtype get_complex_dtype() { return builtin_complex_dtype::get(); } BUILTIN_INT_DTYPE(8); BUILTIN_INT_DTYPE(16); BUILTIN_INT_DTYPE(32); BUILTIN_INT_DTYPE(64); + +//FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT + +#define BUILTIN_FLOAT_DTYPE(bits) \ + template <> struct BOOST_NUMPY_DECL builtin_float_dtype< bits > { \ + static dtype get() { return DTYPE_FROM_CODE(NPY_FLOAT ## bits); } \ + }; \ + template<> BOOST_NUMPY_DECL dtype get_float_dtype< bits >() { \ + return builtin_float_dtype::get(); \ + } + BUILTIN_FLOAT_DTYPE(16); BUILTIN_FLOAT_DTYPE(32); BUILTIN_FLOAT_DTYPE(64); -BUILTIN_COMPLEX_DTYPE(64); -BUILTIN_COMPLEX_DTYPE(128); + #if NPY_BITSOF_LONGDOUBLE > NPY_BITSOF_DOUBLE -template <> struct builtin_float_dtype< NPY_BITSOF_LONGDOUBLE > { +template <> struct BOOST_NUMPY_DECL builtin_float_dtype< NPY_BITSOF_LONGDOUBLE > { static dtype get() { return DTYPE_FROM_CODE(NPY_LONGDOUBLE); } }; -template dtype get_float_dtype< NPY_BITSOF_LONGDOUBLE >(); -template <> struct builtin_complex_dtype< 2 * NPY_BITSOF_LONGDOUBLE > { +template<> dtype BOOST_NUMPY_DECL get_float_dtype< NPY_BITSOF_LONGDOUBLE >(){ + return builtin_float_dtype::get(); +} +#endif + +//COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX COMPLEX + +#define BUILTIN_COMPLEX_DTYPE(bits) \ + template <> struct BOOST_NUMPY_DECL builtin_complex_dtype< bits > { \ + static dtype get() { return DTYPE_FROM_CODE(NPY_COMPLEX ## bits); } \ + }; \ + template<> BOOST_NUMPY_DECL dtype get_complex_dtype< bits >(){ \ + return builtin_complex_dtype::get(); \ +} + +BUILTIN_COMPLEX_DTYPE(64); +BUILTIN_COMPLEX_DTYPE(128); +#if NPY_BITSOF_LONGDOUBLE > NPY_BITSOF_DOUBLE +template <> struct BOOST_NUMPY_DECL builtin_complex_dtype< 2 * NPY_BITSOF_LONGDOUBLE > { static dtype get() { return DTYPE_FROM_CODE(NPY_CLONGDOUBLE); } }; -template dtype get_complex_dtype< 2 * NPY_BITSOF_LONGDOUBLE >(); +template<> dtype get_complex_dtype< 2 * NPY_BITSOF_LONGDOUBLE >() { + return builtin_complex_dtype<2 * NPY_BITSOF_LONGDOUBLE>::get(); +} #endif } // namespace detail