Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75138 - sandbox/variadic_templates/sandbox/stepper/boost/array_stepper
From: cppljevans_at_[hidden]
Date: 2011-10-27 13:50:13


Author: cppljevans
Date: 2011-10-27 13:50:12 EDT (Thu, 27 Oct 2011)
New Revision: 75138
URL: http://svn.boost.org/trac/boost/changeset/75138

Log:
index_stack_length_stride_crtp.hpp:
  now has rotation feature used in implementing Alternating Directions
  Implicit method for solving PDE's.
array_store_print.hpp changed to use simple wrapper around a
  class from index_stack_length_stride_crtp.hpp.

Text files modified:
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_store_print.hpp | 138 ++++++++++++++++++++++++++--------
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/index_stack_length_stride_crtp.hpp | 158 +++++++++++++++++++++++++++++++--------
   2 files changed, 230 insertions(+), 66 deletions(-)

Modified: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_store_print.hpp
==============================================================================
--- sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_store_print.hpp (original)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_store_print.hpp 2011-10-27 13:50:12 EDT (Thu, 27 Oct 2011)
@@ -2,11 +2,11 @@
 #define BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_HPP_INCLUDED
 
 #include <boost/array_stepper/array_store.hpp>
-#if 1
+#if 0
 #include <boost/array_stepper/array_host.hpp>
 #include <boost/iostreams/utility/indent_scoped_ostreambuf.hpp>
 #else
-#include <boost/array_stepper/length_stride_offset_iter_stack.hpp>
+#include <boost/array_stepper/index_stack_length_stride_crtp.hpp>
 #include <iostream>
 #include <iomanip>
 //#define BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
@@ -15,7 +15,7 @@
 #endif
 #endif
 
-#ifndef BOOST_ARRAY_STEPPER_LENGTH_STRIDE_OFFSET_ITER_STACK_HPP_INCLUDED
+#ifndef BOOST_ARRAY_STEPPER_INDEX_STACK_LENGTH_STRIDE_CRTP_HPP_INCLUDED
 namespace boost
 {
 namespace array_stepper
@@ -96,73 +96,114 @@
   template
   < typename T
>
+ struct
+array_iter_wrap
+{
+ typedef typename boost::array_stepper::array_store<T> arr_t;
+ typedef typename arr_t::data_t::const_iterator iter_t;
+ typedef typename arr_t::domain_t domain_t;
+ typedef typename domain_t::stride_t stride_t;
+ typedef
+ boost::array_stepper::index_stack_length_stride_crtp_indices<stride_t>
+ lsos_t;
+ array_iter_wrap
+ ( iter_t a_iter
+ , lsos_t a_lsos
+ )
+ : my_iter(a_iter)
+ , my_lsos(a_lsos)
+ {}
+ iter_t const
+ my_iter;
+ lsos_t const
+ my_lsos;
+};
+ template
+ < typename T
+ >
   std::ostream&
 operator<<
 ( std::ostream& sout
-, boost::array_stepper::array_store<T>const& a_arr
+, array_iter_wrap<T>const& a_arr_iter
 )
 {
- #ifdef BOOST_ARRAY_STEPPER_LENGTH_STRIDE_OFFSET_ITER_STACK_HPP_INCLUDED
- typedef typename boost::array_stepper::array_store<T> arr_t;
- typedef typename arr_t::domain_t domain_t;
- typedef boost::array_stepper::length_stride_offset_iter_stack<> lsos_t;
- lsos_t
- lsos_v
- ( a_arr.length_strides().begin()
- , a_arr.length_strides().end()
- );
- typedef typename arr_t::data_t data_t;
- data_t const& data_v=a_arr.data();
- int const n=data_v.size();
- typename lsos_t::indices_t const& indices_v=lsos_v.indices();
- int const axis_max=indices_v.size()-1;
- int axis_now= axis_max;
- int axis_pre=-1;
- for(int l=axis_pre; l<axis_now; ++l)
+ typedef array_iter_wrap<T> arr_iter_t;
+ typedef typename arr_iter_t::lsos_t lsos_t;
+ typedef typename arr_iter_t::iter_t iter_t;
+ typedef typename lsos_t::axis_depth_t axis_depth_t;
+ unsigned const margin=2;
+ auto depth_indent=[]( axis_depth_t ad)->int
+ {
+ return (ad-1)*margin;
+ };
+ iter_t data_v(a_arr_iter.my_iter);
+ lsos_t lsos_v(a_arr_iter.my_lsos);
+ int const n=lsos_v.space();
+ axis_depth_t axis_now= lsos_v.axis_begin();
+ #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
+ axis_depth_t const axis_max=axis_now;
+ #endif
+ axis_depth_t axis_pre=lsos_t::axis_end;
+ for(axis_depth_t l=axis_pre; l<axis_now; ++l)
     { //open 1st element for all axes.
         sout<<"{ ";
     }
- for(int i=0; i<n; ++i,axis_pre=axis_now,axis_now=++lsos_v)
+ for
+ ( int i=0
+ ; i<n
+ ; ++i
+ , axis_pre=axis_now
+ , axis_now=++lsos_v
+ )
     {
         if(axis_now<axis_pre)
         { //exiting one element and starting next.
- for(int l=axis_pre; axis_now<l; --l)
+ for(axis_depth_t l=axis_pre; axis_now<l; --l)
             { //close axis_pre to axis_now elements.
                 if(l!=axis_pre)
- sout<<std::setw(l*2)<<"";
+ sout<<std::setw(l*margin)<<"";
                 sout<<"}\n";
             }
- sout<<std::setw(axis_now*2)<<""<<", ";//put delimiter between elements
- for(int l=axis_pre; axis_now<l; --l)
+ sout<<std::setw(depth_indent(axis_now))<<""<<", ";//put delimiter between elements
+ for(axis_depth_t l=axis_pre; axis_now<l; --l)
             { //open axis_now to axis_pre elements.
                 sout<<"{ ";
             }
           #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
- sout<<"(axis_now<axis_pre)";
+ sout<<"(:axis_now="<<axis_now<<"<"<<"axis_pre="<<axis_pre<<")";
             BOOST_ASSERT(axis_pre == axis_max);
           #endif
         }
- else if(-1<axis_pre)
+ else if(lsos_t::axis_end<axis_pre)
         { sout<<", ";//put delimiter between elements
           #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
- sout<<"(-1<axis_pre)";
- BOOST_ASSERT( axis_now==axis_max && 0<indices_v[axis_now]);
+ sout<<"(axis_end<axis_pre)";
+ auto ibs=lsos_v[axis_now-1];
+ auto index_now=ibs.template get<boost::array_stepper::index_value>();
+ sout
+ <<":axis_now="<<axis_now
+ <<":axis_max="<<axis_max
+ <<":index_now="<<index_now
+ <<"\n";
+ BOOST_ASSERT( axis_now==axis_max && 0<index_now);
           #endif
         }
+ auto const offset=lsos_v.offset_space_val();
       #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
         sout
           <<":i="<<std::setw(2)<<i
           <<":axis_pre="<<axis_pre
           <<":axis_now="<<axis_now
+ <<":offset="<<offset
           <<":v="
           ;
       #endif
- sout<<data_v[lsos_v.offset()];
+ sout<<data_v[offset];
     }
- for(int l=axis_pre; axis_now<l; --l)
+ for(axis_depth_t l=axis_pre; axis_now<l; --l)
     {//close axis_pre to axis_now elements.
         if(l!=axis_pre)
- sout<<std::setw(l*2)<<"";
+ sout<<std::setw(depth_indent(l))<<"";
         sout<<"}\n";
     }
     #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
@@ -172,6 +213,37 @@
       <<"\n"
       ;
     #endif
+ return sout;
+}
+ template
+ < typename T
+ >
+ std::ostream&
+operator<<
+( std::ostream& sout
+, boost::array_stepper::array_store<T>const& a_arr
+)
+{
+ #ifdef BOOST_ARRAY_STEPPER_INDEX_STACK_LENGTH_STRIDE_CRTP_HPP_INCLUDED
+ typedef typename boost::array_stepper::array_store<T> arr_t;
+ typedef typename arr_t::domain_t domain_t;
+ typedef typename domain_t::stride_t stride_t;
+ typedef
+ boost::array_stepper::index_stack_length_stride_crtp_indices<stride_t>
+ lsos_t;
+ lsos_t
+ lsos_v
+ ( a_arr.length_strides().begin()
+ , a_arr.length_strides().end()
+ );
+ typedef typename arr_t::data_t data_t;
+ auto const offset0=a_arr.offset();
+ #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
+ sout<<"offset0="<<offset0<<"\n";
+ #endif
+ typename data_t::const_iterator data_v=a_arr.data().begin()+offset0;
+ array_iter_wrap<T> aiw(data_v,lsos_v);
+ sout<<aiw;
   #else
     boost::array_stepper::array_store_print<T> a_viz(sout);
     boost::array_stepper::array_host<boost::array_stepper::array_store<T> const> host_arr(a_arr);

Modified: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/index_stack_length_stride_crtp.hpp
==============================================================================
--- sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/index_stack_length_stride_crtp.hpp (original)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/index_stack_length_stride_crtp.hpp 2011-10-27 13:50:12 EDT (Thu, 27 Oct 2011)
@@ -118,6 +118,7 @@
         offset_index_bounds
           (
           )
+ #ifndef __clang__
         : super_t
           ({{ 0
             , 0
@@ -125,6 +126,7 @@
             }
            }
           )
+ #endif
         {}
           template
           < index_bounds_value_enum IBV
@@ -239,7 +241,7 @@
           stride_t
         stride_val()const
         {
- my_ls.stride();
+ return my_ls.stride();
         }
           stride_t
         length_val()const
@@ -265,10 +267,14 @@
           length_stride_iter_t
         my_lsi
         ;
+ axis_t
+ my_rotation
+ ;
      public:
         indices_bounds_strides
           ( axis_t a_rank
           , length_stride_iter_t const& a_lsi
+ , axis_t a_rotation=0
           )
         : my_oib
           ( a_rank
@@ -276,6 +282,9 @@
         , my_lsi
           ( a_lsi
           )
+ , my_rotation
+ ( a_rotation
+ )
         {}
         
           axis_t
@@ -283,21 +292,70 @@
         {
             return my_oib.size();
         }
-
+ axis_t
+ axis_rotated(axis_t a_axis)const
+ {
+ return (my_rotation+a_axis)%rank();
+ }
+ axis_t
+ rotate(axis_t a_rotation)
+ /**@brief
+ * Rotate axes to the left by a_rotation positions.
+ */
+ {
+ my_rotation=axis_rotated(a_rotation);
+ return my_rotation;
+ }
+ axis_t
+ rotation()const
+ {
+ return my_rotation;
+ }
           index_bound_stride<mutable_yes>
         operator[](axis_t a_axis)
         {
- offset_index_bounds&oib=my_oib[a_axis];
- length_stride_t const&ls=my_lsi[a_axis];
+ axis_t const r_axis=axis_rotated(a_axis);
+ offset_index_bounds&oib=my_oib[r_axis];
+ length_stride_t const&ls=my_lsi[r_axis];
             return index_bound_stride<mutable_yes>( oib, ls);
         }
           index_bound_stride<mutable_not>
         operator[](axis_t a_axis)const
         {
- offset_index_bounds const&oib=my_oib[a_axis];
- length_stride_t const&ls=my_lsi[a_axis];
+ axis_t const r_axis=axis_rotated(a_axis);
+ offset_index_bounds const&oib=my_oib[r_axis];
+ length_stride_t const&ls=my_lsi[r_axis];
             return index_bound_stride<mutable_not>( oib, ls);
         }
+ typedef
+ std::vector<index_t>
+ indices_t
+ ;
+ indices_t
+ indices()const
+ {
+ axis_t const n_axis=rank();
+ indices_t indices_v(n_axis);
+ for(axis_t i_axis=0; i_axis<n_axis; ++i_axis)
+ {
+ offset_index_bounds const&oib=my_oib[i_axis];
+ indices_v[i_axis]=oib.template val<index_value>();
+ }
+ return indices_v;
+ }
+ indices_t
+ indices_rotated()const
+ {
+ axis_t const n_axis=rank();
+ indices_t indices_v(n_axis);
+ for(axis_t i_axis=0; i_axis<n_axis; ++i_axis)
+ {
+ axis_t const r_axis=axis_rotated(i_axis);
+ offset_index_bounds const&oib=my_oib[r_axis];
+ indices_v[i_axis]=oib.template val<index_value>();
+ }
+ return indices_v;
+ }
     };
 };
 
@@ -407,45 +465,65 @@
       index_stack_concrete_t&
     derived()
     {
- *static_cast<index_stack_concrete_t*>(this);
+ return static_cast<index_stack_concrete_t&>(*this);
     }
       index_stack_concrete_t const&
     derived()const
     {
- *static_cast<index_stack_concrete_t const*>(this);
+ return static_cast<index_stack_concrete_t const&>(*this);
+ }
+ typedef
+ unsigned
+ axis_depth_t
+ ;
+ static
+ axis_depth_t const
+ axis_end=0
+ /**@brief
+ * The value returned from inc_dec_ator indicating
+ * all indices changed.
+ */
+ ;
+ axis_depth_t
+ axis_begin()const
+ {
+ return derived().rank();
     }
       template
       < inc_dec_enum ID
>
- int
+ axis_depth_t
     inc_dec_ator()
       /**@brief
        * increment (if ID==inc_ator) or decrement(if ID==dec_ator) the indices
        * 1 at a time, from rightmost to leftmost.
        * IOW, the rightmost index increments fastest, and
        * the leftmost index increments slowest.
+ * Rightmost corresponds to top of stack.
+ * Leftmost corresponds to bottom of stack.
+ * Returns the depth of the stack containing unchanged
+ * indices.
        */
     {
         index_stack_concrete_t&der=derived();
         typedef inc_dec_concrete<ID> conc_t;
         auto& offset_space=der.offset_space_ref();
- int const n=der.rank();
- int axis=n-1;//increment 1st rightmost index.
+ axis_depth_t axis_depth_v=axis_begin();//change 1st rightmost index.
       //#define TRACE_INC_DEC_ATOR
- while( 0<=axis)
+ while( axis_end<axis_depth_v)
         {
- auto ibs=der[axis];
+ auto ibs=der[axis_depth_v-1];
             auto& index_axis=ibs.template get<index_value>();
             auto bound_limit_axis=ibs.template bound<conc_t::bound_limit>();
             auto stride_axis=ibs.stride_val();
           #ifdef TRACE_INC_DEC_ATOR
             std::cout
- <<"inc_dec_ator::before:axis="<<axis
+ <<"inc_dec_ator::before:axis_depth_v="<<axis_depth_v
               <<":index_axis="<<index_axis
               <<":bound_limit_axis="<<bound_limit_axis
               <<"\n";
           #endif
- if( index_axis == bound_limit_axis)//if axis-th index at triggeer bound, then
+ if( index_axis == bound_limit_axis)//if axis_depth_v-th index at trigger bound, then
             {
                 { //reset index_axis to bound opposite to bound_limit_axis:
                     auto bound_reset_axis=ibs.template bound<conc_t::bound_reset>();
@@ -456,7 +534,7 @@
                     index_axis=bound_reset_axis;
                 }
                   //then proceed to increment/decrement next (in left direction) index in loop.
- --axis;
+ --axis_depth_v;
             }
             else
             { //just cnahge index_axis, offset_space, and exit loop.
@@ -465,19 +543,19 @@
             }
           #ifdef TRACE_INC_DEC_ATOR
             std::cout
- <<"inc_dec_ator::after:axis="<<axis
+ <<"inc_dec_ator::after:axis_depth_v="<<axis_depth_v
               <<":index_axis="<<index_axis
               <<"\n";
           #endif
         }
- return axis;
+ return axis_depth_v;
     }
- int
+ axis_depth_t
     operator++()
     {
         return inc_dec_ator<inc_ator>();
     }
- int
+ axis_depth_t
     operator--()
     {
         return inc_dec_ator<dec_ator>();
@@ -548,11 +626,14 @@
     }
 
       void
- axis_offset_put
+ axis_offsets_put
       ( axis_t a_axis
- , index_t a_offset_lower
- , index_t a_offset_upper
+ , index_t a_offset_lower=0
+ , index_t a_offset_upper=0
       )
+ /**@brief
+ * Reset the boundary offsets for given axis.
+ */
     {
         derived_t&der=derived();
         auto ibs=der[a_axis];
@@ -567,6 +648,24 @@
         my_space*=l_new;
     }
 
+ void
+ axes_offsets_put
+ ( index_t offset_lower=0
+ , index_t offset_upper=0
+ )
+ {//call axis_offset_put for each axis.
+ axis_t const
+ n_axis=derived().rank();
+ for
+ ( axis_t i_axis=0
+ ; i_axis<n_axis
+ ; ++i_axis
+ )
+ {
+ axis_offsets_put( i_axis, offset_lower, offset_upper);
+ }
+ }
+
       derived_t&
     derived()
     {
@@ -701,16 +800,9 @@
   )
   {
       sout<<"{ offset="<<std::setw(2)<<lsos_v.offset_space_val();
- sout<<", indices=";
- sout<<"{ ";
- for(unsigned axis=0; axis<lsos_v.rank(); ++axis)
- {
- if(0<axis)sout<<", ";
- auto ibs=lsos_v[axis];
- auto index=ibs.template get<boost::array_stepper::index_value>();
- sout<<std::setw(2)<<index;
- }
- sout<<"} ";
+ sout<<", rotation="<<lsos_v.rotation();
+ sout<<", rotated indices=";
+ sout<<lsos_v.indices_rotated();
       sout<<"}";
       return sout;
   }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk