#include "dynamic_operation.h" #include "helper_tools.h" namespace MultiArrayTools { template T DynamicOperation::get(const DExtT& pos) const { return mOp.get(pos.expl()); } template DynamicOperationBase& DynamicOperation::set(const DExtT& pos) { mOp.set(pos.expl()); return *this; } template DExtT DynamicOperation::rootSteps(std::intptr_t iPtrNum) const { return DExtT(mkDExt(mkExtT(mOp.rootSteps(iPtrNum))),None(0)); } template DynamicExpression DynamicOperation::loop(const DynamicExpression& exp) const { return mOp.loop(exp); } template const T* DynamicOperation::data() const { return mOp.data(); } template std::shared_ptr> DynamicOperation::deepCopy() const { return std::make_shared>(*this); } template DynamicOuterOp::DynamicOuterOp(const DynamicOuterOp& in) : mThreadId(omp_get_thread_num()), mOp(in.mOp), mIndices(in.mIndices), mMa((mThreadId != in.mThreadId) ? std::make_shared>(*in.mMa) : in.mMa), mProto((mThreadId != in.mThreadId) ? OperationRoot(*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({1}), std::array({0})) : in.mL) {*mMa = 0;} template DynamicOuterOp::DynamicOuterOp(DynamicOuterOp&& in) : mThreadId(omp_get_thread_num()), mOp(in.mOp), mIndices(in.mIndices), mMa((mThreadId != in.mThreadId) ? std::make_shared>(*in.mMa) : in.mMa), mProto((mThreadId != in.mThreadId) ? OperationRoot(*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({1}), std::array({0})) : in.mL) {*mMa = 0;} template DynamicOuterOp& DynamicOuterOp::operator=(const DynamicOuterOp& in) { mThreadId = omp_get_thread_num(); mOp = in.mOp; mIndices = in.mIndices; if(mThreadId != in.mThreadId){ mMa = std::make_shared>(in.mMa); mProto = OperationRoot(*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({1}), std::array({0})); } else { mMa = in.mMa; mProto = in.mProto; mL = in.mL; } *mMa = 0; return *this; } template DynamicOuterOp& DynamicOuterOp::operator=(DynamicOuterOp&& in) { mThreadId = omp_get_thread_num(); mOp = in.mOp; mIndices = in.mIndices; if(mThreadId != in.mThreadId){ mMa = std::make_shared>(in.mMa); mProto = OperationRoot(*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({1}), std::array({0})); } else { mMa = in.mMa; mProto = in.mProto; mL = in.mL; } *mMa = 0; return *this; } template DynamicOuterOp::DynamicOuterOp(const Operation& op, const std::shared_ptr&... inds) : mThreadId(omp_get_thread_num()), mOp(op), mIndices(inds...), mMa(std::make_shared>(mkArray(inds->range()...))), mProto(OperationRoot(*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({1}), std::array({0})) {} template OpH> DynamicOuterOp::get(const DExtT& pos) const { mL(0,pos.expl()); return mProto; // empty } template DynamicOperationBase>>& DynamicOuterOp::set(const DExtT& pos) { mOp.set(pos.expl()); return *this; } template DExtT DynamicOuterOp::rootSteps(std::intptr_t iPtrNum) const { return DExtT(mkDExt(mkExtT(mL.rootSteps(iPtrNum))),None(0)); } template DynamicExpression DynamicOuterOp::loop(const DynamicExpression& exp) const { return mOp.loop(exp); // ???!! } template const OpH>* DynamicOuterOp::data() const { return &mProto; } template std::shared_ptr>>> DynamicOuterOp::deepCopy() const { return std::make_shared>(*this); } } // namespace MultiArrayTools