some fixes

This commit is contained in:
Christian Zimmermann 2020-09-16 00:09:55 +02:00
parent 5d853473de
commit 863dd09b40
4 changed files with 57 additions and 21 deletions

View file

@ -69,7 +69,7 @@ namespace MultiArrayTools
} }
template <class ROP> template <class ROP>
const ROP* HighLevelOpRoot<ROP>::get() const ROP* HighLevelOpRoot<ROP>::get()
{ {
return &mOp; return &mOp;
} }
@ -100,6 +100,7 @@ namespace MultiArrayTools
auto op = *dop.op.data()->mOp; auto op = *dop.op.data()->mOp;
typedef decltype(op) OP; typedef decltype(op) OP;
res.appendOuter(dop); res.appendOuter(dop);
assert(dop.op.init());
Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M> Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M>
(res, in, inds..., op, ops..., dop, dops...); (res, in, inds..., op, ops..., dop, dops...);
} }
@ -137,6 +138,7 @@ namespace MultiArrayTools
auto op = *dop.op.data()->mOp; auto op = *dop.op.data()->mOp;
res.appendOuter(dop); res.appendOuter(dop);
res.op = mkDynOutOp(mkFOp<OpF>(op,ops...), inds...); res.op = mkDynOutOp(mkFOp<OpF>(op,ops...), inds...);
assert(dop.op.init());
res.appendOuterM(dop.op,dops.op...); res.appendOuterM(dop.op,dops.op...);
} }
else { else {
@ -160,7 +162,7 @@ namespace MultiArrayTools
} }
template <class ROP, class OpF, size_t N> template <class ROP, class OpF, size_t N>
const ROP* HighLevelOp<ROP,OpF,N>::get() const ROP* HighLevelOp<ROP,OpF,N>::get()
{ {
assert(0); assert(0);
return nullptr; return nullptr;
@ -174,6 +176,8 @@ namespace MultiArrayTools
typename B::template RetT<Inds...> res; typename B::template RetT<Inds...> res;
Create<N-1>::template cx<Inds...>::template ccx<ROP,OpF>::template cccx<N> Create<N-1>::template cx<Inds...>::template ccx<ROP,OpF>::template cccx<N>
(res,mIn,inds...); (res,mIn,inds...);
// assert(res.op.init());
//assert(res.outer.init());
return res; return res;
} }
@ -195,7 +199,7 @@ namespace MultiArrayTools
} }
template <class ROP> template <class ROP>
auto HighLevelOpHolder<ROP>::get() const auto HighLevelOpHolder<ROP>::get()
-> decltype(mOp->get()) -> decltype(mOp->get())
{ {
return mOp->get(); return mOp->get();
@ -255,7 +259,7 @@ namespace MultiArrayTools
const std::shared_ptr<Indices>&... is) const std::shared_ptr<Indices>&... is)
{ {
const size_t dim = di->dim(); const size_t dim = di->dim();
if(dim >= 2){ if(dim > 2){
auto ci1 = di->getP(dim-2)->reduced(); auto ci1 = di->getP(dim-2)->reduced();
auto ci2 = di->getP(dim-1)->reduced(); auto ci2 = di->getP(dim-1)->reduced();
//auto ci1 = std::dynamic_pointer_cast<IndexWrapper<CI>>(di->getP(dim-2)); //auto ci1 = std::dynamic_pointer_cast<IndexWrapper<CI>>(di->getP(dim-2));
@ -268,9 +272,9 @@ namespace MultiArrayTools
this->assign(in, mi, ci1, ci2); this->assign(in, mi, ci1, ci2);
} }
else { else {
assert(dim == 1); assert(dim == 2 or dim == 1);
//auto ci1 = std::dynamic_pointer_cast<IndexWrapper<CI>>(di->getP(dim-2)); //auto ci1 = std::dynamic_pointer_cast<IndexWrapper<CI>>(di->getP(dim-2));
auto ci1 = di->getP(dim-2)->reduced(); auto ci1 = di->getP(dim-1)->reduced();
assert(ci1 != nullptr); assert(ci1 != nullptr);
auto odi = mkSubSpaceX(di, dim-1); auto odi = mkSubSpaceX(di, dim-1);
auto mi = mkMIndex(is..., odi); auto mi = mkMIndex(is..., odi);
@ -303,12 +307,25 @@ namespace MultiArrayTools
{ {
//VCHECK(printInd(inds...)); //VCHECK(printInd(inds...));
auto xx = mkArrayPtr<double>(nullr()); auto xx = mkArrayPtr<double>(nullr());
auto& opr = *mOp->get(); ROP& opr = *mOp->get();
if(in.root()){
auto inx = in;
opr.par() = *inx.get();
return *this;
}
auto loop = mkPILoop auto loop = mkPILoop
( [&opr,&in,&xx,&inds...,this](){ ( [&opr,&in,&xx,&inds...,this](){
auto inx = in; auto inx = in;
auto dop = inx.create(inds...); auto dop = inx.create(inds...);
auto gexp = mkDynOp1<size_t>(mkMOp<size_t>(dop.outer,dop.op)); DynamicO<size_t> gexp;
//VCHECK(dop.outer.init());
//VCHECK(dop.op.init());
if(dop.outer.init()){
gexp = mkDynOp1<size_t>(mkMOp<size_t>(dop.outer,dop.op));
}
else {
gexp = mkDynOp1<size_t>(mkMOp<size_t>(dop.op));
}
auto xloop = mkILoop(std::make_tuple(*dop.op.data()->mOp), auto xloop = mkILoop(std::make_tuple(*dop.op.data()->mOp),
std::make_tuple(inds...), std::make_tuple(inds...),
std::make_tuple(xx), std::make_tuple(xx),
@ -327,12 +344,23 @@ namespace MultiArrayTools
const std::shared_ptr<Indices>&... inds) const std::shared_ptr<Indices>&... inds)
{ {
auto xx = mkArrayPtr<double>(nullr()); auto xx = mkArrayPtr<double>(nullr());
auto& opr = *mOp->get(); ROP& opr = *mOp->get();
if(in.root()){
auto inx = in;
opr.par() += *inx.get();
return *this;
}
auto loop = mkPILoop auto loop = mkPILoop
( [&opr,&in,&xx,&inds...,this](){ ( [&opr,&in,&xx,&inds...,this](){
auto inx = in; auto inx = in;
auto dop = inx.create(inds...); auto dop = inx.create(inds...);
auto gexp = mkDynOp1<size_t>(mkMOp<size_t>(dop.outer,dop.op)); DynamicO<size_t> gexp;
if(dop.outer.init()){
gexp = mkDynOp1<size_t>(mkMOp<size_t>(dop.outer,dop.op));
}
else {
gexp = mkDynOp1<size_t>(mkMOp<size_t>(dop.op));
}
auto xloop = mkILoop(std::make_tuple(*dop.op.data()->mOp), auto xloop = mkILoop(std::make_tuple(*dop.op.data()->mOp),
std::make_tuple(inds...), std::make_tuple(inds...),
std::make_tuple(xx), std::make_tuple(xx),

View file

@ -53,7 +53,7 @@ namespace MultiArrayTools
#undef reg_ind2 #undef reg_ind2
#undef reg_ind3 #undef reg_ind3
virtual const ROP* get() const = 0; virtual ROP* get() = 0;
}; };
@ -85,7 +85,7 @@ namespace MultiArrayTools
#include "hl_reg_ind.h" #include "hl_reg_ind.h"
virtual const ROP* get() const override final; virtual ROP* get() override final;
}; };
@ -116,7 +116,7 @@ namespace MultiArrayTools
virtual bool root() const override final; virtual bool root() const override final;
virtual const ROP* get() const override final; virtual ROP* get() override final;
#include "hl_reg_ind.h" #include "hl_reg_ind.h"
@ -147,7 +147,7 @@ namespace MultiArrayTools
auto create(const std::shared_ptr<Inds>&... inds) const auto create(const std::shared_ptr<Inds>&... inds) const
-> decltype(mOp->create(inds...)); -> decltype(mOp->create(inds...));
auto get() const -> decltype(mOp->get()); auto get() -> decltype(mOp->get());
std::shared_ptr<HighLevelOpBase<ROP>> op() const; std::shared_ptr<HighLevelOpBase<ROP>> op() const;
HighLevelOpHolder operator*(const HighLevelOpHolder& in) const; HighLevelOpHolder operator*(const HighLevelOpHolder& in) const;

View file

@ -99,7 +99,10 @@ namespace MultiArrayTools
template <class Expr> template <class Expr>
DynamicExpression DynamicIndex::ifor(size_t step, Expr ex) const DynamicExpression DynamicIndex::ifor(size_t step, Expr ex) const
{ {
if(mIVec.size() == 1){ if(mIVec.size() == 0){
return ex;
}
else if(mIVec.size() == 1){
return mIVec.back().first->ifor(step,ex); return mIVec.back().first->ifor(step,ex);
} }
else { else {
@ -112,7 +115,10 @@ namespace MultiArrayTools
template <class Expr> template <class Expr>
DynamicExpression DynamicIndex::iforh(size_t step, Expr ex) const DynamicExpression DynamicIndex::iforh(size_t step, Expr ex) const
{ {
if(mIVec.size() == 1){ if(mIVec.size() == 0){
return ex;
}
else if(mIVec.size() == 1){
return mIVec.back().first->iforh(step,ex); return mIVec.back().first->iforh(step,ex);
} }
else { else {

View file

@ -79,12 +79,14 @@ namespace MultiArrayTools
IndexInterface<DynamicIndex,MetaType>(range, 0), IndexInterface<DynamicIndex,MetaType>(range, 0),
mIVec(range->dim()) mIVec(range->dim())
{ {
size_t xx = 1; if(mIVec.size() > 0){
for(size_t i = mIVec.size()-1; i != 0; --i){ size_t xx = 1;
mIVec[i].second = xx; for(size_t i = mIVec.size()-1; i != 0; --i){
xx *= range->sub(i)->size(); mIVec[i].second = xx;
xx *= range->sub(i)->size();
}
mIVec[0].second = xx;
} }
mIVec[0].second = xx;
} }