RArray rop() -> operator() + call local operation in case of assignment for roproot
This commit is contained in:
parent
127577e422
commit
9b0286929e
5 changed files with 36 additions and 19 deletions
|
@ -356,27 +356,29 @@ namespace CNORXZ
|
|||
|
||||
template <typename T>
|
||||
template <class Index>
|
||||
OpRoot<T,Index> RArray<T>::rop(const Sptr<Index>& i)
|
||||
OpRoot<T,Index> RArray<T>::operator()(const Sptr<Index>& i)
|
||||
//OpRoot<T,Index> RArray<T>::rop(const Sptr<Index>& i)
|
||||
{
|
||||
return (*mB)(i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class... Indices>
|
||||
inline decltype(auto) RArray<T>::rop(const SPack<Indices...>& pack)
|
||||
inline decltype(auto) RArray<T>::operator()(const SPack<Indices...>& pack)
|
||||
//inline decltype(auto) RArray<T>::rop(const SPack<Indices...>& pack)
|
||||
{
|
||||
typedef typename std::remove_reference<decltype(*pack[CSizeT<0>{}])>::type I0;
|
||||
if constexpr(is_rank_index<I0>::value){
|
||||
// preliminary:
|
||||
CXZ_ASSERT(mB->formatIsTrivial(),
|
||||
"array has non-trivial format, rank operations require trivial format");
|
||||
/*
|
||||
|
||||
auto ri = pack[CSizeT<0>{}];
|
||||
auto li = iter<1,sizeof...(Indices)>
|
||||
( [&](auto i) { return pack[CSizeT<i>{}]; },
|
||||
[](const auto&... x) { return mindexPtr( (x * ...) ); } );
|
||||
*/
|
||||
return oproot(*mB, mindexPtr(pack));
|
||||
return roproot(*this, ri, li);
|
||||
//return oproot(*mB, mindexPtr(pack));
|
||||
}
|
||||
else {
|
||||
return (*mB)(pack);
|
||||
|
@ -384,7 +386,8 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
inline decltype(auto) RArray<T>::rop(const DPack& pack)
|
||||
inline decltype(auto) RArray<T>::operator()(const DPack& pack)
|
||||
//inline decltype(auto) RArray<T>::rop(const DPack& pack)
|
||||
{
|
||||
return (*mB)(pack);
|
||||
}
|
||||
|
|
|
@ -221,14 +221,17 @@ namespace CNORXZ
|
|||
|
||||
/** @copydoc ArrayBase::operator() */
|
||||
template <class Index>
|
||||
OpRoot<T,Index> rop(const Sptr<Index>& i);
|
||||
OpRoot<T,Index> operator()(const Sptr<Index>& i);
|
||||
//OpRoot<T,Index> rop(const Sptr<Index>& i);
|
||||
|
||||
/** @copydoc ArrayBase::operator() */
|
||||
template <class... Indices>
|
||||
inline decltype(auto) rop(const SPack<Indices...>& pack);
|
||||
inline decltype(auto) operator()(const SPack<Indices...>& pack);
|
||||
//inline decltype(auto) rop(const SPack<Indices...>& pack);
|
||||
|
||||
/** @copydoc ArrayBase::operator() */
|
||||
inline decltype(auto) rop(const DPack& pack);
|
||||
inline decltype(auto) operator()(const DPack& pack);
|
||||
//inline decltype(auto) rop(const DPack& pack);
|
||||
|
||||
/** @copydoc ArrayBase::data() */
|
||||
T* data();
|
||||
|
|
|
@ -56,18 +56,24 @@ namespace CNORXZ
|
|||
template <typename T, class RIndexT, class IndexT>
|
||||
constexpr ROpRoot<T,RIndexT,IndexT>::ROpRoot(RArray<T>& a, const Sptr<RIndexT>& ri,
|
||||
const Sptr<IndexT>& li) :
|
||||
mData(a.data()),
|
||||
mLocal(&a.local()),
|
||||
mData(a.buffermap().data()),
|
||||
//mData(a.data()),
|
||||
mRIndex(ri),
|
||||
mIndex(li)
|
||||
{
|
||||
CXZ_ERROR("nope");
|
||||
//CXZ_ERROR("nope");
|
||||
CXZ_ASSERT(a.buffermap().size() == ri->lmax().val(),
|
||||
"data map not properly initialized: map size = " << a.buffermap().size()
|
||||
<< ", rank index range size = " << ri->lmax().val());
|
||||
}
|
||||
|
||||
template <typename T, class RIndexT, class IndexT>
|
||||
template <class Op>
|
||||
constexpr ROpRoot<T,RIndexT,IndexT>& ROpRoot<T,RIndexT,IndexT>::operator=(const Op& in)
|
||||
{
|
||||
OI::a(mIndex, [](auto& a, const auto& b) { a = b; }, in);
|
||||
(*mLocal)(mindexPtr(mRIndex->local()*mIndex)) = in;
|
||||
//OI::a(mIndex, [](auto& a, const auto& b) { a = b; }, in);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -75,14 +81,16 @@ namespace CNORXZ
|
|||
template <class Op>
|
||||
constexpr ROpRoot<T,RIndexT,IndexT>& ROpRoot<T,RIndexT,IndexT>::operator+=(const Op& in)
|
||||
{
|
||||
OI::a(mIndex, [](auto& a, const auto& b) { a += b; }, in);
|
||||
(*mLocal)(mindexPtr(mRIndex->local()*mIndex)) += in;
|
||||
//OI::a(mIndex, [](auto& a, const auto& b) { a += b; }, in);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class RIndexT, class IndexT>
|
||||
constexpr ROpRoot<T,RIndexT,IndexT>& ROpRoot<T,RIndexT,IndexT>::operator=(const ROpRoot& in)
|
||||
{
|
||||
OI::a(mIndex, [](auto& a, const auto& b) { a = b; }, in);
|
||||
(*mLocal)(mindexPtr(mRIndex->local()*mIndex)) = in;
|
||||
//OI::a(mIndex, [](auto& a, const auto& b) { a = b; }, in);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -90,20 +98,20 @@ namespace CNORXZ
|
|||
template <class PosT>
|
||||
constexpr decltype(auto) ROpRoot<T,RIndexT,IndexT>::operator()(const PosT& pos) const
|
||||
{
|
||||
return mData[pos.val()];
|
||||
return (mData[pos.val()])[pos.next().val()];
|
||||
}
|
||||
|
||||
template <typename T, class RIndexT, class IndexT>
|
||||
constexpr decltype(auto) ROpRoot<T,RIndexT,IndexT>::operator()() const
|
||||
{
|
||||
return mData[0];
|
||||
return (mData[0])[0];
|
||||
}
|
||||
|
||||
template <typename T, class RIndexT, class IndexT>
|
||||
template <SizeT I>
|
||||
constexpr decltype(auto) ROpRoot<T,RIndexT,IndexT>::rootSteps(const IndexId<I>& id) const
|
||||
{
|
||||
return mIndex->stepSize(id);
|
||||
return mRIndex->stepSize(id) << mIndex->stepSize(id);
|
||||
}
|
||||
|
||||
template <typename T, class RIndexT, class IndexT>
|
||||
|
|
|
@ -76,7 +76,8 @@ namespace CNORXZ
|
|||
|
||||
private:
|
||||
|
||||
T* mData;
|
||||
ArrayBase<T>* mLocal;
|
||||
const T* const* mData;
|
||||
Sptr<RIndexT> mRIndex;
|
||||
Sptr<IndexT> mIndex;
|
||||
};
|
||||
|
|
|
@ -133,8 +133,10 @@ namespace
|
|||
for(const auto& r: *imap1){
|
||||
req[r] = true;
|
||||
}
|
||||
res.load(x, AB, req); // DUMMY, not used...
|
||||
mM1.load(xp, AB, req);
|
||||
res.rop(x*A*B) = mapXpr(xp,x,imap1, mM1(xp*A*B) - mM1(x*A*B) );
|
||||
//res.rop(x*A*B) = mapXpr(xp,x,imap1, mM1(xp*A*B) - mM1(x*A*B) );
|
||||
res(x*A*B) = mapXpr(xp,x,imap1, mM1(xp*A*B) - mM1(x*A*B) );
|
||||
|
||||
for(SizeT x0 = 0; x0 != T; ++x0) {
|
||||
for(SizeT x1 = 0; x1 != L; ++x1)
|
||||
|
|
Loading…
Reference in a new issue