fixes in dynamic index (ForMaker) + set offset of operation by given index

This commit is contained in:
Christian Zimmermann 2018-12-02 22:08:51 +01:00
parent 7331ff608f
commit bdabee1335
3 changed files with 52 additions and 16 deletions

View file

@ -185,6 +185,7 @@ namespace MultiArrayTools
{ {
//VCHECK(ma.data()); //VCHECK(ma.data());
mIndex(indices...); mIndex(indices...);
mOff = mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -196,13 +197,17 @@ namespace MultiArrayTools
mMaPtr(maptr) mMaPtr(maptr)
{ {
mIndex(indices...); mIndex(indices...);
mOff = mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
ConstOperationRoot<T,Ranges...>:: ConstOperationRoot<T,Ranges...>::
ConstOperationRoot(const T* data, const IndexType& ind) : ConstOperationRoot(const T* data, const IndexType& ind) :
mDataPtr(data), mDataPtr(data),
mIndex( ind ) { } mIndex( ind )
{
mOff = mIndex.pos();
}
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class ET> template <class ET>
@ -335,13 +340,17 @@ namespace MultiArrayTools
mIndex( ma.begin() ) mIndex( ma.begin() )
{ {
mIndex(indices...); mIndex(indices...);
mOff = mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
OperationRoot<T,Ranges...>:: OperationRoot<T,Ranges...>::
OperationRoot(T* data, const IndexType& ind) : OperationRoot(T* data, const IndexType& ind) :
mDataPtr(data), mDataPtr(data),
mIndex( ind ) { } mIndex( ind )
{
mOff = mIndex.pos();
}
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>

View file

@ -201,10 +201,24 @@ namespace MultiArrayTools
return *this; return *this;
} }
template <class EC>
DynamicIndex<EC>& DynamicIndex<EC>::sync()
{
size_t sv = 1;
IB::mPos = 0;
for(size_t i = 0; i != mIVec.size(); ++i){
auto& x = mIVec[mIVec.size()-i-1];
IB::mPos += x.first->pos() * sv;
sv *= x.first->max();
}
return *this;
}
template <class EC> template <class EC>
DynamicIndex<EC>& DynamicIndex<EC>::operator()(const IVecT& ivec) DynamicIndex<EC>& DynamicIndex<EC>::operator()(const IVecT& ivec)
{ {
mIVec = ivec; mIVec = ivec;
sync();
return *this; return *this;
} }
@ -215,6 +229,7 @@ namespace MultiArrayTools
for(size_t i = 0; i != mIVec.size(); ++i){ for(size_t i = 0; i != mIVec.size(); ++i){
mIVec[i].first = ivec[i]; mIVec[i].first = ivec[i];
} }
sync();
return *this; return *this;
} }
@ -229,6 +244,7 @@ namespace MultiArrayTools
for(size_t i = 0; i != mIVec.size(); ++i){ for(size_t i = 0; i != mIVec.size(); ++i){
mIVec[i].first = tmp[i]; mIVec[i].first = tmp[i];
} }
sync();
return *this; return *this;
} }
@ -349,17 +365,18 @@ namespace MultiArrayTools
const IVecT& ivec, bool hidden = false) const IVecT& ivec, bool hidden = false)
-> ExpressionHolder<Expr> -> ExpressionHolder<Expr>
{ {
if(i != 0){ if(i == 0) {
auto& ii = *ivec[0].first;
return hidden ? ii.iforh(step*ivec[i].second, ex) :
ii.ifor(step*ivec[i].second, ex);
}
else {
auto& ii = *ivec[i].first; auto& ii = *ivec[i].first;
return mk(i-1, step, return mk(i-1, step,
(hidden ? ii.iforh(step*ivec[i].second, ex) : (hidden ? ii.iforh(step*ivec[i].second, ex) :
ii.ifor(step*ivec[i].second, ex)), ii.ifor(step*ivec[i].second, ex)),
ivec, hidden); ivec, hidden);
}
else {
auto& ii = *ivec[0].first;
return hidden ? ii.iforh(step*ivec[i].second, ex) :
ii.ifor(step*ivec[i].second, ex);
} }
} }
}; };
@ -386,19 +403,27 @@ namespace MultiArrayTools
template <class Expr> template <class Expr>
ExpressionHolder<Expr> DynamicIndex<EC>::ifor(size_t step, Expr ex) const ExpressionHolder<Expr> DynamicIndex<EC>::ifor(size_t step, Expr ex) const
{ {
if(mIVec.size() == 1){
return mIVec.back().first->ifori(step,ex);
}
else {
return ForMaker<Expr>::mk(mIVec.size()-2, step, mIVec.back().first->ifori(step,ex), return ForMaker<Expr>::mk(mIVec.size()-2, step, mIVec.back().first->ifori(step,ex),
mIVec); mIVec);
} }
}
template <class EC> template <class EC>
template <class Expr> template <class Expr>
ExpressionHolder<Expr> DynamicIndex<EC>::iforh(size_t step, Expr ex) const ExpressionHolder<Expr> DynamicIndex<EC>::iforh(size_t step, Expr ex) const
{ {
if(mIVec.size() == 1){
return mIVec.back().first->iforhi(step,ex);
}
else {
return ForMaker<Expr>::mk(mIVec.size()-2, step, mIVec.back().first->iforhi(step,ex), return ForMaker<Expr>::mk(mIVec.size()-2, step, mIVec.back().first->iforhi(step,ex),
mIVec, true); mIVec, true);
} }
}
/*********************** /***********************
* DynamicRange * * DynamicRange *

View file

@ -202,6 +202,8 @@ namespace MultiArrayTools
template <class... Indices> template <class... Indices>
DynamicIndex& operator()(const std::shared_ptr<Indices>&... is); DynamicIndex& operator()(const std::shared_ptr<Indices>&... is);
DynamicIndex<EC>& sync();
int pp(std::intptr_t idxPtrNum); int pp(std::intptr_t idxPtrNum);
int mm(std::intptr_t idxPtrNum); int mm(std::intptr_t idxPtrNum);