im com
This commit is contained in:
parent
34161f10cb
commit
7afd193d09
3 changed files with 74 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "dynamic_operation.h"
|
#include "dynamic_operation.h"
|
||||||
|
#include "helper_tools.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
@ -43,23 +44,28 @@ namespace MultiArrayTools
|
||||||
template <typename T, class Operation, class... Ranges>
|
template <typename T, class Operation, class... Ranges>
|
||||||
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(const Operation& op,
|
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(const Operation& op,
|
||||||
const std::shared_ptr<typename Ranges::IndexType>&... inds)
|
const std::shared_ptr<typename Ranges::IndexType>&... inds)
|
||||||
: mOp(op)
|
: mOp(op),
|
||||||
|
mMa(std::make_shared<MultiArray<T,Ranges...>>(mkArray<T>(inds->range()...))),
|
||||||
|
mProto((*mMa)(inds...))
|
||||||
{
|
{
|
||||||
//...!!!
|
/*
|
||||||
// setup operations
|
auto ll = mkILoop(std::make_tuple(mProto.mOp,mOp), std::make_tuple(inds...),
|
||||||
|
std::make_tuple(mMa), std::make_tuple(mProto.mOp.assign( mOp )),
|
||||||
|
std::array<size_t,1>({0}), std::array<size_t,1>({0}));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Operation, class... Ranges>
|
template <typename T, class Operation, class... Ranges>
|
||||||
OpH<ConstOperationRoot<T,Ranges...>> DynamicOuterOp<T,Operation,Ranges...>::get(const DExtT& pos) const
|
OpH<OperationRoot<T,Ranges...>> DynamicOuterOp<T,Operation,Ranges...>::get(const DExtT& pos) const
|
||||||
{
|
{
|
||||||
mOp.get(pos.expl<ET>());
|
mOp.get(pos.expl<ET>());
|
||||||
//...
|
//mL();
|
||||||
// execute assignment... care about threads!!!
|
// execute assignment... care about threads!!!
|
||||||
return OpH<ConstOperationRoot<T,Ranges...>>(); // empty
|
return mProto.mOp; // empty
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Operation, class... Ranges>
|
template <typename T, class Operation, class... Ranges>
|
||||||
DynamicOperationBase<OpH<ConstOperationRoot<T,Ranges...>>>&
|
DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>&
|
||||||
DynamicOuterOp<T,Operation,Ranges...>::set(const DExtT& pos)
|
DynamicOuterOp<T,Operation,Ranges...>::set(const DExtT& pos)
|
||||||
{
|
{
|
||||||
mOp.set(pos.expl<ET>());
|
mOp.set(pos.expl<ET>());
|
||||||
|
@ -79,16 +85,24 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Operation, class... Ranges>
|
template <typename T, class Operation, class... Ranges>
|
||||||
const OpH<ConstOperationRoot<T,Ranges...>>* DynamicOuterOp<T,Operation,Ranges...>::data() const
|
const OpH<OperationRoot<T,Ranges...>>* DynamicOuterOp<T,Operation,Ranges...>::data() const
|
||||||
{
|
{
|
||||||
return &mProto;
|
return &mProto;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Operation, class... Ranges>
|
template <typename T, class Operation, class... Ranges>
|
||||||
std::shared_ptr<DynamicOperationBase<OpH<ConstOperationRoot<T,Ranges...>>>>
|
std::shared_ptr<DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>>
|
||||||
DynamicOuterOp<T,Operation,Ranges...>::deepCopy() const
|
DynamicOuterOp<T,Operation,Ranges...>::deepCopy() const
|
||||||
{
|
{
|
||||||
return std::make_shared<DynamicOuterOp<T,Operation,Ranges...>>(*this);
|
return std::make_shared<DynamicOuterOp<T,Operation,Ranges...>>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Operation, class... Indices>
|
||||||
|
DynamicOuterOp<typename Operation::value_type,Operation,typename Indices::RangeType...>
|
||||||
|
mkDynOutOp(const Operation& op, const std::shared_ptr<Indices>&... inds)
|
||||||
|
{
|
||||||
|
return DynamicOuterOp<typename Operation::value_type,Operation,
|
||||||
|
typename Indices::RangeType...>(op, inds...);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace MultiArrayTools
|
||||||
|
|
|
@ -61,16 +61,26 @@ namespace MultiArrayTools
|
||||||
template <class Op>
|
template <class Op>
|
||||||
struct OpH
|
struct OpH
|
||||||
{
|
{
|
||||||
Op mOp;
|
Op mOp;
|
||||||
|
OpH(const Op& op) : mOp(op) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, class Operation, class... Ranges>
|
template <typename T, class Operation, class... Ranges>
|
||||||
class DynamicOuterOp : public DynamicOperationBase<OpH<ConstOperationRoot<T,Ranges...>>>
|
class DynamicOuterOp : public DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Operation mOp;
|
Operation mOp;
|
||||||
//ConstOperationRoot<T,Ranges...> mProto;
|
//OperationRoot<T,Ranges...> mProto;
|
||||||
OpH<ConstOperationRoot<T,Ranges...>> mProto;
|
std::shared_ptr<MultiArray<T,Ranges...>> mMa;
|
||||||
|
OpH<OperationRoot<T,Ranges...>> mProto;
|
||||||
|
/*
|
||||||
|
typedef ILoop<std::tuple<OperationRoot<T,Ranges...>,Operation>,
|
||||||
|
std::tuple<std::shared_ptr<typename Ranges::IndexType>...>,
|
||||||
|
std::tuple<std::shared_ptr<MultiArray<T,Ranges...>>>,
|
||||||
|
std::tuple<decltype(mProto.mOp.assign( mOp ))>> LoopT;
|
||||||
|
|
||||||
|
LoopT mL;
|
||||||
|
*/
|
||||||
public:
|
public:
|
||||||
typedef decltype(mOp.rootSteps()) ET;
|
typedef decltype(mOp.rootSteps()) ET;
|
||||||
//typedef decltype(std::declval<Operation>().rootSteps()) ET;
|
//typedef decltype(std::declval<Operation>().rootSteps()) ET;
|
||||||
|
@ -83,14 +93,18 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
DynamicOuterOp(const Operation& op, const std::shared_ptr<typename Ranges::IndexType>&... inds);
|
DynamicOuterOp(const Operation& op, const std::shared_ptr<typename Ranges::IndexType>&... inds);
|
||||||
|
|
||||||
virtual OpH<ConstOperationRoot<T,Ranges...>> get(const DExtT& pos) const override final;
|
virtual OpH<OperationRoot<T,Ranges...>> get(const DExtT& pos) const override final;
|
||||||
virtual DynamicOperationBase<OpH<ConstOperationRoot<T,Ranges...>>>& set(const DExtT& pos) override final;
|
virtual DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>& set(const DExtT& pos) override final;
|
||||||
virtual DExtT rootSteps(std::intptr_t iPtrNum = 0) const override final;
|
virtual DExtT rootSteps(std::intptr_t iPtrNum = 0) const override final;
|
||||||
virtual DynamicExpression loop(const DynamicExpression& exp) const override final;
|
virtual DynamicExpression loop(const DynamicExpression& exp) const override final;
|
||||||
virtual const OpH<ConstOperationRoot<T,Ranges...>>* data() const override final;
|
virtual const OpH<OperationRoot<T,Ranges...>>* data() const override final;
|
||||||
virtual std::shared_ptr<DynamicOperationBase<OpH<ConstOperationRoot<T,Ranges...>>>> deepCopy() const override final;
|
virtual std::shared_ptr<DynamicOperationBase<OpH<OperationRoot<T,Ranges...>>>> deepCopy() const override final;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class Operation, class... Indices>
|
||||||
|
DynamicOuterOp<typename Operation::value_type,Operation,typename Indices::RangeType...>
|
||||||
|
mkDynOutOp(const Operation& op, const std::shared_ptr<Indices>&... inds);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class DynamicO : public OperationTemplate<T,DynamicO<T>>
|
class DynamicO : public OperationTemplate<T,DynamicO<T>>
|
||||||
{
|
{
|
||||||
|
@ -113,6 +127,9 @@ namespace MultiArrayTools
|
||||||
template <class Op>
|
template <class Op>
|
||||||
DynamicO(const Op& op) : mOp(std::make_shared<DynamicOperation<T,Op>>(op)) {}
|
DynamicO(const Op& op) : mOp(std::make_shared<DynamicOperation<T,Op>>(op)) {}
|
||||||
|
|
||||||
|
DynamicO(const std::shared_ptr<DynamicOperationBase<T>>& op) :
|
||||||
|
mOp(op) {}
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
inline T get(const DExtTX<X>& pos) const { return mOp->get(pos.reduce()); }
|
inline T get(const DExtTX<X>& pos) const { return mOp->get(pos.reduce()); }
|
||||||
template <class X>
|
template <class X>
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace
|
||||||
std::map<std::string,std::shared_ptr<IndexW>> imap;
|
std::map<std::string,std::shared_ptr<IndexW>> imap;
|
||||||
|
|
||||||
std::shared_ptr<DR> dr1;
|
std::shared_ptr<DR> dr1;
|
||||||
|
std::shared_ptr<DR> dr1a;
|
||||||
std::shared_ptr<DR> dr2;
|
std::shared_ptr<DR> dr2;
|
||||||
std::shared_ptr<DR> dr3;
|
std::shared_ptr<DR> dr3;
|
||||||
std::shared_ptr<DR> dr4;
|
std::shared_ptr<DR> dr4;
|
||||||
|
@ -60,6 +61,8 @@ namespace
|
||||||
std::shared_ptr<DR> dr6;
|
std::shared_ptr<DR> dr6;
|
||||||
std::shared_ptr<CR> cr1;
|
std::shared_ptr<CR> cr1;
|
||||||
|
|
||||||
|
std::shared_ptr<CR::IndexType> ci4;
|
||||||
|
|
||||||
OpTest_Dyn()
|
OpTest_Dyn()
|
||||||
{
|
{
|
||||||
cr1 = createRangeE<CR>(5);
|
cr1 = createRangeE<CR>(5);
|
||||||
|
@ -70,6 +73,7 @@ namespace
|
||||||
auto cr5 = createRangeE<CR>(13);
|
auto cr5 = createRangeE<CR>(13);
|
||||||
|
|
||||||
dr1 = createRangeE<DR>(cr2,cr2,cr3,cr4);
|
dr1 = createRangeE<DR>(cr2,cr2,cr3,cr4);
|
||||||
|
dr1a = createRangeE<DR>(cr2,cr2,cr3);
|
||||||
dr2 = createRangeE<DR>(cr3,cr3,cr4);
|
dr2 = createRangeE<DR>(cr3,cr3,cr4);
|
||||||
dr3 = createRangeE<DR>(cr2,cr5);
|
dr3 = createRangeE<DR>(cr2,cr5);
|
||||||
dr5 = createRangeE<DR>(cr5);
|
dr5 = createRangeE<DR>(cr5);
|
||||||
|
@ -94,7 +98,8 @@ namespace
|
||||||
imap["i2_2"] = mkIndexW(getIndex(cr2));
|
imap["i2_2"] = mkIndexW(getIndex(cr2));
|
||||||
imap["i3_1"] = mkIndexW(getIndex(cr3));
|
imap["i3_1"] = mkIndexW(getIndex(cr3));
|
||||||
imap["i3_2"] = mkIndexW(getIndex(cr3));
|
imap["i3_2"] = mkIndexW(getIndex(cr3));
|
||||||
imap["i4_1"] = mkIndexW(getIndex(cr4));
|
ci4 = getIndex(cr4);
|
||||||
|
imap["i4_1"] = mkIndexW(ci4);
|
||||||
imap["i4_2"] = mkIndexW(getIndex(cr4));
|
imap["i4_2"] = mkIndexW(getIndex(cr4));
|
||||||
imap["i5_1"] = mkIndexW(getIndex(cr5));
|
imap["i5_1"] = mkIndexW(getIndex(cr5));
|
||||||
imap["i5_2"] = mkIndexW(getIndex(cr5));
|
imap["i5_2"] = mkIndexW(getIndex(cr5));
|
||||||
|
@ -105,21 +110,39 @@ namespace
|
||||||
{
|
{
|
||||||
auto i1 = getIndex(cr1);
|
auto i1 = getIndex(cr1);
|
||||||
auto di1 = getIndex(dr1);
|
auto di1 = getIndex(dr1);
|
||||||
|
auto di1a = getIndex(dr1a);
|
||||||
auto di2 = getIndex(dr2);
|
auto di2 = getIndex(dr2);
|
||||||
auto di4 = getIndex(dr4);
|
auto di4 = getIndex(dr4);
|
||||||
|
|
||||||
|
auto mi = mkMIndex(i1,di1a);
|
||||||
|
|
||||||
(*di1)({imap["i2_1"],imap["i2_2"],imap["i3_1"],imap["i4_1"]});
|
(*di1)({imap["i2_1"],imap["i2_2"],imap["i3_1"],imap["i4_1"]});
|
||||||
|
(*di1a)({imap["i2_1"],imap["i2_2"],imap["i3_1"]});
|
||||||
(*di2)({imap["i3_1"],imap["i3_1"],imap["i4_2"]});
|
(*di2)({imap["i3_1"],imap["i3_1"],imap["i4_2"]});
|
||||||
(*di4)({imap["i2_1"],imap["i3_1"],imap["i4_1"],imap["i4_2"]});
|
(*di4)({imap["i2_1"],imap["i3_1"],imap["i4_1"],imap["i4_2"]});
|
||||||
|
|
||||||
auto resx1 = res1;
|
auto resx1 = res1;
|
||||||
auto resx2 = res1;
|
auto resx2 = res1;
|
||||||
auto resx3 = res1;
|
auto resx3 = res1;
|
||||||
|
auto resx4 = res1;
|
||||||
|
//auto xx = std::make_shared<decltype(resx4)>(resx4);
|
||||||
res1(i1,di4) = ma1(i1,di1) * ma2(i1,di2);
|
res1(i1,di4) = ma1(i1,di1) * ma2(i1,di2);
|
||||||
resx1(i1,di4) = mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2));
|
resx1(i1,di4) = mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2));
|
||||||
resx2(i1,di4) = mkDynOp(ma1(i1,di1) * ma2(i1,di2));
|
resx2(i1,di4) = mkDynOp(ma1(i1,di1) * ma2(i1,di2));
|
||||||
resx3(i1,di4) = mkDynOp(mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2)));
|
resx3(i1,di4) = mkDynOp(mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2)));
|
||||||
|
|
||||||
|
auto op1 = mkDynOutOp(ma1(i1,di1) * ma2(i1,di2), ci4);
|
||||||
|
/**auto opr = resx4(i1,di4);
|
||||||
|
auto loop = mkILoop(std::make_tuple(opr,op1), std::make_tuple(ci4),
|
||||||
|
std::make_tuple(xx), std::make_tuple(opr.assign( op1.data()->mOp )),
|
||||||
|
//std::make_tuple(), std::make_tuple(),
|
||||||
|
std::array<size_t,1>({1}), std::array<size_t,1>({0}));
|
||||||
|
*/
|
||||||
|
//std::array<size_t,0>(), std::array<size_t,0>());
|
||||||
|
//!!!!
|
||||||
|
//mi->ifor(1, loop)();
|
||||||
|
|
||||||
|
//mi->ifor(1, opr.assign( op1.data()->mOp ))();
|
||||||
auto i2_1 = imap.at("i2_1");
|
auto i2_1 = imap.at("i2_1");
|
||||||
auto i2_2 = imap.at("i2_2");
|
auto i2_2 = imap.at("i2_2");
|
||||||
auto i3_1 = imap.at("i3_1");
|
auto i3_1 = imap.at("i3_1");
|
||||||
|
|
Loading…
Reference in a new issue