11#ifndef NDARRAY_DETAIL_ViewBuilder_h_INCLUDED
12#define NDARRAY_DETAIL_ViewBuilder_h_INCLUDED
19#include <boost/fusion/include/push_back.hpp>
20#include <boost/fusion/include/pop_back.hpp>
21#include <boost/fusion/include/front.hpp>
22#include <boost/fusion/include/back.hpp>
23#include <boost/fusion/include/vector.hpp>
24#include <boost/fusion/include/reverse_view.hpp>
25#include <boost/fusion/include/mpl.hpp>
26#include <boost/fusion/include/at.hpp>
27#include <boost/fusion/include/at_c.hpp>
28#include <boost/fusion/tuple.hpp>
29#include <boost/mpl/count.hpp>
30#include <boost/mpl/size.hpp>
31#include <boost/mpl/fold.hpp>
40template <
typename T,
int M,
int N>
50 ) : _data(data), _input(input), _output(output) {}
52 template <
int M1,
int N1>
54 _data(other._data), _input(other._input), _output(other._output) {}
57template <
int N,
int C,
int I>
59 typedef boost::mpl::int_<N> ND;
60 typedef boost::mpl::int_<C> RMC;
61 typedef boost::mpl::int_<I> IDX;
62 typedef boost::mpl::int_<N-I> N_I;
74 ((D::RMC::value < D::N_I::value) ? D::RMC::value : (D::N_I::value - 1)),
80 template <
typename T,
int M,
int N>
struct TransformCoreResult {
85 template <
typename T,
int M,
int N>
89 NDARRAY_ASSERT(index.step > 0);
90 NDARRAY_ASSERT(index.start <= index.stop);
91 NDARRAY_ASSERT(index.start >= 0);
92 NDARRAY_ASSERT(index.stop <= t._input->
getSize());
93 t._data += index.start * t._input->
getStride();
94 t._output->setSize(index.computeSize());
95 t._output->setStride(t._input->
getStride() * index.step);
104 template <
typename D>
108 ((D::RMC::value < D::N_I::value) ? D::RMC::value : D::N_I::value),
114 template <
typename T,
int M,
int N>
struct TransformCoreResult {
119 template <
typename T,
int M,
int N>
123 NDARRAY_ASSERT(index.start <= index.stop);
124 NDARRAY_ASSERT(index.start >= 0);
125 NDARRAY_ASSERT(index.stop <= t._input->
getSize());
126 t._data += index.start * t._input->
getStride();
127 t._output->setSize(index.stop - index.start);
128 t._output->setStride(t._input->
getStride());
136 template <
typename D>
146 template <
typename T,
int M,
int N>
struct TransformCoreResult {
151 template <
typename T,
int M,
int N>
155 t._output->setSize(t._input->
getSize());
156 t._output->setStride(t._input->
getStride());
164 template <
typename D>
168 ((D::RMC::value < (D::N_I::value - 1)) ? D::RMC::value : (D::N_I::value - 1)),
174 template <
typename T,
int M,
int N>
struct TransformCoreResult {
179 template <
typename T,
int M,
int N>
183 NDARRAY_ASSERT(index.n >= 0);
184 NDARRAY_ASSERT(index.n < t._input->
getSize());
185 t._data += index.n * t._input->
getStride();
190template <
typename T,
int M,
int N,
typename Index>
191typename IndexTraits<Index>::template TransformCoreResult<T,M,N>::Type
192transformCore(Index
const & index, CoreTransformer<T,M,N> & t) {
193 return IndexTraits<Index>::transformCore(index, t);
198 template <
typename State,
typename Index>
205template <
int N,
int C,
typename Seq_,
bool isColumnMajor = (C < 0)>
208template <
int N,
int C,
typename Seq_>
211 typedef typename boost::mpl::fold< Seq_, Dimensions<N,C,0>,
AppendIndex >::type Dims;
213 typedef typename Dims::ND ND;
214 typedef typename Dims::RMC RMC;
218template <
int N,
int C,
typename Seq_>
221 typedef typename boost::mpl::fold<
222 boost::fusion::reverse_view< typename boost::fusion::result_of::as_vector<Seq_>::type >,
226 typedef typename Dims::ND ND;
227 typedef typename boost::mpl::negate<typename Dims::RMC>::type RMC;
235template <
int N,
typename Seq_,
bool IsNormalized=(boost::mpl::
template size<Seq_>::type::value==N)>
238 typedef typename boost::fusion::result_of::push_back<Seq_ const,index::Full>::type Next;
240 typedef typename ViewNormalizer<N,Next>::Output Output;
242 static Output apply(Seq_
const & input) {
249template <
int N,
typename Seq_>
251 typedef typename boost::fusion::result_of::as_vector<Seq_>::type Output;
252 static Output apply(Seq_
const & input) {
return boost::fusion::as_vector(input); }
259template <
typename Array_,
typename InSeq>
262 typedef typename Traits::Element Element;
263 typedef typename Traits::ND InputND;
264 typedef typename Traits::RMC InputRMC;
265 typedef typename Traits::Core InputCore;
266 typedef boost::mpl::bool_<(InputRMC::value < 0)> IsColumnMajor;
269 typedef typename ViewNormalizer<InputND::value,InSeq>::Output NormSeq;
272 typedef typename OutputTraits::ND OutputND;
273 typedef typename OutputTraits::RMC OutputRMC;
278 static OutputArray apply(Array_
const & array, InSeq
const & seq) {
282 OutputCore::create(array.getManager())
284 NormSeq normSeq = Normalizer::apply(seq);
285 std::pair<Element*,typename OutputCore::Ptr>
final = process(normSeq, initial);
289 template <
int M,
int N>
290 static std::pair<Element*,typename OutputCore::Ptr>
292 return process(seq, transformCore(boost::fusion::at_c<(InputND::value-M)>(seq), t));
295 static std::pair<Element*,typename OutputCore::Ptr>
297 return std::make_pair(t._data, boost::static_pointer_cast<OutputCore>(t._output));
306template <
typename Array_,
typename Seq_>
308buildView(Array_
const & array, Seq_
const & seq) {
A proxy class for Array with deep assignment operators.
Definition ArrayRef.h:34
Definition ArrayAccess.h:26
Size getSize() const
Return the size of the Nth dimension.
Definition Core.h:88
boost::intrusive_ptr< Core > Ptr
intrusive_ptr to Core
Definition Core.h:51
boost::intrusive_ptr< Core const > ConstPtr
const intrusive_ptr to Core
Definition Core.h:52
Offset getStride() const
Return the stride of the Nth dimension.
Definition Core.h:91
Traits for expressions.
Definition ExpressionTraits.h:30
Definition ViewBuilder.h:199
Definition ViewBuilder.h:196
Definition ViewBuilder.h:58
Definition ViewBuilder.h:260
Definition ViewBuilder.h:236
Definition ViewBuilder.h:206
Empty structure marking a view of an entire dimension.
Definition views.h:54
Simple structure defining a contiguous range of indices.
Definition views.h:44
Structure marking a single element of a dimension.
Definition views.h:59
Simple structure defining a noncontiguous range of indices.
Definition views.h:31
Public interface for arbitrary views into arrays.