op_types: contraction (not finished)

This commit is contained in:
Christian Zimmermann 2022-10-22 02:42:18 +02:00
parent e3fe04d5da
commit fa1ea56d51
2 changed files with 39 additions and 96 deletions

View file

@ -164,12 +164,6 @@ namespace CNORXZ
return xpr; return xpr;
} }
template <typename T, class IndexT>
T* OpRoot<T,IndexT>::data() const
{
return mData;
}
/******************* /*******************
* Operation * * Operation *
@ -210,26 +204,6 @@ namespace CNORXZ
} }
} }
template <size_t I, typename V, class OpFunction, class ETuple, class OpTuple, typename... Args>
inline auto
mkVOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, Args... args)
{
if constexpr(I == std::tuple_size<OpTuple>{}){
if constexpr(OpFunction::FISSTATIC){
return VFunc<OpFunction>::apply(args...);
}
else {
auto vf = mkVFuncPtr(f);
(*vf)(args...);
}
}
else {
typedef typename std::remove_reference<decltype(std::get<I>(ops))>::type NextOpType;
return mkVOpExpr<I+1,V>( f, getX<NextOpType::SIZE>(pos), ops, args...,
std::get<I>(ops).template vget<V>(pos));
}
}
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
template <class ET> template <class ET>
inline auto Operation<T,OpFunction,Ops...>::get(ET pos) const inline auto Operation<T,OpFunction,Ops...>::get(ET pos) const
@ -284,51 +258,38 @@ namespace CNORXZ
* Contraction * * Contraction *
*********************/ *********************/
template <typename T, class Op, class IndexType> template <class CXpr>
Contraction<T,Op,IndexType>::Contraction(const Op& op, std::shared_ptr<IndexType> ind) : Contraction<CXpr>::Contraction(CXpr&& cxpr) :
mOp(op), mCXpr(cxpr)
mInd(ind) {} {}
// forward loop !!!! template <class CXpr>
template <typename T, class Op, class IndexType> template <class PosT>
template <class ET> constexpr decltype(auto) Contraction<CXpr>::get(const PosT& pos) const
inline auto Contraction<T,Op,IndexType>::get(ET pos) const
-> decltype(mOp.template get<ET>(pos))
{ {
return mOp.template get<ET>(pos); return mCXpr(pos);
} }
template <typename T, class Op, class IndexType> template <class CXpr>
template <typename V, class ET> template <SizeT I>
inline auto Contraction<T,Op,IndexType>::vget(ET pos) const constexpr decltype(auto) Contraction<CXpr>::rootSteps(const IndexId<I>& id) const;
-> decltype(mOp.template vget<V,ET>(pos))
{ {
return mOp.template vget<V,ET>(pos); return mCXpr.stepSize(id);
} }
template <typename T, class Op, class IndexType> template <class CXpr>
template <class ET>
inline Contraction<T,Op,IndexType>& Contraction<T,Op,IndexType>::set(ET pos)
{
mOp.set(pos);
return *this;
}
template <typename T, class Op, class IndexType>
auto Contraction<T,Op,IndexType>::rootSteps(std::intptr_t iPtrNum) const
-> decltype(mOp.rootSteps(iPtrNum))
{
return mOp.rootSteps(iPtrNum);
}
template <typename T, class Op, class IndexType>
template <class Expr> template <class Expr>
auto Contraction<T,Op,IndexType>::loop(Expr exp) const constexpr decltype(auto) Contraction<CXpr>::loop(Xpr&& xpr) const
-> decltype(mInd->iforh(1,mOp.loop(exp)))
{ {
return mInd->iforh(0,mOp.loop(exp)); return xpr;
} }
template <class F, class Op, class IndexT>
constexpr decltype(auto) mkContracion(F&& f, Op&& op, const Sptr<IndexT>& i)
{
typedef decltype(i->ifor( mkOpXpr( f, op ) )) CXprT;
return Contraction<CXprT>( i->ifor( mkOpXpr( f, op ) ) );
}
} }
#endif #endif

View file

@ -154,48 +154,30 @@ namespace CNORXZ
}; };
template <typename T, class Op, class IndexType> template <class CXpr>
class Contraction : public OperationTemplate<T,Contraction<T,Op,IndexType> > class Contraction : public OpInterface<Contraction<CXpr>>
{ {
public: public:
typedef OpInterface<Contraction<CXpr>> OI;
typedef T value_type; constexpr Contraction(CXpr&& cxpr);
typedef OperationBase<T,Contraction<T,Op,IndexType> > OT;
template <class PosT>
constexpr decltype(auto) get(const PosT& pos) const;
template <SizeT I>
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
template <class Xpr>
constexpr decltype(auto) loop(Xpr&& xpr) const;
static constexpr size_t SIZE = Op::SIZE;
static constexpr bool CONT = Op::CONT;
static constexpr bool VABLE = Op::VABLE;
private: private:
CXpr mCXpr;
Op mOp; Sptr<IndexType> mInd;
std::shared_ptr<IndexType> mInd;
public:
typedef decltype(mOp.rootSteps(0)) ETuple;
Contraction(const Op& op, std::shared_ptr<IndexType> ind);
template <class ET>
inline auto get(ET pos) const
-> decltype(mOp.template get<ET>(pos));
template <typename V, class ET>
inline auto vget(ET pos) const
-> decltype(mOp.template vget<V,ET>(pos));
template <class ET>
inline Contraction& set(ET pos);
T* data() const { assert(0); return nullptr; }
auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype
-> decltype(mOp.rootSteps(iPtrNum));
template <class Expr>
auto loop(Expr exp) const
-> decltype(mInd->iforh(1,mOp.loop(exp)));
}; };
template <class F, class Op, class IndexT>
constexpr decltype(auto) mkContracion(F&& f, Op&& op, const Sptr<IndexT>& i);
} }
#endif #endif