Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72719 - in sandbox/variadic_templates/sandbox/stepper: . boost boost/array_stepper libs libs/array_stepper libs/array_stepper/examples
From: cppljevans_at_[hidden]
Date: 2011-06-22 16:14:42


Author: cppljevans
Date: 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
New Revision: 72719
URL: http://svn.boost.org/trac/boost/changeset/72719

Log:
An attempt to use ideas in _An Apl Compiler_ in design of c++ multidim array

Added:
   sandbox/variadic_templates/sandbox/stepper/
   sandbox/variadic_templates/sandbox/stepper/README.txt (contents, props changed)
   sandbox/variadic_templates/sandbox/stepper/boost/
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_own.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_own_print.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/mk_iota.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/permutation0_last.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/stepper_offset.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/stepper/libs/
   sandbox/variadic_templates/sandbox/stepper/libs/array_stepper/
   sandbox/variadic_templates/sandbox/stepper/libs/array_stepper/examples/
   sandbox/variadic_templates/sandbox/stepper/libs/array_stepper/examples/array_own.cpp (contents, props changed)
   sandbox/variadic_templates/sandbox/stepper/libs/array_stepper/examples/stepper_offset.cpp (contents, props changed)

Added: sandbox/variadic_templates/sandbox/stepper/README.txt
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/README.txt 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
@@ -0,0 +1,24 @@
+WHAT:
+
+ This directory contains code which attempts to use the ideas in
+
+ _An Apl Compiler_
+ Timothy Budd
+ Springer-Verlag 1988
+
+ to implement multi-dimensional arrays in c++.
+
+STATUS:
+
+ *VERY* preliminary. Just a few example codes in libs/*/examples
+ directories.
+
+FUTURE:
+
+ Maybe none, depending on how much time and desire I have to
+ work on it.
+
+AUTHOR:
+
+ Larry Evans
+

Added: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_own.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_own.hpp 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
@@ -0,0 +1,436 @@
+#ifndef BOOST_ARRAY_STEPPER_ARRAY_OWN_HPP_INCLUDED
+#define BOOST_ARRAY_STEPPER_ARRAY_OWN_HPP_INCLUDED
+#include <boost/array_stepper/stepper_offset.hpp>
+namespace boost
+{
+namespace array_stepper
+{
+
+ enum
+array_type
+{ arr_own //array that owns its data.
+, arr_ref //array that references data belonging to an arr_own.
+, arr_cref//same as arr_ref but data is const.
+};
+
+ template
+ < typename Value
+ , typename Index=int
+ , array_type ArrType=arr_own
+ >
+struct array
+;
+ template
+ < typename Value
+ , typename Index
+ >
+struct array_data
+ : stepper_offset<Index>
+{
+ typedef
+ stepper_offset<Index>
+ domain_t
+ ;
+ typedef
+ typename domain_t::index_t
+ index_t
+ ;
+ typedef
+ typename domain_t::axis_t
+ axis_t
+ ;
+ typedef
+ typename domain_t::lengths_t
+ lengths_t
+ ;
+ typedef
+ typename domain_t::offset_t
+ offset_t
+ ;
+ typedef
+ Value
+ value_t
+ ;
+ typedef
+ std::vector<Value>
+ data_t
+ ;
+ array_data
+ ( lengths_t const& a_lengths
+ , permut_predefined a_permut_pred=permut_default
+ )
+ : domain_t(a_lengths.size())
+ , my_data
+ ( this->domain_t::init_strides
+ ( a_lengths
+ , permutation0_last<axis_t>::permute_select(a_permut_pred)(a_lengths.size())
+ )
+ )
+ {
+ }
+
+ void
+ reshape
+ ( lengths_t const& a_lengths
+ , permut_predefined a_permut_pred=permut_default
+ )
+ {
+ this->stepper_ones().resize(a_lengths.size());
+ offset_t new_size=
+ this->domain_t::init_strides
+ ( a_lengths
+ , permutation0_last<axis_t>::permute_select(a_permut_pred)(a_lengths.size())
+ );
+ my_data.resize(new_size);
+ }
+
+ data_t&
+ data()
+ {
+ return my_data;
+ }
+ data_t const&
+ data()const
+ {
+ return my_data;
+ }
+
+ private:
+ data_t
+ my_data
+ ;
+};
+
+ template
+ < typename Value
+ , typename Index
+ >
+struct array
+ < Value
+ , Index
+ , arr_cref
+ >
+{
+ typedef
+ stepper_offset<Index>
+ domain_t
+ ;
+ typedef
+ typename domain_t::axis_t
+ axis_t
+ ;
+ typedef
+ typename domain_t::index_t
+ index_t
+ ;
+ typedef
+ typename domain_t::lengths_t
+ lengths_t
+ ;
+ typedef
+ typename domain_t::offset_t
+ offset_t
+ ;
+ typedef
+ Value
+ value_t
+ ;
+ typedef
+ std::vector<Value>
+ data_t
+ ;
+ typedef
+ typename data_t::const_iterator
+ data_iter_t
+ ;
+ typedef
+ typename domain_t::const_iterator
+ domain_iter_t
+ ;
+ array
+ ( array_data< Value, Index>const& a_val
+ , index_t a_index
+ )
+ : my_data_iter
+ ( a_val.data().begin()
+ + a_val.offset()
+ + a_val.stepper_ones().front().offset(a_index)
+ )
+ , my_domain_iter(a_val.domain_t::begin()+1)
+ , my_rank(a_val.rank()-1)
+ {
+ }
+ array
+ ( array< Value, Index, arr_cref>const& a_val
+ , index_t a_index
+ )
+ : my_data_iter
+ ( a_val.my_data_iter
+ + a_val.my_domain_iter->offset(a_index)
+ )
+ , my_domain_iter(a_val.my_domain_iter+1)
+ , my_rank(a_val.my_rank-1)
+ {
+ }
+
+ axis_t
+ rank()const
+ {
+ return my_rank;
+ }
+
+ index_t
+ size()const
+ {
+ typename domain_t::stepper_one_t const&s1=*my_domain_iter;
+ return s1[stepr_length];
+ }
+ value_t const&
+ operator()()const
+ {
+ return *my_data_iter;
+ }
+
+ value_t const&
+ operator()(index_t a_index)const
+ {
+ auto l_offset=my_domain_iter->offset(a_index);
+ return *(my_data_iter+l_offset);
+ }
+
+ array< value_t, Index, arr_cref>
+ operator[](index_t a_index)const
+ {
+ return array< value_t, Index, arr_cref>( *this, a_index);
+ }
+
+ private:
+ data_iter_t
+ my_data_iter
+ ;
+ domain_iter_t
+ my_domain_iter
+ ;
+ axis_t
+ my_rank
+ ;
+};
+
+ template
+ < typename Value
+ , typename Index
+ >
+struct array
+ < Value
+ , Index
+ , arr_ref
+ >
+{
+ typedef
+ stepper_offset<Index>
+ domain_t
+ ;
+ typedef
+ typename domain_t::axis_t
+ axis_t
+ ;
+ typedef
+ typename domain_t::index_t
+ index_t
+ ;
+ typedef
+ typename domain_t::lengths_t
+ lengths_t
+ ;
+ typedef
+ typename domain_t::offset_t
+ offset_t
+ ;
+ typedef
+ Value
+ value_t
+ ;
+ typedef
+ std::vector<Value>
+ data_t
+ ;
+ typedef
+ typename data_t::iterator
+ data_iter_t
+ ;
+ typedef
+ typename domain_t::const_iterator
+ domain_iter_t
+ ;
+ array
+ ( array_data< Value, Index>& a_val
+ , index_t a_index
+ )
+ : my_data_iter
+ ( a_val.data().begin()
+ + a_val.offset()
+ + a_val.stepper_ones().front()[stepr_stride]*a_index
+ )
+ , my_domain_iter(a_val.domain_t::begin()+1)
+ , my_rank(a_val.rank()-1)
+ {
+ }
+ array
+ ( array< Value, Index, arr_ref>& a_val
+ , index_t a_index
+ )
+ : my_data_iter
+ ( a_val.my_data_iter
+ + a_val.my_domain_iter->offset( a_index)
+ )
+ , my_domain_iter(a_val.my_domain_iter+1)
+ , my_rank(a_val.my_rank-1)
+ {
+ }
+
+ axis_t
+ rank()const
+ {
+ return my_rank;
+ }
+
+ index_t
+ size()const
+ {
+ return (*my_domain_iter)[stepr_length];
+ }
+ value_t&
+ operator()()
+ {
+ return *my_data_iter;
+ }
+
+ value_t const&
+ operator()()const
+ {
+ return *my_data_iter;
+ }
+
+ value_t&
+ operator()(index_t a_index)
+ {
+ return *(my_data_iter+a_index);
+ }
+
+ value_t const&
+ operator()(index_t a_index)const
+ {
+ return *(my_data_iter+a_index);
+ }
+
+ array< value_t, Index, arr_ref>
+ operator[](index_t a_index)
+ {
+ return array< value_t, Index, arr_ref>( *this, a_index);
+ }
+
+ array< value_t, Index, arr_cref>
+ operator[](index_t a_index)const
+ {
+ return array< value_t, Index, arr_cref>( *this, a_index);
+ }
+
+ private:
+ data_iter_t
+ my_data_iter
+ ;
+ domain_iter_t
+ my_domain_iter
+ ;
+ axis_t
+ my_rank
+ ;
+};
+
+ template
+ < typename Value
+ , typename Index
+ >
+struct array
+ < Value
+ , Index
+ , arr_own
+ >
+ : array_data< Value, Index>
+{
+ typedef
+ array_data< Value, Index>
+ super_t
+ ;
+ typedef
+ typename super_t::domain_t
+ domain_t
+ ;
+ typedef
+ typename domain_t::index_t
+ index_t
+ ;
+ typedef
+ typename domain_t::lengths_t
+ lengths_t
+ ;
+ typedef
+ typename domain_t::offset_t
+ offset_t
+ ;
+ typedef
+ typename super_t::value_t
+ value_t
+ ;
+ array
+ ( lengths_t const& a_lengths
+ , permut_predefined a_permut_pred=permut_default
+ )
+ : super_t
+ ( a_lengths
+ , a_permut_pred
+ )
+ {
+ }
+
+ value_t&
+ operator()()
+ {
+ return this->data().front();
+ }
+
+ value_t const&
+ operator()()const
+ {
+ return this->data().front();
+ }
+
+ value_t&
+ operator()(index_t a_index)
+ {
+ return this->data()[a_index];
+ }
+
+ value_t const&
+ operator()(index_t a_index)const
+ {
+ return this->data()[a_index];
+ }
+
+ array< value_t, Index, arr_ref>
+ operator[](index_t a_index)
+ {
+ return array< value_t, Index, arr_ref>( *this, a_index);
+ }
+
+ array< value_t, Index, arr_cref>
+ operator[](index_t a_index)const
+ {
+ return array< value_t, Index, arr_cref>( *this, a_index);
+ }
+
+};
+
+}//exit array_stepper namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_own_print.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_own_print.hpp 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
@@ -0,0 +1,43 @@
+#ifndef BOOST_ARRAY_STEPPER_ARRAY_OWN_PRINT_HPP_INCLUDED
+#define BOOST_ARRAY_STEPPER_ARRAY_OWN_PRINT_HPP_INCLUDED
+#include <boost/array_stepper/array_own.hpp>
+namespace boost
+{
+namespace array_stepper
+{
+
+ template
+ < typename Value
+ , typename Index
+ , array_type ArrType
+ >
+ std::ostream&
+operator<<
+ ( std::ostream& sout
+ , array< Value, Index, ArrType>const& a_arr
+ )
+ {
+ unsigned const r=a_arr.rank();
+ if(0<r)
+ {
+ unsigned const n=a_arr.size();
+ sout<<"{ ";
+ for( unsigned i=0; i<n; ++i)
+ {
+ if(0<i) sout<<", ";
+ sout<<indent_buf_in;
+ sout<<a_arr[i];
+ sout<<indent_buf_out;
+ }
+ sout<<"}\n";
+ }
+ else
+ {
+ sout<<a_arr();
+ }
+ return sout;
+ }
+
+}//exit array_stepper namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/mk_iota.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/mk_iota.hpp 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
@@ -0,0 +1,32 @@
+#ifndef BOOST_ARRAY_STEPPER_MK_IOTA_HPP_INCLUDED
+#define BOOST_ARRAY_STEPPER_MK_IOTA_HPP_INCLUDED
+#include <numeric>
+#include <vector>
+namespace boost
+{
+namespace array_stepper
+{
+ template
+ < typename Value
+ >
+ std::vector<Value>
+mk_iota
+ ( Value first
+ , Value last
+ )
+ {
+ int size=last-first;
+ std::vector<Value> result(abs(size));
+ if(size>0)
+ {
+ std::iota( result.begin(), result.end(), first);
+ }
+ else
+ {
+ std::iota( result.rbegin(), result.rend(), last);
+ }
+ return result;
+ }
+}//exit array_stepper namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/permutation0_last.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/permutation0_last.hpp 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
@@ -0,0 +1,82 @@
+#ifndef BOOST_ARRAY_STEPPER_PERMUTATION0_LAST_HPP_INCLUDED
+#define BOOST_ARRAY_STEPPER_PERMUTATION0_LAST_HPP_INCLUDED
+#include <boost/array_stepper/mk_iota.hpp>
+
+namespace boost
+{
+namespace array_stepper
+{
+
+enum permut_predefined
+{ permut_reverse //permutation in monotonically decreasing from last...0.
+, permut_forward //permutaion in montonically increasing from 0...last.
+};
+enum
+{ permut_predef_num=permut_forward+1
+};
+ static
+ permut_predefined const
+permut_default
+=permut_reverse
+;
+
+ template
+ < typename Value=unsigned
+ >
+ struct
+permutation0_last
+{
+ typedef
+ std::vector<Value>
+ permute_t
+ /**@brief
+ * Type of a permutaion of , 0...Last-1
+ * for some Value Last.
+ */
+ ;
+ typedef typename
+ permute_t::value_type
+ permute_val_t
+ ;
+ typedef
+ permute_t
+ (*permute_0to_t) //function returning a permutation of [0,a_last)
+ ( permute_val_t //a_last
+ )
+ ;
+ static
+ permute_t
+ identity_permutation
+ ( permute_val_t a_last
+ )
+ {
+ return mk_iota( permute_val_t(0), a_last);
+ }
+
+ static
+ permute_t
+ reverse_permutation
+ ( permute_val_t a_last
+ )
+ {
+ return mk_iota( a_last, permute_val_t(0));
+ }
+
+ static
+ permute_0to_t
+ permute_select
+ ( permut_predefined a_permut_pred=permut_default
+ )
+ {
+ static permute_0to_t mk[permut_predef_num]=
+ { reverse_permutation
+ , identity_permutation
+ };
+ return mk[a_permut_pred];
+ }
+
+};
+
+}//exit array_stepper namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/stepper_offset.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/stepper_offset.hpp 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
@@ -0,0 +1,305 @@
+#ifndef BOOST_ARRAY_STEPPER_STEPPER_OFFSET_HPP_INCLUDED
+#define BOOST_ARRAY_STEPPER_STEPPER_OFFSET_HPP_INCLUDED
+#include <boost/array.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/type_traits/make_signed.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
+#include <limits>
+#include <boost/array_stepper/permutation0_last.hpp>
+namespace boost
+{
+namespace array_stepper
+{
+
+enum stepr_index
+/**@brief
+ * Indices into stepper_one struct (see below).
+ */
+{ stepr_length
+ //axis length
+, stepr_stride
+ //difference between successive
+ //elements on this axis.
+, stepr_axis
+ //axis of array described
+ //by the stepper_one.
+};
+enum
+{ stepr_size=stepr_axis+1
+};
+ template
+ < typename Value=int
+ //Value must include negative values(i.e. be signed)
+ //to indicate reverse direction for axis.
+ >
+struct stepper_one
+: array< Value, stepr_size>
+{
+ typedef
+ array< Value, stepr_size>
+ super_t
+ ;
+ private:
+ BOOST_STATIC_ASSERT(std::numeric_limits<Value>::is_signed);
+ public:
+ typedef
+ Value
+ value_t
+ ;
+ typedef
+ value_t
+ offset_diff_t
+ ;
+ typedef
+ typename make_unsigned<value_t>::type
+ space_t
+ ;
+ typedef
+ space_t
+ index_t
+ ;
+ space_t
+ space()const
+ /**@brief
+ * Space occupied by all elements on axis
+ * described by this stepper_one.
+ */
+ {
+ value_t const length=(*this)[stepr_length];
+ space_t const stride=abs((*this)[stepr_stride]);
+ return length*stride;
+ }
+ offset_diff_t
+ offset(index_t a_index)const
+ {
+ return (*this)[stepr_stride]*a_index;
+ }
+ space_t
+ offset()const
+ /**@brief
+ * Offset caused by negative strides.
+ */
+ {
+ super_t const& me=*this;
+ if(me[stepr_stride]<0)
+ {
+ return abs(this->offset(me[stepr_length]-1));
+ }
+ else
+ {
+ return 0;
+ }
+ }
+};
+
+ template
+ < stepr_index Index
+ , typename Value
+ >
+ Value&
+get( stepper_one<Value>& x)
+{
+ return x[Index];
+}
+
+ template
+ < stepr_index Index
+ , typename Value
+ >
+ Value
+get( stepper_one<Value> const& x)
+{
+ return x[Index];
+}
+ template
+ < typename Value
+ >
+ int
+isign
+ ( Value a_value
+ )
+ {
+ return
+ (a_value<0)
+ ? -1
+ : (a_value>0)
+ ? +1
+ : 0
+ ;
+ }
+ template
+ < typename Value=int
+ >
+struct stepper_offset
+{
+ typedef
+ stepper_one<Value>
+ stepper_one_t
+ ;
+ typedef typename
+ stepper_one_t::value_t
+ value_t
+ ;
+ typedef typename
+ stepper_one_t::index_t
+ index_t
+ ;
+ typedef
+ std::vector<stepper_one_t>
+ stepper_ones_t
+ ;
+ typedef
+ typename stepper_ones_t::const_iterator
+ const_iterator
+ ;
+ typedef
+ std::vector<Value>
+ lengths_t
+ /**@brief
+ * length of axes in an array.
+ * Negative Value means axis is reversed.
+ */
+ ;
+ typedef
+ unsigned
+ offset_t
+ /**@brief
+ * offset into array.
+ */
+ ;
+ typedef
+ unsigned
+ axis_t
+ /**@brief
+ * Axis index.
+ * Value in [0,this->rank() )
+ */
+ ;
+ typedef
+ typename permutation0_last<axis_t>::permute_t
+ axes_permutation_t
+ /**@brief
+ * size()==this->rank().
+ * Value is permutation of values of axis_t.
+ */
+ ;
+ axis_t
+ rank()const
+ {
+ return my_stepper_ones.size();
+ }
+ stepper_ones_t const&
+ stepper_ones()const
+ {
+ return my_stepper_ones;
+ }
+ index_t
+ size()const
+ {
+ return my_stepper_ones[0][stepr_length];
+ }
+ offset_t
+ offset()const
+ {
+ return my_offset;
+ }
+ const_iterator
+ begin()const
+ {
+ return my_stepper_ones.begin();
+ }
+ void
+ permute( axes_permutation_t a_permut)
+ {
+ stepper_ones_t so_v(stepper_ones());
+ unsigned r=rank();
+ for( unsigned i=0; i<r; ++i)
+ {
+ unsigned p=a_permut[i];
+ my_stepper_ones[i]=so_v[p];
+ //my_stepper_ones[i][stepr_axis]=a_permut[so_v[i][stepr_axis]];
+ }
+ }
+ protected:
+ offset_t
+ init_strides
+ ( lengths_t const& a_lengths
+ , axes_permutation_t a_permut//Must be a permutation of 0..a_length.size().
+ )
+ {
+ unsigned size=a_lengths.size();
+ if(0<size)
+ {
+ unsigned i=0;
+ unsigned now_index =a_permut[i];
+ value_t now_length=a_lengths[now_index];
+ int now_sign =isign(now_length);
+ my_stepper_ones[now_index][stepr_length]=abs(now_length);
+ my_stepper_ones[now_index][stepr_stride]=now_sign;
+ my_stepper_ones[now_index][stepr_axis ]=size-1-i;
+ my_offset+=my_stepper_ones[now_index].offset();
+ for(++i; i<size; ++i)
+ {
+ value_t pre_space=my_stepper_ones[now_index].space();
+ now_index =a_permut[i];
+ now_length=a_lengths[now_index];
+ now_sign =isign(now_length);
+ my_stepper_ones[now_index][stepr_length]=abs(now_length);
+ my_stepper_ones[now_index][stepr_stride]=now_sign*pre_space;
+ my_stepper_ones[now_index][stepr_axis ]=size-1-i;
+ my_offset+=my_stepper_ones[now_index].offset();
+ }
+ return my_stepper_ones[now_index].space();
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ stepper_offset
+ ( std::size_t a_rank
+ )
+ : my_stepper_ones(a_rank)//subclass should call init_strides
+ , my_offset(0)
+ {
+ }
+ stepper_ones_t&
+ stepper_ones()
+ {
+ return my_stepper_ones;
+ }
+ public:
+ offset_t
+ space()const
+ {
+ unsigned i=0;
+ unsigned r=rank();
+ for(; i<r; ++i)
+ {
+ if(my_stepper_ones[i][stepr_axis]==0) break;
+ }
+ return my_stepper_ones[i].space();
+ }
+
+ stepper_offset
+ ( lengths_t const& a_lengths
+ , axes_permutation_t a_permut//Must be a permutation of 0..a_length.size().
+ )
+ : my_stepper_ones(a_lengths.size())
+ , my_offset(0)
+ {
+ init_strides( a_lengths, a_permut);
+ }
+ private:
+ stepper_ones_t
+ my_stepper_ones
+ ;
+ offset_t
+ my_offset
+ ;
+};
+
+}//exit array_stepper namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/sandbox/stepper/libs/array_stepper/examples/array_own.cpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/libs/array_stepper/examples/array_own.cpp 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
@@ -0,0 +1,74 @@
+//Purpose:
+// Demo array whose dimensions and sizes are defined at runtime.
+//
+#include <boost/iostreams/utility/indent_scoped_ostreambuf.hpp>
+#include <boost/array_stepper/array_own_print.hpp>
+
+using namespace boost::array_stepper;
+typedef array<int> array_t;
+
+
+void test(array_t::lengths_t const& a_lengths)
+{
+ unsigned const rank=a_lengths.size();
+ std::cout<<"a_lengths["<<rank<<"]=\n";
+ for(unsigned i=0; i<rank; ++i)
+ {
+ std::cout<<" length["<<i<<"]="<<a_lengths[i]<<"\n";
+ }
+ for(unsigned dir_op=0; dir_op<permut_predef_num; ++dir_op)
+ {
+ std::cout<<"*************************\n";
+ std::cout<<"dir_op="<<dir_op<<"\n";
+ array_t ai( a_lengths, permut_predefined(dir_op));
+ unsigned const size=ai.data().size();
+ std::cout<<"my_data.size()="<<size<<"\n";
+ std::cout<<"ai.offset="<<ai.offset()<<"\n";
+ {
+ unsigned value=1000;
+ std::iota( ai.data().begin(), ai.data().end(), value);
+ }
+ std::cout<<"ai=\n";
+ std::cout<<ai<<".\n";
+ }
+}
+
+int main(void)
+{
+ boost::iostreams::indent_scoped_ostreambuf<char> indent_outbuf(std::cout,2);
+ {
+ std::cout<<"***reorderings:\n";
+ std::cout<<indent_buf_in;
+ array_t::lengths_t const lengths0({ 2, 3, 4});
+ test(lengths0);
+ for(unsigned i=0; i< lengths0.size(); ++i)
+ {
+ array_t::lengths_t a_lengths(lengths0);
+ a_lengths[i]=-a_lengths[i];
+ test(a_lengths);
+ }
+ std::cout<<indent_buf_out;
+ }
+ {
+ std::cout<<"***reshap:\n";
+ std::cout<<indent_buf_in;
+ array_t::lengths_t const lengths0({ 2, 3, 4});
+ array_t ai( lengths0);
+ {
+ unsigned value=1000;
+ std::iota( ai.data().begin(), ai.data().end(), value);
+ }
+ std::cout<<"ai before reshape=\n";
+ std::cout<<indent_buf_in;
+ std::cout<<ai;
+ std::cout<<indent_buf_out;
+ array_t::lengths_t const lengths1({6,4});
+ ai.reshape(lengths1);
+ std::cout<<"ai after reshape=\n";
+ std::cout<<indent_buf_in;
+ std::cout<<ai;
+ std::cout<<indent_buf_out;
+ std::cout<<indent_buf_out;
+ }
+ return 0;
+}

Added: sandbox/variadic_templates/sandbox/stepper/libs/array_stepper/examples/stepper_offset.cpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/libs/array_stepper/examples/stepper_offset.cpp 2011-06-22 16:14:41 EDT (Wed, 22 Jun 2011)
@@ -0,0 +1,60 @@
+#include <iostream>
+#include <boost/iostreams/utility/indent_scoped_ostreambuf.hpp>
+#include <boost/array_stepper/stepper_offset_print.hpp>
+#include <boost/array_stepper/mk_iota.hpp>
+#include <boost/array_stepper/vector_print.hpp>
+#include <algorithm>
+
+using namespace boost::array_stepper;
+
+int main()
+{
+ boost::iostreams::indent_scoped_ostreambuf<char> indent_outbuf(std::cout,2);
+ typedef stepper_offset<> sto_t;
+ typedef sto_t::lengths_t lengths_t;
+ lengths_t lengths_v({-2,3,4});
+ unsigned rank=lengths_v.size();
+ std::cout<<"lengths_v="<<lengths_v;
+ std::cout<<"***permut CTOR\n";
+ std::cout<<indent_buf_in;
+ sto_t::axes_permutation_t permut_v=mk_iota<sto_t::axis_t>( 0, rank);
+ unsigned count=0;
+ do
+ {
+ std::cout<<":count="<<count;
+ std::cout<<":permut_v="<<permut_v;
+ sto_t sto_v( lengths_v, permut_v);
+ std::cout<<"stepper_ones=\n"<<sto_v.stepper_ones();
+ std::cout<<"offset="<<sto_v.offset()<<"\n";
+ }while
+ ( ++count< 10
+ && std::next_permutation
+ ( permut_v.begin()
+ , permut_v.end()
+ )
+ );
+ std::cout<<indent_buf_out;
+ std::cout<<":permut_v="<<permut_v;
+ std::cout<<"***permut VALU\n";
+ std::cout<<indent_buf_in;
+ sto_t::axes_permutation_t const permut_c=permut_v;
+ count=0;
+ do
+ {
+ std::cout<<":count="<<count;
+ std::cout<<":permut_v="<<permut_v;
+ sto_t sto_v( lengths_v, permut_c);
+ sto_v.permute(permut_v);
+ std::cout<<"stepper_ones=\n"<<sto_v.stepper_ones();
+ std::cout<<"offset="<<sto_v.offset()<<"\n";
+ }while
+ ( ++count< 10
+ && std::next_permutation
+ ( permut_v.begin()
+ , permut_v.end()
+ )
+ );
+ std::cout<<indent_buf_out;
+ std::cout<<":permut_v="<<permut_v;
+ return 0;
+}


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