almost remove index_info dependency -> performance lack down to factor 1.15
This commit is contained in:
parent
219a267995
commit
b045b2d7e1
7 changed files with 109 additions and 28 deletions
|
@ -117,7 +117,7 @@ namespace MultiArrayTools
|
||||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||||
T* mDataPtr;
|
T* mDataPtr;
|
||||||
IndexType mIndex;
|
IndexType mIndex;
|
||||||
IndexInfo mIInfo;
|
//IndexInfo mIInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ namespace MultiArrayTools
|
||||||
const T* mDataPtr;
|
const T* mDataPtr;
|
||||||
//std::shared_ptr<IndexType> mIndex;
|
//std::shared_ptr<IndexType> mIndex;
|
||||||
IndexType mIndex;
|
IndexType mIndex;
|
||||||
IndexInfo mIInfo;
|
//IndexInfo mIInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
|
@ -187,7 +187,7 @@ namespace MultiArrayTools
|
||||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||||
T* mDataPtr;
|
T* mDataPtr;
|
||||||
IndexType mIndex;
|
IndexType mIndex;
|
||||||
IndexInfo mIInfo;
|
//IndexInfo mIInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Op>
|
template <class Op>
|
||||||
|
@ -383,7 +383,7 @@ namespace MultiArrayTools
|
||||||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
|
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
|
||||||
IndexType& index) :
|
IndexType& index) :
|
||||||
mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
|
mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
|
||||||
mIndex(index), mIInfo(mIndex)
|
mIndex(index)
|
||||||
{
|
{
|
||||||
performAssignment(0);
|
performAssignment(0);
|
||||||
}
|
}
|
||||||
|
@ -394,7 +394,7 @@ namespace MultiArrayTools
|
||||||
IndexType& index,
|
IndexType& index,
|
||||||
const IndexInfo* blockIndex) :
|
const IndexInfo* blockIndex) :
|
||||||
mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
|
mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
|
||||||
mIndex(index), mIInfo(mIndex)
|
mIndex(index)
|
||||||
{
|
{
|
||||||
performAssignment(0);
|
performAssignment(0);
|
||||||
}
|
}
|
||||||
|
@ -424,8 +424,8 @@ namespace MultiArrayTools
|
||||||
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
|
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
|
||||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||||
mArrayRef(ma), mDataPtr(mArrayRef.data()),
|
mArrayRef(ma), mDataPtr(mArrayRef.data()),
|
||||||
//mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex)
|
//mIndex( mkIndex(ma,indices...) ), mIInfo(mIndex)
|
||||||
mIndex( ma.begin() ), mIInfo(mIndex)
|
mIndex( ma.begin() )
|
||||||
{
|
{
|
||||||
mIndex(indices...);
|
mIndex(indices...);
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
MExt<void> ConstOperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
|
MExt<void> ConstOperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
|
||||||
{
|
{
|
||||||
return MExt<void>(getStepSize( mIndex.info(), iPtrNum ));
|
return MExt<void>(getStepSize( mIndex, iPtrNum ));
|
||||||
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
|
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +461,7 @@ namespace MultiArrayTools
|
||||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||||
mArrayRef(ma), mDataPtr(mArrayRef.data()),
|
mArrayRef(ma), mDataPtr(mArrayRef.data()),
|
||||||
mIndex( ma.begin() ), mIInfo(mIndex)
|
mIndex( ma.begin() )
|
||||||
{
|
{
|
||||||
mIndex(indices...);
|
mIndex(indices...);
|
||||||
}
|
}
|
||||||
|
@ -483,8 +483,8 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
MExt<void> OperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
|
MExt<void> OperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
|
||||||
{
|
{
|
||||||
return MExt<void>(getStepSize( mIndex.info(), iPtrNum ));
|
return MExt<void>(getStepSize( mIndex, iPtrNum ));
|
||||||
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
|
//return MExt<void>(getStepSize( mIndex.info(), iPtrNum ));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
|
|
|
@ -28,9 +28,9 @@ namespace MultiArrayTools
|
||||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||||
typedef ContainerRange<T,typename Indices::RangeType...> RangeType;
|
typedef ContainerRange<T,typename Indices::RangeType...> RangeType;
|
||||||
|
|
||||||
static IndexType sType() { return IndexType::CONT; }
|
static constexpr IndexType sType() { return IndexType::CONT; }
|
||||||
static size_t sDim() { return sizeof...(Indices); }
|
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||||
static size_t totalDim() { return mkTotalDim<Indices...>(); }
|
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
~IndexInterface() = default;
|
~IndexInterface() = default;
|
||||||
|
|
||||||
IndexType type() const { return THIS().type(); }
|
constexpr IndexType type() const { return THIS().type(); }
|
||||||
|
|
||||||
I& operator=(size_t pos) { return THIS() = pos; }
|
I& operator=(size_t pos) { return THIS() = pos; }
|
||||||
I& operator++() { return THIS()++; }
|
I& operator++() { return THIS()++; }
|
||||||
|
@ -78,11 +78,13 @@ namespace MultiArrayTools
|
||||||
auto iforh(const Expr ex) const -> decltype(THIS().template iforh<Expr>(ex))
|
auto iforh(const Expr ex) const -> decltype(THIS().template iforh<Expr>(ex))
|
||||||
{ return THIS().template iforh<Expr>(ex); }
|
{ return THIS().template iforh<Expr>(ex); }
|
||||||
|
|
||||||
|
std::intptr_t ptrNum() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend I;
|
friend I;
|
||||||
|
|
||||||
IndexInterface() { mId = indexId(); }
|
IndexInterface();
|
||||||
IndexInterface(const IndexInterface& in) = default;
|
IndexInterface(const IndexInterface& in) = default;
|
||||||
IndexInterface& operator=(const IndexInterface& in) = default;
|
IndexInterface& operator=(const IndexInterface& in) = default;
|
||||||
IndexInterface(IndexInterface&& in) = default;
|
IndexInterface(IndexInterface&& in) = default;
|
||||||
|
@ -91,11 +93,13 @@ namespace MultiArrayTools
|
||||||
IndexInterface(const std::shared_ptr<RangeBase>& range, size_t pos);
|
IndexInterface(const std::shared_ptr<RangeBase>& range, size_t pos);
|
||||||
|
|
||||||
std::shared_ptr<RangeBase> mRangePtr;
|
std::shared_ptr<RangeBase> mRangePtr;
|
||||||
size_t mPos;
|
size_t mPos = 0;
|
||||||
size_t mId;
|
size_t mId;
|
||||||
size_t mMax;
|
size_t mMax = 0;
|
||||||
|
|
||||||
|
std::intptr_t mPtrNum;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================= *
|
/* ========================= *
|
||||||
|
@ -108,6 +112,12 @@ namespace MultiArrayTools
|
||||||
* IndexInterface *
|
* IndexInterface *
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
template <class I, typename MetaType>
|
||||||
|
IndexInterface<I,MetaType>::IndexInterface() : mId(indexId())
|
||||||
|
{
|
||||||
|
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||||
|
}
|
||||||
|
|
||||||
template <class I, typename MetaType>
|
template <class I, typename MetaType>
|
||||||
IndexInterface<I,MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& range,
|
IndexInterface<I,MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& range,
|
||||||
size_t pos) : mRangePtr(range),
|
size_t pos) : mRangePtr(range),
|
||||||
|
@ -115,6 +125,7 @@ namespace MultiArrayTools
|
||||||
mMax(mRangePtr->size())
|
mMax(mRangePtr->size())
|
||||||
{
|
{
|
||||||
mId = indexId();
|
mId = indexId();
|
||||||
|
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class I, typename MetaType>
|
template <class I, typename MetaType>
|
||||||
|
@ -146,6 +157,12 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return pos();
|
return pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class I, typename MetaType>
|
||||||
|
std::intptr_t IndexInterface<I,MetaType>::ptrNum() const
|
||||||
|
{
|
||||||
|
return mPtrNum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -77,6 +77,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
std::vector<IndexInfo> getRootIndices(const IndexInfo& info);
|
std::vector<IndexInfo> getRootIndices(const IndexInfo& info);
|
||||||
|
|
||||||
|
/*
|
||||||
inline size_t getStepSize(const IndexInfo& ii, std::intptr_t j)
|
inline size_t getStepSize(const IndexInfo& ii, std::intptr_t j)
|
||||||
{
|
{
|
||||||
if(ii.type() == IndexType::SINGLE){
|
if(ii.type() == IndexType::SINGLE){
|
||||||
|
@ -91,12 +92,13 @@ namespace MultiArrayTools
|
||||||
const size_t tmp = getStepSize(itmp, j);
|
const size_t tmp = getStepSize(itmp, j);
|
||||||
ss += tmp * sx;
|
ss += tmp * sx;
|
||||||
sx *= max;
|
sx *= max;
|
||||||
|
VCHECK(ss);
|
||||||
}
|
}
|
||||||
return ss;
|
return ss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j);
|
//size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j);
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace MultiArrayTools
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,9 +32,9 @@ namespace MultiArrayTools
|
||||||
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
||||||
typedef MultiRange<typename Indices::RangeType...> RangeType;
|
typedef MultiRange<typename Indices::RangeType...> RangeType;
|
||||||
|
|
||||||
static IndexType sType() { return IndexType::MULTI; }
|
static constexpr IndexType sType() { return IndexType::MULTI; }
|
||||||
static size_t sDim() { return sizeof...(Indices); }
|
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||||
static size_t totalDim() { return mkTotalDim<Indices...>(); }
|
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,9 @@ namespace MultiArrayHelper
|
||||||
static constexpr size_t ISSTATIC = 1;
|
static constexpr size_t ISSTATIC = 1;
|
||||||
static constexpr size_t SIZE = 1;
|
static constexpr size_t SIZE = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
struct RPackNum
|
struct RPackNum
|
||||||
|
@ -249,6 +252,19 @@ namespace MultiArrayHelper
|
||||||
->iforh( RPackNum<N-1>::mkForh(ipack, exs) );
|
->iforh( RPackNum<N-1>::mkForh(ipack, exs) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
||||||
|
{
|
||||||
|
//constexpr size_t DIM = Index::sDim();
|
||||||
|
const auto& ni = ii.template get<N>();
|
||||||
|
const size_t max = ni.max();
|
||||||
|
const size_t tmp = getStepSize(ni, j);
|
||||||
|
//VCHECK(tmp);
|
||||||
|
ss += tmp * sx;
|
||||||
|
//VCHECK(ss);
|
||||||
|
sx *= max;
|
||||||
|
RPackNum<N-1>::getStepSizeX(ii, j, ss, sx);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -424,8 +440,53 @@ namespace MultiArrayHelper
|
||||||
return std::get<std::tuple_size<IndexPack>::value-1>(ipack)->iforh(exs);
|
return std::get<std::tuple_size<IndexPack>::value-1>(ipack)->iforh(exs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
||||||
|
{
|
||||||
|
//constexpr size_t DIM = Index::sDim();
|
||||||
|
const auto& ni = ii.template get<0>();
|
||||||
|
const size_t max = ni.max();
|
||||||
|
const size_t tmp = getStepSize(ni, j);
|
||||||
|
//VCHECK(tmp);
|
||||||
|
ss += tmp * sx;
|
||||||
|
//VCHECK(ss);
|
||||||
|
sx *= max;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <IndexType IT>
|
||||||
|
struct SSG
|
||||||
|
{
|
||||||
|
template <class Index>
|
||||||
|
static inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
||||||
|
{
|
||||||
|
size_t ss = 0;
|
||||||
|
size_t sx = 1;
|
||||||
|
constexpr size_t DIM = Index::sDim();
|
||||||
|
RPackNum<DIM-1>::getStepSizeX(ii, j, ss, sx);
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct SSG<IndexType::SINGLE>
|
||||||
|
{
|
||||||
|
template <class Index>
|
||||||
|
static inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
||||||
|
{
|
||||||
|
//VCHECK(ii.ptrNum());
|
||||||
|
//VCHECK(j);
|
||||||
|
return ii.ptrNum() == j ? 1 : 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
||||||
|
{
|
||||||
|
constexpr IndexType IT = Index::sType();
|
||||||
|
return SSG<IT>::getStepSize(ii, j);
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
} // end namespace MultiArrayHelper
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,10 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
|
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
|
||||||
|
|
||||||
static IndexType sType() { return IndexType::SINGLE; }
|
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
||||||
static size_t totalDim() { return 1; }
|
static constexpr size_t totalDim() { return 1; }
|
||||||
|
static constexpr size_t sDim() { return 1; }
|
||||||
|
|
||||||
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||||
|
|
||||||
IndexType type() const;
|
IndexType type() const;
|
||||||
|
|
Loading…
Reference in a new issue