Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75384 - sandbox/variadic_templates/sandbox/stepper/boost/array_stepper
From: cppljevans_at_[hidden]
Date: 2011-11-07 10:02:30


Author: cppljevans
Date: 2011-11-07 10:02:29 EST (Mon, 07 Nov 2011)
New Revision: 75384
URL: http://svn.boost.org/trac/boost/changeset/75384

Log:
Added files for new #includes of length_strides_offset.hpp

Added:
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/indices_at_offset.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/offset_at_indices.hpp (contents, props changed)

Added: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/indices_at_offset.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/indices_at_offset.hpp 2011-11-07 10:02:29 EST (Mon, 07 Nov 2011)
@@ -0,0 +1,134 @@
+#ifndef BOOST_ARRAY_STEPPER_INDICES_AT_OFFSET_HPP_INCLUDED
+#define BOOST_ARRAY_STEPPER_INDICES_AT_OFFSET_HPP_INCLUDED
+#include <numeric>
+#include <boost/iterator/transform_iterator.hpp>
+
+namespace boost
+{
+namespace array_stepper
+{
+ template
+ < typename Index
+ , typename LengthStride
+ , typename GetLengthStride
+ , typename Offset
+ >
+ struct
+ index_at_offset
+ /**@brief
+ * Functor used by indexs_at_offset.
+ */
+ {
+ Offset
+ my_offset
+ /**@brief
+ * offset in multitimensional array.
+ * from beginning of array.
+ */
+ ;
+ GetLengthStride
+ my_get_length_stride
+ /**@brief
+ * offset in multitimensional array.
+ * from beginning of array.
+ */
+ ;
+ index_at_offset( Offset a_offset, GetLengthStride a_get_length_stride)
+ : my_offset(a_offset)
+ , my_get_length_stride(a_get_length_stride)
+ {}
+ typedef
+ Index
+ result_type
+ /**@brief
+ * required by make_transform_iterator
+ * used in indexs_at_offset.
+ */
+ ;
+ result_type
+ operator()( LengthStride const& ls)const
+ /**@brief
+ * this is equation (5.7) in @reference
+ * for an axis described by ls.
+ */
+ {
+ result_type div_v=my_offset/my_get_length_stride.stride(ls);
+ result_type index_v=div_v%my_get_length_stride.length(ls);
+ return index_v;
+ }
+ };
+
+ template
+ < typename Indices
+ , typename LengthStrideIter
+ , typename GetLengthStride
+ , typename Offset
+ >
+ Indices
+ indices_at_offset
+ ( LengthStrideIter first_ls
+ , LengthStrideIter last_ls
+ , GetLengthStride get_length_stride
+ //provides length and stride funcitons to access lengths
+ //and strides of elements in LengthStrideIter.
+ , Offset offset0
+ )
+ /**@brief
+ * Returns the indices corresponding to offset0
+ * in array with length and strides given by
+ * first_ls...last_ls.
+ *
+ * This corresponds to equation (5.7) in @reference
+ * for each axis.
+ *
+ **@reference:
+ * _An APL Compiler_
+ * Timothy Budd
+ * Springer-Verlag, 1988
+ */
+ {
+ std::size_t const
+ size=last_ls-first_ls
+ ;
+ Indices
+ indices(size)
+ ;
+ typedef
+ index_at_offset
+ < typename Indices::value_type
+ , typename LengthStrideIter::value_type
+ , GetLengthStride
+ , Offset
+ >
+ iao_t
+ ;
+ typedef
+ transform_iterator
+ < iao_t
+ , LengthStrideIter
+ >
+ xiter_t
+ ;
+ iao_t
+ iao_v(offset0,get_length_stride)
+ ;
+ xiter_t
+ beg_index( first_ls, iao_v)
+ ;
+ xiter_t
+ end_index( last_ls, iao_v)
+ ;
+ typename Indices::iterator
+ beg_is=indices.begin()
+ ;
+ std::copy
+ ( beg_index
+ , end_index
+ , beg_is
+ );
+ return indices;
+ }
+
+}//exit array_stepper namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/offset_at_indices.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/offset_at_indices.hpp 2011-11-07 10:02:29 EST (Mon, 07 Nov 2011)
@@ -0,0 +1,55 @@
+#ifndef BOOST_ARRAY_STEPPER_OFFSET_AT_INDICES_HPP_INCLUDED
+#define BOOST_ARRAY_STEPPER_OFFSET_AT_INDICES_HPP_INCLUDED
+#include <numeric>
+#include <boost/iterator/transform_iterator.hpp>
+
+namespace boost
+{
+namespace array_stepper
+{
+ template
+ < typename StrideIter
+ , typename GetStride
+ , typename IndexIter
+ , typename Offset
+ >
+ Offset
+ offset_at_indices
+ ( IndexIter first_index
+ , IndexIter last_index
+ , StrideIter first_stride
+ , GetStride get_stride //functor returning strides in StrideIter
+ , Offset offset0=Offset(0)
+ )
+ /**@brief
+ * Returns offset corresponding to the indices
+ * in array with strides given by
+ * first_stride...(first_stride+(last_index-first_index).
+ *
+ * This corresponds to equation (5.2) of the @reference.
+ *
+ **@reference:
+ * _An APL Compiler_
+ * Timothy Budd
+ * Springer-Verlag, 1988
+ */
+ {
+ transform_iterator
+ < GetStride
+ , StrideIter
+ >
+ beg_s
+ ( first_stride
+ , get_stride
+ );
+ return std::inner_product
+ ( first_index
+ , last_index
+ , beg_s
+ , offset0
+ );
+ }
+
+}//exit array_stepper namespace
+}//exit boost namespace
+#endif


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