'partial assignment' expression + allow slice -> anonymous for trivial cases
This commit is contained in:
parent
f70efbeb82
commit
d109475d96
4 changed files with 66 additions and 1 deletions
|
@ -137,6 +137,23 @@ namespace MultiArrayTools
|
|||
return mSec.rootSteps(iPtrNum);
|
||||
}
|
||||
|
||||
template <typename T, class Target, class OpClass>
|
||||
AssignmentExpr2<T,Target,OpClass>::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) :
|
||||
mTar(tar), mSec(sec), mDataPtr(dataPtr) {}
|
||||
|
||||
template <typename T, class Target, class OpClass>
|
||||
inline void AssignmentExpr2<T,Target,OpClass>::operator()(size_t start, ExtType last)
|
||||
{
|
||||
mDataPtr[last.val()] = mSec.get(last.next());
|
||||
}
|
||||
|
||||
template <typename T, class Target, class OpClass>
|
||||
typename AssignmentExpr2<T,Target,OpClass>::ExtType
|
||||
AssignmentExpr2<T,Target,OpClass>::rootSteps(std::intptr_t iPtrNum) const
|
||||
{
|
||||
return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) );
|
||||
}
|
||||
|
||||
template <typename T, class OpClass>
|
||||
AddExpr<T,OpClass>::AddExpr(T* dataPtr, const OpClass& sec) :
|
||||
mSec(sec), mDataPtr(dataPtr) {}
|
||||
|
@ -350,6 +367,18 @@ namespace MultiArrayTools
|
|||
return mIndex.ifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in)));
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
template <class OpClass, class Index>
|
||||
auto OperationRoot<T,Ranges...>::assign(const OpClass& in, const std::shared_ptr<Index>& i)
|
||||
-> decltype(i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
|
||||
(mOrigDataPtr,*this,in))))
|
||||
{
|
||||
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
|
||||
return i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
|
||||
(mOrigDataPtr,*this,in)));
|
||||
//return mIndex.ifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in)));
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
template <class OpClass>
|
||||
auto OperationRoot<T,Ranges...>::plus(const OpClass& in)
|
||||
|
|
|
@ -125,6 +125,31 @@ namespace MultiArrayTools
|
|||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||
};
|
||||
|
||||
template <typename T, class Target, class OpClass>
|
||||
class AssignmentExpr2
|
||||
{
|
||||
private:
|
||||
AssignmentExpr2() = default;
|
||||
|
||||
Target mTar;
|
||||
OpClass mSec;
|
||||
T* mDataPtr;
|
||||
|
||||
public:
|
||||
|
||||
static constexpr size_t LAYER = 0;
|
||||
static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE;
|
||||
typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType;
|
||||
|
||||
AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec);
|
||||
AssignmentExpr2(const AssignmentExpr2& in) = default;
|
||||
AssignmentExpr2(AssignmentExpr2&& in) = default;
|
||||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void operator()(size_t start, ExtType last);
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||
};
|
||||
|
||||
template <typename T, class OpClass>
|
||||
class AddExpr
|
||||
{
|
||||
|
@ -290,6 +315,11 @@ namespace MultiArrayTools
|
|||
auto assign(const OpClass& in)
|
||||
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in))));
|
||||
|
||||
template <class OpClass, class Index>
|
||||
auto assign(const OpClass& in, const std::shared_ptr<Index>& i)
|
||||
-> decltype(i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
|
||||
template <class OpClass>
|
||||
auto plus(const OpClass& in)
|
||||
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OpClass>(mOrigDataPtr,in))));
|
||||
|
|
|
@ -535,6 +535,7 @@ namespace MultiArrayTools
|
|||
format(const std::array<size_t,sizeof...(Indices)+1>& blocks)
|
||||
{
|
||||
mBlockSizes = blocks;
|
||||
mNonTrivialBlocks = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,12 @@ namespace MultiArrayTools
|
|||
template <typename T, class... SRanges>
|
||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > ConstSlice<T,SRanges...>::anonymous(bool slice) const
|
||||
{
|
||||
assert(0); // think about carefully!!!!
|
||||
assert(slice);
|
||||
assert(not MAB::mProtoI->sliceMode()); // only originally ordered slices!
|
||||
AnonymousRangeFactory arf(MAB::mRange->space());
|
||||
return std::make_shared<ConstSlice<T,AnonymousRange> >
|
||||
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
|
||||
data() );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue