cnorxz/src/include/dynamic_operation.cc.h

199 lines
6.9 KiB
C
Raw Normal View History

2020-07-10 00:17:38 +02:00
#include "dynamic_operation.h"
2020-08-27 23:48:04 +02:00
#include "helper_tools.h"
2020-07-10 00:17:38 +02:00
namespace MultiArrayTools
{
template <typename T, class Operation>
T DynamicOperation<T,Operation>::get(const DExtT& pos) const
2020-07-10 00:17:38 +02:00
{
return mOp.get(pos.expl<ET>());
2020-07-10 00:17:38 +02:00
}
template <typename T, class Operation>
2020-07-13 01:00:35 +02:00
DynamicOperationBase<T>& DynamicOperation<T,Operation>::set(const DExtT& pos)
2020-07-10 00:17:38 +02:00
{
mOp.set(pos.expl<ET>());
return *this;
}
template <typename T, class Operation>
2020-07-13 01:00:35 +02:00
DExtT DynamicOperation<T,Operation>::rootSteps(std::intptr_t iPtrNum) const
2020-07-10 00:17:38 +02:00
{
2020-08-24 16:35:14 +02:00
return DExtT(mkDExt(mkExtT(mOp.rootSteps(iPtrNum))),None(0));
2020-07-10 00:17:38 +02:00
}
template <typename T, class Operation>
DynamicExpression DynamicOperation<T,Operation>::loop(const DynamicExpression& exp) const
{
return mOp.loop(exp);
}
template <typename T, class Operation>
const T* DynamicOperation<T,Operation>::data() const
{
return mOp.data();
}
2020-08-24 16:35:14 +02:00
template <typename T, class Operation>
std::shared_ptr<DynamicOperationBase<T>> DynamicOperation<T,Operation>::deepCopy() const
{
return std::make_shared<DynamicOperation<T,Operation>>(*this);
}
template <typename T, class Operation, class... Ranges>
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(const DynamicOuterOp& in) :
mThreadId(omp_get_thread_num()), mOp(in.mOp),
mIndices(in.mIndices),
mMa((mThreadId != in.mThreadId) ? std::make_shared<MultiArray<T,Ranges...>>(*in.mMa) : in.mMa),
mProto((mThreadId != in.mThreadId) ? OperationRoot<T,Ranges...>(*mMa,mIndices) : in.mProto),
mL((mThreadId != in.mThreadId) ?
mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
std::make_tuple(mMa),
std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(mIndices) )),
std::array<size_t,1>({1}), std::array<size_t,1>({0})) :
in.mL)
{*mMa = 0;}
template <typename T, class Operation, class... Ranges>
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(DynamicOuterOp&& in) :
mThreadId(omp_get_thread_num()), mOp(in.mOp),
mIndices(in.mIndices),
mMa((mThreadId != in.mThreadId) ? std::make_shared<MultiArray<T,Ranges...>>(*in.mMa) : in.mMa),
mProto((mThreadId != in.mThreadId) ? OperationRoot<T,Ranges...>(*mMa,mIndices) : in.mProto),
mL((mThreadId != in.mThreadId) ?
mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
std::make_tuple(mMa),
std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(mIndices) )),
std::array<size_t,1>({1}), std::array<size_t,1>({0})) :
in.mL)
{*mMa = 0;}
template <typename T, class Operation, class... Ranges>
DynamicOuterOp<T,Operation,Ranges...>&
DynamicOuterOp<T,Operation,Ranges...>::operator=(const DynamicOuterOp& in)
{
mThreadId = omp_get_thread_num();
mOp = in.mOp;
mIndices = in.mIndices;
if(mThreadId != in.mThreadId){
mMa = std::make_shared<MultiArray<T,Ranges...>>(in.mMa);
mProto = OperationRoot<T,Ranges...>(*mMa,mIndices);
mL = mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
std::make_tuple(mMa),
std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(mIndices) )),
std::array<size_t,1>({1}), std::array<size_t,1>({0}));
}
else {
mMa = in.mMa;
mProto = in.mProto;
mL = in.mL;
}
*mMa = 0;
return *this;
}
template <typename T, class Operation, class... Ranges>
DynamicOuterOp<T,Operation,Ranges...>&
DynamicOuterOp<T,Operation,Ranges...>::operator=(DynamicOuterOp&& in)
{
mThreadId = omp_get_thread_num();
mOp = in.mOp;
mIndices = in.mIndices;
if(mThreadId != in.mThreadId){
mMa = std::make_shared<MultiArray<T,Ranges...>>(in.mMa);
mProto = OperationRoot<T,Ranges...>(*mMa,mIndices);
mL = mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
std::make_tuple(mMa),
std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(mIndices) )),
std::array<size_t,1>({1}), std::array<size_t,1>({0}));
}
else {
mMa = in.mMa;
mProto = in.mProto;
mL = in.mL;
}
*mMa = 0;
return *this;
}
2020-08-27 17:46:30 +02:00
template <typename T, class Operation, class... Ranges>
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(const Operation& op,
const std::shared_ptr<typename Ranges::IndexType>&... inds)
: mThreadId(omp_get_thread_num()), mOp(op),
mIndices(inds...),
2020-08-27 23:48:04 +02:00
mMa(std::make_shared<MultiArray<T,Ranges...>>(mkArray<T>(inds->range()...))),
2020-08-28 13:46:12 +02:00
mProto(OperationRoot<T,Ranges...>(*mMa,inds...)),
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(inds...),
std::make_tuple(mMa), std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(inds...) )),
std::array<size_t,1>({1}), std::array<size_t,1>({0}))
{}
2020-08-27 17:46:30 +02:00
2020-08-30 14:43:53 +02:00
/*
DynamicOuterOp(const std::shared_ptr<DynamicOperationBase<OpH<OperationRoot<typename Operatrion::value_type,Ranges...>>>>& dyn,
const Operation& op, const std::shared_ptr<Indices>&... inds )
: mThreadId(omp_get_thread_num()),
//mDyn(dyn),
mOp(op), mIndices(inds...),
mMa(std::make_shared<MultiArray<T,Ranges...>>(mkArray<T>(inds->range()...))),
mProto(OperationRoot<T,Ranges...>(*mMa,inds...)),
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(inds...),
std::make_tuple(mMa), std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(inds...) )),
std::array<size_t,1>({1}), std::array<size_t,1>({0}))
{}
*/
2020-08-27 17:46:30 +02:00
template <typename T, class Operation, class... Ranges>
2020-08-27 23:48:04 +02:00
OpH<OperationRoot<T,Ranges...>> DynamicOuterOp<T,Operation,Ranges...>::get(const DExtT& pos) const
2020-08-27 17:46:30 +02:00
{
2020-08-30 14:43:53 +02:00
//if(mPrev) mPrev.get(pos.expl<ET>());
mL(0,pos.expl<ET>());
return mProto; // empty
2020-08-27 17:46:30 +02:00
}
template <typename T, class Operation, class... Ranges>
2020-08-27 23:48:04 +02:00
DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>&
2020-08-27 17:46:30 +02:00
DynamicOuterOp<T,Operation,Ranges...>::set(const DExtT& pos)
{
mOp.set(pos.expl<ET>());
return *this;
}
template <typename T, class Operation, class... Ranges>
DExtT DynamicOuterOp<T,Operation,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{
2020-08-28 13:46:12 +02:00
return DExtT(mkDExt(mkExtT(mL.rootSteps(iPtrNum))),None(0));
2020-08-27 17:46:30 +02:00
}
template <typename T, class Operation, class... Ranges>
DynamicExpression DynamicOuterOp<T,Operation,Ranges...>::loop(const DynamicExpression& exp) const
{
2020-08-28 13:46:12 +02:00
return mOp.loop(exp); // ???!!
2020-08-27 17:46:30 +02:00
}
template <typename T, class Operation, class... Ranges>
2020-08-27 23:48:04 +02:00
const OpH<OperationRoot<T,Ranges...>>* DynamicOuterOp<T,Operation,Ranges...>::data() const
2020-08-27 17:46:30 +02:00
{
return &mProto;
}
2020-08-30 14:43:53 +02:00
/*
2020-08-30 03:52:44 +02:00
template <class Op1, class Op2>
template <class ET>
inline T TwoOp<Op1,Op2>::get(const ET& pos) const
{
return mOp2.get(pos);
}
2020-08-30 14:43:53 +02:00
*/
2020-08-27 17:46:30 +02:00
template <typename T, class Operation, class... Ranges>
2020-08-27 23:48:04 +02:00
std::shared_ptr<DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>>
2020-08-27 17:46:30 +02:00
DynamicOuterOp<T,Operation,Ranges...>::deepCopy() const
{
return std::make_shared<DynamicOuterOp<T,Operation,Ranges...>>(*this);
}
2020-07-13 01:00:35 +02:00
2020-07-10 00:17:38 +02:00
} // namespace MultiArrayTools