From b988e8c45f3e7f1c9376146d1881b7099db2a2a8 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Sun, 25 Jul 2010 00:18:18 +0000 Subject: [PATCH] boost.python.numpy - adding missing symbols, fixed constness in dtype --- boost/python/numpy/dtype.hpp | 23 +++++++++++++++++++++-- libs/python/numpy/src/dtype.cpp | 5 +++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/boost/python/numpy/dtype.hpp b/boost/python/numpy/dtype.hpp index cb1666b5..edbde0e0 100644 --- a/boost/python/numpy/dtype.hpp +++ b/boost/python/numpy/dtype.hpp @@ -47,7 +47,7 @@ public: BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dtype, object); template - void invoke_matching_template(Function f); + void invoke_matching_template(Function f) const; }; @@ -83,10 +83,29 @@ private: Function m_func; }; +template +struct dtype_template_invoker< boost::reference_wrapper > { + + template + void operator()(T * x) const { + if (dtype::get_builtin() == m_dtype) { + m_func.template apply(); + throw dtype_template_match_found(); + } + } + + dtype_template_invoker(dtype const & dtype_, Function & func) : + m_dtype(dtype_), m_func(func) {} + +private: + dtype const & m_dtype; + Function & m_func; +}; + } // namespace boost::python::numpy::detail template -void dtype::invoke_matching_template(Function f) { +void dtype::invoke_matching_template(Function f) const { detail::dtype_template_invoker invoker(*this, f); try { boost::mpl::for_each< Sequence, detail::add_pointer_meta >(invoker); diff --git a/libs/python/numpy/src/dtype.cpp b/libs/python/numpy/src/dtype.cpp index 852038e7..fc882ac9 100644 --- a/libs/python/numpy/src/dtype.cpp +++ b/libs/python/numpy/src/dtype.cpp @@ -30,6 +30,10 @@ template dtype dtype::get_builtin< std::complex >() namespace boost { namespace python { +namespace converter { +NUMPY_OBJECT_MANAGER_TRAITS_IMPL(PyArrayDescr_Type, python::numpy::dtype) +} // namespace boost::python::converter + namespace numpy { template struct dtype_traits; @@ -61,6 +65,7 @@ NUMPY_DTYPE_TRAITS_BUILTIN(npy_uint, NPY_UINT); NUMPY_DTYPE_TRAITS_BUILTIN(npy_int, NPY_INT); NUMPY_DTYPE_TRAITS_BUILTIN(npy_ulong, NPY_ULONG); NUMPY_DTYPE_TRAITS_BUILTIN(npy_long, NPY_LONG); +NUMPY_DTYPE_TRAITS_BUILTIN(npy_longlong, NPY_LONGLONG); NUMPY_DTYPE_TRAITS_BUILTIN(npy_float, NPY_FLOAT); NUMPY_DTYPE_TRAITS_BUILTIN(npy_double, NPY_DOUBLE); NUMPY_DTYPE_TRAITS_BUILTIN(npy_longdouble, NPY_LONGDOUBLE);