$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r65794 - in sandbox/numpy: boost/python/numpy libs/python/numpy/test
From: talljimbo_at_[hidden]
Date: 2010-10-06 18:40:44
Author: jbosch
Date: 2010-10-06 18:40:41 EDT (Wed, 06 Oct 2010)
New Revision: 65794
URL: http://svn.boost.org/trac/boost/changeset/65794
Log:
boost.python.numpy - switched to simpler syntax for invoke_matching_array
Text files modified: 
   sandbox/numpy/boost/python/numpy/invoke_matching.hpp   |    61 ++++++++++++++++++++++----------------- 
   sandbox/numpy/libs/python/numpy/test/templates_mod.cpp |    20 +++---------                            
   2 files changed, 40 insertions(+), 41 deletions(-)
Modified: sandbox/numpy/boost/python/numpy/invoke_matching.hpp
==============================================================================
--- sandbox/numpy/boost/python/numpy/invoke_matching.hpp	(original)
+++ sandbox/numpy/boost/python/numpy/invoke_matching.hpp	2010-10-06 18:40:41 EDT (Wed, 06 Oct 2010)
@@ -9,6 +9,8 @@
 #include <boost/python/numpy/dtype.hpp>
 #include <boost/python/numpy/ndarray.hpp>
 
+#include <boost/mpl/integral_c.hpp>
+
 namespace boost { namespace python { namespace numpy {
 
 namespace detail {
@@ -29,9 +31,9 @@
 struct dtype_template_invoker {
     
     template <typename T>
-    void operator()(T * x) const {
+    void operator()(T *) const {
         if (dtype::get_builtin<T>() == m_dtype) {
-            m_func.apply(x);
+            m_func.template apply<T>();
             throw dtype_template_match_found();
         }
     }
@@ -48,9 +50,9 @@
 struct dtype_template_invoker< boost::reference_wrapper<Function> > {
     
     template <typename T>
-    void operator()(T * x) const {
+    void operator()(T *) const {
         if (dtype::get_builtin<T>() == m_dtype) {
-            m_func.apply(x);
+            m_func.template apply<T>();
             throw dtype_template_match_found();
         }
     }
@@ -66,10 +68,10 @@
 template <typename Function>
 struct nd_template_invoker {
     
-    template <typename T>
-    void operator()(T * x) const {
-        if (m_nd == T::value) {
-            m_func.apply(x);
+    template <int N>
+    void operator()(boost::mpl::integral_c<int,N> *) const {
+        if (m_nd == N) {
+            m_func.template apply<N>();
             throw nd_template_match_found();
         }
     }
@@ -85,10 +87,10 @@
 template <typename Function>
 struct nd_template_invoker< boost::reference_wrapper<Function> > {
     
-    template <typename T>
-    void operator()(T * x) const {
-        if (m_nd == T::value) {
-            m_func.apply(x);
+    template <int N>
+    void operator()(boost::mpl::integral_c<int,N> *) const {
+        if (m_nd == N) {
+            m_func.template apply<N>();
             throw nd_template_match_found();
         }
     }
@@ -129,31 +131,30 @@
 
 namespace detail {
 
-template <typename DimSequence, typename Function>
-struct array_template_invoker_wrapper {
+template <typename T, typename Function>
+struct array_template_invoker_wrapper_2 {
 
-    template <typename T>
-    void apply(T * x) const {
-        invoke_matching_nd<DimSequence>(m_nd, m_func.nest(x));
+    template <int N>
+    void apply() const {
+        m_func.template apply<T,N>();
     }
 
-    array_template_invoker_wrapper(int nd, Function func) :
-        m_nd(nd), m_func(func) {}
+    array_template_invoker_wrapper_2(Function & func) :
+        m_func(func) {}
 
 private:
-    int m_nd;
-    Function m_func;
+    Function & m_func;
 };
 
 template <typename DimSequence, typename Function>
-struct array_template_invoker_wrapper< DimSequence, boost::reference_wrapper<Function> > {
+struct array_template_invoker_wrapper_1 {
 
     template <typename T>
-    void apply(T * x) const {
-        invoke_matching_nd<DimSequence>(m_nd, m_func.nest(x));
+    void apply() const {
+        invoke_matching_nd<DimSequence>(m_nd, array_template_invoker_wrapper_2<T,Function>(m_func));
     }
 
-    array_template_invoker_wrapper(int nd, Function & func) :
+    array_template_invoker_wrapper_1(int nd, Function & func) :
         m_nd(nd), m_func(func) {}
 
 private:
@@ -161,11 +162,19 @@
     Function & m_func;
 };
 
+template <typename DimSequence, typename Function>
+struct array_template_invoker_wrapper_1< DimSequence, boost::reference_wrapper<Function> >
+    : public array_template_invoker_wrapper_1< DimSequence, Function >
+{
+    array_template_invoker_wrapper_1(int nd, Function & func) :
+        array_template_invoker_wrapper_1< DimSequence, Function >(nd, func) {}
+};
+
 } // namespace boost::python::numpy::detail
 
 template <typename TypeSequence, typename DimSequence, typename Function>
 void invoke_matching_array(ndarray const & array_, Function f) {
-    detail::array_template_invoker_wrapper<DimSequence,Function> wrapper(array_.get_nd(), f);
+    detail::array_template_invoker_wrapper_1<DimSequence,Function> wrapper(array_.get_nd(), f);
     invoke_matching_dtype<TypeSequence>(array_.get_dtype(), wrapper);
 }
 
Modified: sandbox/numpy/libs/python/numpy/test/templates_mod.cpp
==============================================================================
--- sandbox/numpy/libs/python/numpy/test/templates_mod.cpp	(original)
+++ sandbox/numpy/libs/python/numpy/test/templates_mod.cpp	2010-10-06 18:40:41 EDT (Wed, 06 Oct 2010)
@@ -9,19 +9,16 @@
     typedef boost::mpl::vector< short, int, float, std::complex<double> > TypeSequence;
     typedef boost::mpl::vector_c< int, 1, 2 > DimSequence;
 
-    template <typename T>
-    struct nested {
-
-        void apply(boost::mpl::integral_c<int,1> * ) const {
+    template <typename T, int N>
+    void apply() const {
+        if (N == 1) {
             char * p = argument.get_data();
             int stride = argument.strides(0);
             int size = argument.shape(0);
             for (int n = 0; n != size; ++n, p += stride) {
                 *reinterpret_cast<T*>(p) = static_cast<T>(n);
             }
-        }
-
-        void apply(boost::mpl::integral_c<int,2> * ) const {
+        } else {
             char * row_p = argument.get_data();
             int row_stride = argument.strides(0);
             int col_stride = argument.strides(1);
@@ -35,14 +32,7 @@
                 }
             }
         }
-
-        explicit nested(bp::numpy::ndarray const & arg) : argument(arg) {}
-
-        bp::numpy::ndarray argument;
-    };
-
-    template <typename T>
-    nested<T> nest(T *) const { return nested<T>(argument); }
+    }
 
     bp::numpy::ndarray argument;