index prototype in each ma instance + simplify op-index initialization procedure

This commit is contained in:
Christian Zimmermann 2018-03-02 13:35:50 +01:00
parent 516f2ed3a4
commit 219a267995
4 changed files with 51 additions and 71 deletions

View file

@ -60,7 +60,7 @@ namespace MultiArrayTools
protected:
bool mInit = false;
std::shared_ptr<CRange> mRange;
std::shared_ptr<IndexType> mProtoI;
};
template <typename T, class... SRanges>
@ -116,6 +116,7 @@ namespace MultiArrayTools
{
ContainerRangeFactory<T,SRanges...> crf(ranges...);
mRange = std::dynamic_pointer_cast<ContainerRange<T,SRanges...> >( crf.create() );
mProtoI = std::make_shared<IndexType>( mRange );
}
template <typename T, class... SRanges>
@ -123,6 +124,7 @@ namespace MultiArrayTools
{
ContainerRangeFactory<T,SRanges...> crf(space);
mRange = std::dynamic_pointer_cast<ContainerRange<T,SRanges...> >( crf.create() );
mProtoI = std::make_shared<IndexType>( mRange );
}
template <typename T, class... SRanges>
@ -134,14 +136,17 @@ namespace MultiArrayTools
template <typename T, class... SRanges>
typename MultiArrayBase<T,SRanges...>::IndexType MultiArrayBase<T,SRanges...>::begin() const
{
IndexType i = mRange->begin();
IndexType i(*mProtoI);
i = 0;
return i.setData(data());
}
template <typename T, class... SRanges>
typename MultiArrayBase<T,SRanges...>::IndexType MultiArrayBase<T,SRanges...>::end() const
{
IndexType i = mRange->end();
IndexType i(*mProtoI);
i = i.max();
//i = mRange->size();
return i.setData(data());
}
@ -149,7 +154,8 @@ namespace MultiArrayTools
typename MultiArrayBase<T,SRanges...>::IndexType
MultiArrayBase<T,SRanges...>::beginIndex() const
{
IndexType i = mRange->begin();
IndexType i(*mProtoI);
i = 0;
return i.setData(data());
}
@ -157,7 +163,9 @@ namespace MultiArrayTools
typename MultiArrayBase<T,SRanges...>::IndexType
MultiArrayBase<T,SRanges...>::endIndex() const
{
IndexType i = mRange->end();
IndexType i(*mProtoI);
i = i.max();
//i = mRange->size();
return i.setData(data());
}

View file

@ -95,13 +95,15 @@ namespace MultiArrayTools
typedef T value_type;
typedef OperationBase<T> OB;
typedef ContainerRange<T,Ranges...> CRange;
typedef typename MultiRange<Ranges...>::IndexType IndexType;
typedef ContainerIndex<T,typename Ranges::IndexType...> IndexType;
//typedef typename MultiRange<Ranges...>::IndexType IndexType;
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index);
IndexType& index);
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index,
//std::shared_ptr<IndexType>& index,
IndexType& index,
const IndexInfo* blockIndex);
inline void set(size_t pos, T val) { mDataPtr[pos] = val; }
@ -110,12 +112,11 @@ namespace MultiArrayTools
private:
std::shared_ptr<IndexType> mkIndex(std::shared_ptr<typename CRange::IndexType>& index);
void performAssignment(std::intptr_t blockIndexNum);
OpClass const& mSecond;
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
T* mDataPtr;
std::shared_ptr<IndexType> mIndex;
IndexType mIndex;
IndexInfo mIInfo;
};
@ -130,7 +131,7 @@ namespace MultiArrayTools
typedef OperationBase<T> OB;
typedef OperationTemplate<T,ConstOperationRoot<T,Ranges...> > OT;
typedef ContainerRange<T,Ranges...> CRange;
typedef typename CRange::IndexType IndexType;
typedef ContainerIndex<T,typename Ranges::IndexType...> IndexType;
static constexpr size_t SIZE = 1;
@ -147,13 +148,10 @@ namespace MultiArrayTools
private:
std::shared_ptr<IndexType>
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices);
MultiArrayBase<T,Ranges...> const& mArrayRef;
const T* mDataPtr;
std::shared_ptr<IndexType> mIndex;
//std::shared_ptr<IndexType> mIndex;
IndexType mIndex;
IndexInfo mIInfo;
};
@ -166,7 +164,7 @@ namespace MultiArrayTools
typedef OperationBase<T> OB;
typedef OperationTemplate<T,OperationRoot<T,Ranges...> > OT;
typedef ContainerRange<T,Ranges...> CRange;
typedef typename CRange::IndexType IndexType;
typedef ContainerIndex<T,typename Ranges::IndexType...> IndexType;
static constexpr size_t SIZE = 1;
@ -186,13 +184,9 @@ namespace MultiArrayTools
private:
std::shared_ptr<IndexType>
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices);
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
T* mDataPtr;
std::shared_ptr<IndexType> mIndex;
IndexType mIndex;
IndexInfo mIInfo;
};
@ -387,9 +381,9 @@ namespace MultiArrayTools
template <typename T, class OpClass, class... Ranges>
OperationMaster<T,OpClass,Ranges...>::
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index) :
IndexType& index) :
mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex(mkIndex(index)), mIInfo(*mIndex)
mIndex(index), mIInfo(mIndex)
{
performAssignment(0);
}
@ -397,32 +391,19 @@ namespace MultiArrayTools
template <typename T, class OpClass, class... Ranges>
OperationMaster<T,OpClass,Ranges...>::
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index,
IndexType& index,
const IndexInfo* blockIndex) :
mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex(mkIndex(index)), mIInfo(*mIndex)
mIndex(index), mIInfo(mIndex)
{
performAssignment(0);
}
template <typename T, class OpClass, class... Ranges>
std::shared_ptr<typename OperationMaster<T,OpClass,Ranges...>::IndexType>
OperationMaster<T,OpClass,Ranges...>::
mkIndex(std::shared_ptr<typename CRange::IndexType>& index)
{
MultiRangeFactory<Ranges...> mrf( index->range() );
std::shared_ptr<MultiRange<Ranges...> > mr =
std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
auto i = std::make_shared<IndexType>( mr->begin() );
(*i) = *index;
return i;
}
template <typename T, class OpClass, class... Ranges>
void OperationMaster<T,OpClass,Ranges...>::performAssignment(std::intptr_t blockIndexNum)
{
AssignmentExpr ae(*this, mSecond); // Expression to be executed within loop
const auto loop = mSecond.template loop<decltype(mIndex->ifor(ae))>( mIndex->ifor(ae) );
const auto loop = mSecond.template loop<decltype(mIndex.ifor(ae))>( mIndex.ifor(ae) );
// hidden Loops outside ! -> auto vectorizable
loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions
}
@ -443,18 +424,10 @@ namespace MultiArrayTools
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex)
{}
template <typename T, class... Ranges>
std::shared_ptr<typename ConstOperationRoot<T,Ranges...>::IndexType>
ConstOperationRoot<T,Ranges...>::
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices)
//mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex)
mIndex( ma.begin() ), mIInfo(mIndex)
{
auto i = std::make_shared<IndexType>( ma.range() );
(*mIndex)(indices...);
return i;
mIndex(indices...);
}
template <typename T, class... Ranges>
@ -467,7 +440,7 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
MExt<void> ConstOperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{
return MExt<void>(getStepSize( mIndex->info(), iPtrNum ));
return MExt<void>(getStepSize( mIndex.info(), iPtrNum ));
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
}
@ -488,18 +461,9 @@ namespace MultiArrayTools
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex( mkIndex( ma, indices... ) ), mIInfo(*mIndex)
{}
template <typename T, class... Ranges>
std::shared_ptr<typename OperationRoot<T,Ranges...>::IndexType>
OperationRoot<T,Ranges...>::
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices)
mIndex( ma.begin() ), mIInfo(mIndex)
{
auto i = std::make_shared<IndexType>( ma.range() );
(*mIndex)(indices...);
return i;
mIndex(indices...);
}
template <typename T, class... Ranges>
@ -519,7 +483,7 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
MExt<void> OperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{
return MExt<void>(getStepSize( mIndex->info(), iPtrNum ));
return MExt<void>(getStepSize( mIndex.info(), iPtrNum ));
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
}

View file

@ -34,6 +34,8 @@ namespace MultiArrayTools
private:
ContainerIndex() = default;
bool mNonTrivialBlocks = false;
bool mExternControl = false;
IndexPack mIPack;
@ -42,7 +44,8 @@ namespace MultiArrayTools
public:
ContainerIndex() = delete;
ContainerIndex(const ContainerIndex& in) = default;
ContainerIndex& operator=(const ContainerIndex& in) = default;
template <class MRange>
ContainerIndex(const std::shared_ptr<MRange>& range);

View file

@ -50,6 +50,7 @@ namespace {
typedef ContainerRangeFactory<double,M3Range,SRange> CRF;
typedef CRF::oType CRange;
typedef ContainerIndex<double,M3Range::IndexType,SRange::IndexType> CIndex;
IndexTest()
{
@ -182,8 +183,12 @@ namespace {
EXPECT_EQ(cr2ptr->size(), 12u);
auto mi = mstrptr->begin();
auto ci1 = cr1ptr->begin();
auto ci2 = cr2ptr->begin();
//auto ci1 = cr1ptr->begin();
CIndex ci1(cr1ptr);
ci1 = 0;
//auto ci2 = cr2ptr->begin();
CIndex ci2(cr2ptr);
ci2 = 0;
EXPECT_EQ(ci1.max(), 16u);
EXPECT_EQ(ci2.max(), 12u);