4 #ifndef CPPQEDCORE_UTILS_BLITZARRAYSLICEITERATOR_H_INCLUDED
5 #define CPPQEDCORE_UTILS_BLITZARRAYSLICEITERATOR_H_INCLUDED
7 #include "BlitzArraySliceIteratorFwd.h"
15 #include <boost/mpl/size.hpp>
16 #include <boost/mpl/sort.hpp>
17 #include <boost/mpl/unique.hpp>
18 #include <boost/mpl/max_element.hpp>
20 #include <boost/range.hpp>
36 template <
typename V>
struct Size : boost::mpl::size<V> {};
45 template <
typename V,
bool IS_CONST>
using ConditionalConstResCArray=ConditionalConstCArray<Size<V>::value,IS_CONST>;
47 template <
typename I,
typename V,
bool IS_CONST>
using ForwardIteratorHelper=boost::forward_iterator_helper<I,ConditionalConstResCArray<V,IS_CONST> >;
54 using cpputils::mii::Begin;
using cpputils::mii::End;
68 static_assert( RANK >=
Size<V>::value ,
"Indexer with nonpositive RANK." );
70 typedef typename boost::mpl::sort<V>::type SortedV;
71 static_assert( boost::mpl::equal<
typename boost::mpl::unique<SortedV,boost::is_same<boost::mpl::_1,boost::mpl::_2> >::type,SortedV>::value ,
"basi::Iterator inconsistent vector" );
72 static_assert( boost::mpl::deref<
typename boost::mpl::max_element<V>::type>::type::value < RANK ,
"basi::Iterator vector out of range" );
77 template<
int RANK,
int I1,
int I2>
struct ConsistencyChecker<RANK,boost::mpl::range_c<int,I1,I2> > { static_assert( I1>=0 && I2<RANK ,
"basi::Iterator vector out of range" ); };
81 template<
int RANK,
int N>
struct ConsistencyChecker<RANK,
tmptools::Ordinals<N> > :
private ConsistencyChecker<RANK,tmptools:: Range <N,0> > {};
96 template<
int RANK,
typename V>
97 const ttd::VecIdxTiny<RANK,V>
133 template<
int RANK,
typename V>
167 #pragma GCC diagnostic push
168 #pragma GCC diagnostic ignored "-Wunused-parameter"
171 template<
int RANK,
typename V>
202 ttd::ResCArray<V>& resArray,
203 const ttd::VecIdxTiny<RANK,V>& idx
209 #pragma GCC diagnostic pop
225 template<
typename,
bool>
228 template<
typename,
bool>
231 template<
int,
typename,
bool>
236 #define BASE_class boost::mpl::if_c<RANK==1,\
237 details::BaseTrivial<V,IS_CONST>,\
238 typename boost::mpl::if_c<RANK==Size<V>::value,\
239 details::BaseSpecial<V,IS_CONST>,\
240 details::Base<RANK,V,IS_CONST>\
296 template<
int RANK,
typename V,
bool IS_CONST>
298 :
public ttd::ForwardIteratorHelper<Iterator<RANK,V,IS_CONST>,V,IS_CONST>,
303 typedef typename BASE_class Base;
307 typedef typename Base::CcCA
CcCA;
309 typedef boost::iterator_range<Iterator>
Range;
315 template<
bool IS_END>
316 Iterator(CcCA& array, boost::mpl::bool_<IS_END> isEnd) : Base(array,isEnd) {}
322 #define RETURN_type1(IS_CONST) Iterator<Rank<A>::value,V_S,IS_CONST>
323 #define ADDITIONAL_PARAMETER
324 #define ADDITIONAL_ARGUMENT
326 #include "details_BlitzArraySliceIteratorReentrant.h"
337 template<
int RANK,
typename V,
bool IS_CONST>
338 class Base :
public Indexer<RANK,V>
342 typedef ttd::ConditionalConstCArray<RANK,IS_CONST> CcCA ;
343 typedef ttd::ResCArray<V> CARes;
344 typedef ttd::ConditionalConstResCArray<V,IS_CONST> CcCARes;
346 typedef ttd::VecIdxTiny<RANK,V> VecIdxTiny;
348 static const int RANKIDX=RANK-Size<V>::value;
355 void increment() {++impl_;}
360 friend bool operator==(
const Base& i1,
const Base& i2) {
return i1.impl_==i2.impl_ ;}
363 const Impl& operator()()
const {
return impl_;}
367 static Impl ctorHelper(CcCA&);
372 mutable CARes arrayRes_;
389 template<
typename V,
bool IS_CONST>
393 static const int RANK=Size<V>::value;
396 typedef ttd::ConditionalConstCArray<RANK,IS_CONST> CcCA;
398 BaseTrivial(CcCA&, Begin);
399 BaseTrivial(CcCA&, End );
401 void increment() {
if (!isEnd_) isEnd_=
true;
else throw OutOfRange();}
403 CcCA& operator*()
const {
if (isEnd_)
throw OutOfRange();
return array_;}
405 friend bool operator==(
const BaseTrivial& i1,
const BaseTrivial& i2) {
return i1.isEnd_==i2.isEnd_;}
422 template<
typename V,
bool IS_CONST>
423 class BaseSpecial :
public BaseTrivial<V,IS_CONST>
426 typedef typename BaseTrivial<V,IS_CONST>::CcCA CcCA;
428 BaseSpecial(CcCA&, Begin);
429 BaseSpecial(CcCA&, End );
453 template<
int RANK,
typename V>
457 typedef std::list<ptrdiff_t>
Impl;
469 const Impl firstOffsets_;
471 const blitz::TinyVector<int ,basi::Size<V>::value> shape_;
472 const blitz::TinyVector<ptrdiff_t,basi::Size<V>::value> stride_;
474 const blitz::GeneralArrayStorage<basi::Size<V>::value> storage_;
481 namespace basi_fast {
492 template<
int RANK,
typename V,
bool IS_CONST>
494 :
public basi::ttd::ForwardIteratorHelper<Iterator<RANK,V,IS_CONST>,V,IS_CONST>
497 typedef basi::ttd::ConditionalConstCArray<RANK,IS_CONST> CcCA ;
498 typedef basi::ttd::ResCArray<V> CARes;
499 typedef basi::ttd::ConditionalConstResCArray<V,IS_CONST> CcCARes;
501 typedef boost::iterator_range<Iterator> Range;
503 Iterator& operator++() {++iter_;
return *
this;}
505 CcCARes& operator*()
const
507 arrayRes_.reference(CARes(arrayData_+*iter_,slicesData_.shape_,slicesData_.stride_,blitz::neverDeleteData,slicesData_.storage_));
511 friend bool operator==(
const Iterator& i1,
const Iterator& i2) {
return i1.iter_==i2.iter_;}
513 template<
bool IS_END>
519 mutable CARes arrayRes_;
521 dcomp*
const arrayData_;
530 #define NS_NAME basi_fast
531 #define RETURN_type1(IS_CONST) Iterator<Rank<A>::value,V_S,IS_CONST>
532 #define ADDITIONAL_PARAMETER , sd
533 #define ADDITIONAL_ARGUMENT , const SlicesData<Rank<A>::value,V_S>& sd
535 #include "details_BlitzArraySliceIteratorReentrant.h"
545 template<
typename V,
typename A>
546 const Iterator<Rank<A>::value,V,
false>
550 template<
typename V,
typename A>
551 const Iterator<Rank<A>::value,V,
false>
556 template<
typename V,
typename A>
557 const Iterator<Rank<A>::value,V,
true>
558 begin(
const A& array );
561 template<
typename V,
typename A>
562 const Iterator<Rank<A>::value,V,
true>
563 end (
const A& array );
570 template<
typename V,
typename A>
571 const boost::iterator_range<Iterator<Rank<A>::value,V,
false> >
572 fullRange( A& array );
575 template<
typename V,
typename A>
576 const boost::iterator_range<Iterator<Rank<A>::value,V,
true> >
577 fullRange(
const A& array );
581 namespace basi_fast {
584 template<
typename V,
typename A>
585 const Iterator<Rank<A>::value,V,
false>
586 begin( A& array ,
const SlicesData<Rank<A>::value,V>& sd);
589 template<
typename V,
typename A>
590 const Iterator<Rank<A>::value,V,
true>
591 begin(
const A& array ,
const SlicesData<Rank<A>::value,V>& sd);
594 template<
typename V,
typename A>
595 const Iterator<Rank<A>::value,V,
false>
596 end ( A& array ,
const SlicesData<Rank<A>::value,V>& sd);
599 template<
typename V,
typename A>
600 const Iterator<Rank<A>::value,V,
true>
601 end (
const A& array ,
const SlicesData<Rank<A>::value,V>& sd);
604 template<
typename V,
typename A>
605 const boost::iterator_range<Iterator<Rank<A>::value,V,
true> >
606 fullRange(
const A& array ,
const SlicesData<Rank<A>::value,V>& sd);
609 template<
typename V,
typename A>
610 const boost::iterator_range<Iterator<Rank<A>::value,V,
false> >
611 fullRange( A& array ,
const SlicesData<Rank<A>::value,V>& sd);
723 #endif // CPPQEDCORE_UTILS_BLITZARRAYSLICEITERATOR_H_INCLUDED
The class that is (meant to be, at least) the base of all exceptions in the framework.
blitz::TinyVector< ptrdiff_t, RANK > IdxTiny
A tiny vector used for indexing of objects of arbitrary arity.
A forwarding metafunction to boost::mpl::size.
blitz::Array< dcomp,RANK > CArray
A complex array of arbitrary arity.
boost::iterator_range< Iterator > Range
Boost.Range-compliant range.
template metafunction for the rank (arity) of the multi-array A
Performs the slicing on an array already transposed by Transposer.
static CArray< RANK > & transpose(CArray< RANK > &)
Static worker.
Exception thrown if the partial specialization of Transposer or Indexer for the given RANK does not e...
Iterator & operator++()
For the ForwardIterator concept.
const ttd::VecIdxTiny< RANK, V > filterOut(const IdxTiny< RANK > &idx)
Filters out the indices corresponding to a subsystem.
Iterator(CcCA &array, boost::mpl::bool_< IS_END > isEnd)
Can be initialized either to the beginning or the end of the sequence of dummy-index combinations...
Class performing the “possible permutation” of the retained indices (cf. Synopsis).
An iterator over all possible combinations of indices (a number of integers) between certain bounds...
std::list< ptrdiff_t > Impl
Data structure for the sequence of slices.
“Fast” version of basi::Iterator relying on a pre-calculated set of slices stored by SlicesData ...
Checking the consistency of template arguments for use in slicing.
Defines class MultiIndexIterator and a few helpers.
Base::CcCA CcCA
ttd::ConditionalConstCArray
std::complex< double > dcomp
Double-precision complex number.
static ttd::ResCArray< V > & index(CArray< RANK > &array, ttd::ResCArray< V > &resArray, const ttd::VecIdxTiny< RANK, V > &idx)
Static worker.
Contains data for pre-calculated slices for basi_fast::Iterator.
SlicesData(const CArray< RANK > &array)
Constructor from a reference array.
Comprises our own extensions to Blitz++.
Implementations of the traits functions declared in ArrayTraits.h for blitz::Array ...
Defines tentative base classes for the exception classes of the framework.