some corrections...
This commit is contained in:
parent
c349ff7bd0
commit
a8c62d0481
6 changed files with 105 additions and 54 deletions
|
@ -17,6 +17,8 @@
|
|||
#include "ranges/rheader.h"
|
||||
#include "pack_num.h"
|
||||
|
||||
#include "ranges/index_info.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
|
@ -54,7 +56,8 @@ namespace MultiArrayTools
|
|||
{
|
||||
public:
|
||||
|
||||
OperationTemplate(OperationClass* oc);
|
||||
OperationClass& THIS() { return static_cast<OperationClass&>(*this); }
|
||||
const OperationClass& THIS() const { return static_cast<OperationClass const&>(*this); }
|
||||
|
||||
template <class Second>
|
||||
auto operator+(const Second& in) const
|
||||
|
@ -77,7 +80,8 @@ namespace MultiArrayTools
|
|||
-> Contraction<T,OperationClass,IndexType>;
|
||||
|
||||
private:
|
||||
OperationClass* mOc;
|
||||
friend OperationClass;
|
||||
OperationTemplate() = default;
|
||||
};
|
||||
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
|
@ -105,10 +109,12 @@ namespace MultiArrayTools
|
|||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<IndexType> mkIndex(std::shared_ptr<typename CRange::IndexType>& index);
|
||||
void performAssignment(std::intptr_t blockIndexNum);
|
||||
OpClass const& mSecond;
|
||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
IndexInfo mIInfo;
|
||||
mutable MBlock<T> mBlock;
|
||||
};
|
||||
|
||||
|
@ -135,8 +141,13 @@ namespace MultiArrayTools
|
|||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<IndexType>
|
||||
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
MultiArrayBase<T,Ranges...> const& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
IndexInfo mIInfo;
|
||||
mutable Block<T> mBlock;
|
||||
};
|
||||
|
||||
|
@ -168,8 +179,13 @@ namespace MultiArrayTools
|
|||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<IndexType>
|
||||
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
IndexInfo mIInfo;
|
||||
mutable MBlock<T> mBlock;
|
||||
std::shared_ptr<VIWB> mBlockIndex; // predefine to save time
|
||||
};
|
||||
|
@ -193,7 +209,7 @@ namespace MultiArrayTools
|
|||
const Operation& block() const;
|
||||
|
||||
protected:
|
||||
std::tuple<Ops...> mOps;
|
||||
std::tuple<Ops const&...> mOps;
|
||||
mutable BlockResult<T> mRes;
|
||||
};
|
||||
|
||||
|
@ -214,7 +230,7 @@ namespace MultiArrayTools
|
|||
|
||||
protected:
|
||||
|
||||
Op mOp;
|
||||
const Op& mOp;
|
||||
std::shared_ptr<IndexType> mInd;
|
||||
mutable BlockResult<T> mRes;
|
||||
};
|
||||
|
@ -267,15 +283,12 @@ namespace MultiArrayTools
|
|||
* OperationTemplate *
|
||||
***************************/
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
OperationTemplate<T,OperationClass>::OperationTemplate(OperationClass* oc) : mOc(oc) {}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
template <class Second>
|
||||
auto OperationTemplate<T,OperationClass>::operator+(const Second& in) const
|
||||
-> Operation<T,std::plus<T>,OperationClass,Second>
|
||||
{
|
||||
return Operation<T,std::plus<T>,OperationClass,Second>(*mOc, in);
|
||||
return Operation<T,std::plus<T>,OperationClass,Second>(THIS(), in);
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
|
@ -283,7 +296,7 @@ namespace MultiArrayTools
|
|||
auto OperationTemplate<T,OperationClass>::operator-(const Second& in) const
|
||||
-> Operation<T,std::minus<T>,OperationClass,Second>
|
||||
{
|
||||
return Operation<T,std::minus<T>,OperationClass,Second>(*mOc, in);
|
||||
return Operation<T,std::minus<T>,OperationClass,Second>(THIS(), in);
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
|
@ -291,7 +304,7 @@ namespace MultiArrayTools
|
|||
auto OperationTemplate<T,OperationClass>::operator*(const Second& in) const
|
||||
-> Operation<T,std::multiplies<T>,OperationClass,Second>
|
||||
{
|
||||
return Operation<T,std::multiplies<T>,OperationClass,Second>(*mOc, in);
|
||||
return Operation<T,std::multiplies<T>,OperationClass,Second>(THIS(), in);
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
|
@ -299,7 +312,7 @@ namespace MultiArrayTools
|
|||
auto OperationTemplate<T,OperationClass>::operator/(const Second& in) const
|
||||
-> Operation<T,std::divides<T>,OperationClass,Second>
|
||||
{
|
||||
return Operation<T,std::divides<T>,OperationClass,Second>(*mOc, in);
|
||||
return Operation<T,std::divides<T>,OperationClass,Second>(THIS(), in);
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
|
@ -307,7 +320,7 @@ namespace MultiArrayTools
|
|||
auto OperationTemplate<T,OperationClass>::c(std::shared_ptr<IndexType>& ind) const
|
||||
-> Contraction<T,OperationClass,IndexType>
|
||||
{
|
||||
return Contraction<T,OperationClass,IndexType>(*mOc, ind);
|
||||
return Contraction<T,OperationClass,IndexType>(THIS(), ind);
|
||||
}
|
||||
|
||||
|
||||
|
@ -319,14 +332,8 @@ namespace MultiArrayTools
|
|||
OperationMaster<T,OpClass,Ranges...>::
|
||||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
|
||||
std::shared_ptr<typename CRange::IndexType>& index) :
|
||||
mSecond(second), mArrayRef(ma), mIndex()
|
||||
mSecond(second), mArrayRef(ma), mIndex(mkIndex(index)), mIInfo(*mIndex)
|
||||
{
|
||||
MultiRangeFactory<Ranges...> mrf( index->range() );
|
||||
std::shared_ptr<MultiRange<Ranges...> > mr =
|
||||
std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
||||
mIndex = std::make_shared<IndexType>( mr->begin() );
|
||||
(*mIndex) = *index;
|
||||
|
||||
auto blockIndex = seekBlockIndex( make_viwb( mIndex ), second);
|
||||
std::intptr_t blockIndexNum = blockIndex->getPtrNum();
|
||||
|
||||
|
@ -341,14 +348,8 @@ namespace MultiArrayTools
|
|||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
|
||||
std::shared_ptr<typename CRange::IndexType>& index,
|
||||
std::shared_ptr<VIWB> blockIndex) :
|
||||
mSecond(second), mArrayRef(ma), mIndex()
|
||||
mSecond(second), mArrayRef(ma), mIndex(mkIndex(index)), mIInfo(*mIndex)
|
||||
{
|
||||
MultiRangeFactory<Ranges...> mrf( index->range() );
|
||||
std::shared_ptr<MultiRange<Ranges...> > mr =
|
||||
std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
||||
mIndex = std::make_shared<IndexType>( mr->begin() );
|
||||
(*mIndex) = *index;
|
||||
|
||||
std::intptr_t blockIndexNum = blockIndex->getPtrNum();
|
||||
second.block(blockIndex, true);
|
||||
|
||||
|
@ -356,6 +357,19 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
std::shared_ptr<typename OperationMaster<T,OpClass,Ranges...>::IndexType>
|
||||
OperationMaster<T,OpClass,Ranges...>::
|
||||
mkIndex(std::shared_ptr<typename CRange::IndexType>& index)
|
||||
{
|
||||
MultiRangeFactory<Ranges...> mrf( index->range() );
|
||||
std::shared_ptr<MultiRange<Ranges...> > mr =
|
||||
std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
||||
auto i = std::make_shared<IndexType>( mr->begin() );
|
||||
(*i) = *index;
|
||||
return i;
|
||||
}
|
||||
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
void OperationMaster<T,OpClass,Ranges...>::performAssignment(std::intptr_t blockIndexNum)
|
||||
{
|
||||
|
@ -412,10 +426,19 @@ namespace MultiArrayTools
|
|||
ConstOperationRoot<T,Ranges...>::
|
||||
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||
OperationTemplate<T,ConstOperationRoot<T,Ranges...> >(this),
|
||||
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
|
||||
//OperationTemplate<T,ConstOperationRoot<T,Ranges...> >(this),
|
||||
mArrayRef(ma), mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex)
|
||||
{}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
std::shared_ptr<typename ConstOperationRoot<T,Ranges...>::IndexType>
|
||||
ConstOperationRoot<T,Ranges...>::
|
||||
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices)
|
||||
{
|
||||
auto i = std::make_shared<IndexType>( ma.range() );
|
||||
(*mIndex)(indices...);
|
||||
return i;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
|
@ -450,11 +473,20 @@ namespace MultiArrayTools
|
|||
OperationRoot<T,Ranges...>::
|
||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||
OperationTemplate<T,OperationRoot<T,Ranges...> >(this),
|
||||
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) ),
|
||||
//OperationTemplate<T,OperationRoot<T,Ranges...> >(this),
|
||||
mArrayRef(ma), mIndex( mkIndex( ma, indices... ) ), mIInfo(*mIndex),
|
||||
mBlockIndex(nullptr)
|
||||
{}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
std::shared_ptr<typename OperationRoot<T,Ranges...>::IndexType>
|
||||
OperationRoot<T,Ranges...>::
|
||||
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices)
|
||||
{
|
||||
auto i = std::make_shared<IndexType>( ma.range() );
|
||||
(*mIndex)(indices...);
|
||||
return i;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
|
@ -514,7 +546,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
Operation<T,OpFunction,Ops...>::Operation(const Ops&... ops) :
|
||||
OperationTemplate<T,Operation<T,OpFunction,Ops...> >(this),
|
||||
//OperationTemplate<T,Operation<T,OpFunction,Ops...> >(this),
|
||||
mOps(ops...) {}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
|
@ -548,7 +580,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class Op, class IndexType>
|
||||
Contraction<T,Op,IndexType>::Contraction(const Op& op, std::shared_ptr<IndexType> ind) :
|
||||
OperationTemplate<T,Contraction<T,Op,IndexType> >(this),
|
||||
//OperationTemplate<T,Contraction<T,Op,IndexType> >(this),
|
||||
mOp(op),
|
||||
mInd(ind) {}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ namespace MultiArrayTools
|
|||
|
||||
void seekIndexInst(std::shared_ptr<VIWB> i, std::vector<std::shared_ptr<VIWB> >& ivec);
|
||||
|
||||
//void seekIndexInst(const IndexInfo& i, std::vector<IndexInfo>& ivec);
|
||||
|
||||
BTSS getBlockType(std::shared_ptr<VIWB> i,
|
||||
std::shared_ptr<VIWB> j,
|
||||
bool first, size_t higherStepSize = 1);
|
||||
|
|
|
@ -337,8 +337,9 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
std::vector<IndexInfo> ContainerIndex<Indices...>::infoVec() const
|
||||
{
|
||||
std::vector<IndexInfo> out(sizeof...(Indices));
|
||||
RPackNum<sizeof...(Indices)-1>::buildInfoVec(out, mIPack);
|
||||
std::vector<IndexInfo> out;
|
||||
out.reserve(sizeof...(Indices));
|
||||
RPackNum<sizeof...(Indices)-1>::buildInfoVec(out, mIPack, mBlockSizes);
|
||||
return std::move( out );
|
||||
}
|
||||
|
||||
|
|
|
@ -20,13 +20,15 @@ namespace MultiArrayTools
|
|||
|
||||
IndexInfo(IndexInfo&& in) = default;
|
||||
IndexInfo& operator=(IndexInfo&& in) = default;
|
||||
IndexInfo(const IndexInfo& in) = default;
|
||||
IndexInfo& operator=(const IndexInfo& in) = default;
|
||||
|
||||
//IndexInfo(const IndexInfo& in) = default;
|
||||
//IndexInfo& operator=(const IndexInfo& in) = default;
|
||||
|
||||
template <class IndexClass>
|
||||
IndexInfo(const IndexClass& ind, size_t stepSize = 1);
|
||||
|
||||
template <class IndexClass>
|
||||
IndexInfo& reassign(const IndexClass& ind, size_t stepSize = 1);
|
||||
|
||||
bool operator==(const IndexInfo& in) const;
|
||||
bool operator!=(const IndexInfo& in) const;
|
||||
|
||||
|
@ -65,6 +67,15 @@ namespace MultiArrayTools
|
|||
mStepSize(stepSize)
|
||||
{}
|
||||
|
||||
template <class IndexClass>
|
||||
IndexInfo& IndexInfo::reassign(const IndexClass& ind, size_t stepSize)
|
||||
{
|
||||
IndexInfo ii(ind, stepSize);
|
||||
(*this) = std::move(ii);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
|
||||
#endif
|
||||
|
|
|
@ -381,8 +381,9 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
std::vector<IndexInfo> MultiIndex<Indices...>::infoVec() const
|
||||
{
|
||||
std::vector<IndexInfo> out(sizeof...(Indices));
|
||||
RPackNum<sizeof...(Indices)-1>::buildInfoVec(out, mIPack);
|
||||
std::vector<IndexInfo> out;
|
||||
out.reserve(sizeof...(Indices));
|
||||
RPackNum<sizeof...(Indices)-1>::buildInfoVec(out, mIPack, mBlockSizes);
|
||||
return std::move( out );
|
||||
}
|
||||
|
||||
|
|
|
@ -211,10 +211,12 @@ namespace MultiArrayHelper
|
|||
|
||||
template <class... Indices>
|
||||
static void buildInfoVec(std::vector<IndexInfo>& out,
|
||||
std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
const std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const std::array<size_t,sizeof...(Indices)+1>& bs)
|
||||
{
|
||||
out.emplace_back(*std::get<sizeof...(Indices)-N-1>(ip));
|
||||
RPackNum<N-1>::buildInfoVec(out, ip);
|
||||
static const size_t POS = sizeof...(Indices)-N-1;
|
||||
out.emplace_back(*std::get<POS>(ip), std::get<POS>(bs));
|
||||
RPackNum<N-1>::buildInfoVec(out, ip, bs);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -373,9 +375,11 @@ namespace MultiArrayHelper
|
|||
|
||||
template <class... Indices>
|
||||
static void buildInfoVec(std::vector<IndexInfo>& out,
|
||||
std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
const std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const std::array<size_t,sizeof...(Indices)+1>& bs)
|
||||
{
|
||||
out.emplace_back(*std::get<sizeof...(Indices)-1>(ip));
|
||||
static const size_t POS = sizeof...(Indices)-1;
|
||||
out.emplace_back(*std::get<POS>(ip), std::get<POS>(bs));
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue