meta ref in index + dynamic function

This commit is contained in:
Christian Zimmermann 2018-03-19 18:38:53 +01:00
parent ea139067dd
commit 7fdaef7b2f
3 changed files with 24 additions and 3 deletions

View file

@ -41,6 +41,16 @@ namespace MultiArrayHelper
} }
}; };
template <typename T, class Func>
struct dynamic_function
{
template <typename... Us>
static inline T apply(const Func& f, Us... args)
{
return f(args...);
}
}
} // end namespace MultiArrayHelper } // end namespace MultiArrayHelper
#endif #endif

View file

@ -258,6 +258,7 @@ namespace MultiArrayTools
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp)); -> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp));
}; };
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
class Contraction : public OperationTemplate<T,Contraction<T,Op,IndexType> > class Contraction : public OperationTemplate<T,Contraction<T,Op,IndexType> >

View file

@ -48,6 +48,7 @@ namespace MultiArrayTools
int mm(std::intptr_t idxPtrNum); int mm(std::intptr_t idxPtrNum);
U meta(); U meta();
U* metaPtr();
SingleIndex& at(const U& metaPos); SingleIndex& at(const U& metaPos);
size_t dim(); // = 1 size_t dim(); // = 1
@ -72,6 +73,8 @@ namespace MultiArrayTools
auto iforh(Expr ex) const auto iforh(Expr ex) const
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>; -> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>;
private:
U* mMetaPtr;
}; };
template <typename U, SpaceType TYPE> template <typename U, SpaceType TYPE>
@ -110,7 +113,7 @@ namespace MultiArrayTools
static constexpr bool defaultable = false; static constexpr bool defaultable = false;
static constexpr size_t ISSTATIC = 0; static constexpr size_t ISSTATIC = 0;
static constexpr size_t SIZE = -1; static constexpr size_t SIZE = -1;
static constexpr bool HASMETACONT = true;
protected: protected:
@ -136,7 +139,8 @@ namespace MultiArrayTools
template <typename U, SpaceType TYPE> template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) : SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
IndexInterface<SingleIndex<U,TYPE>,U>(range, 0) {} IndexInterface<SingleIndex<U,TYPE>,U>(range, 0),
mMetaPtr(&IB::mRangePtr->get(0)) {}
template <typename U, SpaceType TYPE> template <typename U, SpaceType TYPE>
IndexType SingleIndex<U,TYPE>::type() const IndexType SingleIndex<U,TYPE>::type() const
@ -182,9 +186,15 @@ namespace MultiArrayTools
template <typename U, SpaceType TYPE> template <typename U, SpaceType TYPE>
U SingleIndex<U,TYPE>::meta() U SingleIndex<U,TYPE>::meta()
{ {
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->get( IB::pos() ); return mMetaPtr[IB::mPos];
} }
template <typename U, SpaceType TYPE>
U* SingleIndex<U,TYPE>::metaPtr()
{
return mMetaPtr;
}
template <typename U, SpaceType TYPE> template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::at(const U& metaPos) SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::at(const U& metaPos)
{ {