This commit is contained in:
Christian Zimmermann 2018-12-21 23:02:35 +01:00
parent bc372257f8
commit 9a4f6e7386
2 changed files with 23 additions and 17 deletions

View file

@ -317,7 +317,9 @@ namespace MultiArrayTools
-> For<SubIndex<Index>,SubExpr<Index,Expr>> -> For<SubIndex<Index>,SubExpr<Index,Expr>>
{ {
return For<SubIndex<Index>,SubExpr<Index,Expr>> return For<SubIndex<Index>,SubExpr<Index,Expr>>
(this, 1, SubExpr<Index,Expr>( mFullIndex, &mExplicitRangePtr->subset(), step, ex ) ); (this, 1, SubExpr<Index,Expr>
( mFullIndex, reinterpret_cast<std::intptr_t>(this),
&mExplicitRangePtr->subset(), step, ex ) );
} }
/************************ /************************

View file

@ -20,6 +20,8 @@ namespace MultiArrayHelper
typedef std::pair<size_t const*,size_t> DExt; typedef std::pair<size_t const*,size_t> DExt;
inline MExt<void> mkExt(size_t s) { return MExt<void>(s); }
class ExpressionBase class ExpressionBase
{ {
public: public:
@ -140,11 +142,12 @@ namespace MultiArrayHelper
SubExpr() = default; SubExpr() = default;
const IndexClass* mIndPtr; const IndexClass* mIndPtr;
std::intptr_t mSIPtr;
size_t mSPos; size_t mSPos;
size_t mMax; size_t mMax;
Expr mExpr; Expr mExpr;
typedef decltype(mExpr.rootSteps()) ExtType; typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType;
ExtType mExt; ExtType mExt;
const std::vector<size_t>* mSubSet; const std::vector<size_t>* mSubSet;
@ -164,10 +167,12 @@ namespace MultiArrayHelper
SubExpr& operator=(SubExpr&& in) = default; SubExpr& operator=(SubExpr&& in) = default;
SubExpr(const std::shared_ptr<IndexClass>& indPtr, SubExpr(const std::shared_ptr<IndexClass>& indPtr,
std::intptr_t siptr,
const std::vector<size_t>* subset, const std::vector<size_t>* subset,
size_t step, Expr expr); size_t step, Expr expr);
SubExpr(const IndexClass* indPtr, SubExpr(const IndexClass* indPtr,
std::intptr_t siptr,
const std::vector<size_t>* subset, const std::vector<size_t>* subset,
size_t step, Expr expr); size_t step, Expr expr);
@ -488,11 +493,13 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const std::shared_ptr<IndexClass>& indPtr, SubExpr<IndexClass,Expr>::SubExpr(const std::shared_ptr<IndexClass>& indPtr,
std::intptr_t siptr,
const std::vector<size_t>* subset, const std::vector<size_t>* subset,
size_t step, size_t step,
Expr expr) : Expr expr) :
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ))), mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
mSubSet(subset), mStep(step) mSubSet(subset), mStep(step)
{ {
assert(mIndPtr != nullptr); assert(mIndPtr != nullptr);
@ -500,11 +507,13 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr, SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr,
std::intptr_t siptr,
const std::vector<size_t>* subset, const std::vector<size_t>* subset,
size_t step, size_t step,
Expr expr) : Expr expr) :
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ))), mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
mSubSet(subset), mStep(step) mSubSet(subset), mStep(step)
{ {
assert(mIndPtr != nullptr); assert(mIndPtr != nullptr);
@ -521,25 +530,20 @@ namespace MultiArrayHelper
ExtType last) const ExtType last) const
{ {
// INCLUDE FOR LOOP HERE AGIAN !!!! // INCLUDE FOR LOOP HERE AGIAN !!!!
const size_t pos = (*mSubSet)[mlast]; const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast * mStep; const size_t mnpos = mlast * mStep;
VCHECK(mlast);
VCHECK(pos);
VCHECK(mnpos);
const ExtType npos = last + mExt*pos; const ExtType npos = last + mExt*pos;
VCHECK(npos.val()); mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
VCHECK(npos.next().val());
mExpr(mnpos, npos);
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast) const inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast) const
{ {
const ExtType last; const ExtType last;
const size_t pos = (*mSubSet)[mlast]; const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast * mStep; const size_t mnpos = mlast * mStep;
const ExtType npos = last + mExt*pos; const ExtType npos = last + mExt*pos;
mExpr(mnpos, npos); mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
} }
@ -547,7 +551,7 @@ namespace MultiArrayHelper
auto SubExpr<IndexClass,Expr>::rootSteps(std::intptr_t iPtrNum) const auto SubExpr<IndexClass,Expr>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType -> ExtType
{ {
return mExpr.rootSteps(iPtrNum); return mkExt(iPtrNum == mSIPtr ? 1 : 0).extend(mExpr.rootSteps(iPtrNum));
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>