im com (Operation: remove T?)

This commit is contained in:
Christian Zimmermann 2021-01-15 01:05:58 +01:00
parent 68ae7d8428
commit db92197048
4 changed files with 89 additions and 40 deletions

View file

@ -519,66 +519,91 @@ namespace MultiArrayTools
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class IOp, class OpClass>
auto OperationRoot<T,Ranges...>::assign(const OpClass& in) const auto OperationRoot<T,Ranges...>::asx(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET> -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)))) (mOrigDataPtr,*this,in))))
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET> return mIndex.ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))); (mOrigDataPtr,*this,in)));
} }
template <typename T, class... Ranges>
template <class IOp, class OpClass>
auto OperationRoot<T,Ranges...>::asxExpr(const OpClass& in) const
-> decltype(in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)))
{
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in));
}
template <typename T, class... Ranges>
template <class IOp, class OpClass, class Index>
auto OperationRoot<T,Ranges...>::asx(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))))
{
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return i->ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)));
}
template <typename T, class... Ranges>
template <class OpClass>
auto OperationRoot<T,Ranges...>::assign(const OpClass& in) const
-> decltype(this->template asx<IAssign>(in))
{
return this->template asx<IAssign>(in);
}
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto OperationRoot<T,Ranges...>::assignExpr(const OpClass& in) const auto OperationRoot<T,Ranges...>::assignExpr(const OpClass& in) const
-> decltype(in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(this->template asxExpr<IAssign>(in))
(mOrigDataPtr,*this,in)))
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); return this->template asxExpr<IAssign>(in);
return in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass, class Index> template <class OpClass, class Index>
auto OperationRoot<T,Ranges...>::assign(const OpClass& in, const std::shared_ptr<Index>& i) const auto OperationRoot<T,Ranges...>::assign(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(this->template asx<IAssign>(in,i))
(mOrigDataPtr,*this,in))))
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); return this->template asx<IAssign>(in,i);
return i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto OperationRoot<T,Ranges...>::plus(const OpClass& in) const auto OperationRoot<T,Ranges...>::plus(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET> -> decltype(this->template asx<IPlus>(in))
(mOrigDataPtr,*this,in))))
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); return this->template asx<IPlus>(in);
return mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass, class Index> template <class OpClass, class Index>
auto OperationRoot<T,Ranges...>::plus(const OpClass& in, const std::shared_ptr<Index>& i) const auto OperationRoot<T,Ranges...>::plus(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(this->template asx<IPlus>(in,i))
(mOrigDataPtr,*this,in))))
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); return this->template asx<IPlus>(in,i);
return i->ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::operator=(const OpClass& in) OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::operator=(const OpClass& in)
{ {
auto x = this->template asx<IVAssign<typename VType<T>::type>>(in);
const size_t inum = x.vec(VType<T>::MULT);
if(x.rootSteps(inum) == 1){
x();
}
else {
assign(in)(); assign(in)();
}
return *this; return *this;
} }
@ -613,7 +638,7 @@ namespace MultiArrayTools
template <typename V, class ET> template <typename V, class ET>
inline V& OperationRoot<T,Ranges...>::vget(ET pos) const inline V& OperationRoot<T,Ranges...>::vget(ET pos) const
{ {
return *(reinterpret_cast<const V*>(mDataPtr)+pos.val()); return *(reinterpret_cast<V*>(mDataPtr)+pos.val());
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>

View file

@ -538,29 +538,39 @@ namespace MultiArrayTools
OperationRoot(T* data, const IndexType& ind); OperationRoot(T* data, const IndexType& ind);
template <class IOp, class OpClass>
auto asx(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))));
template <class IOp, class OpClass>
auto asxExpr(const OpClass& in) const
-> decltype(in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)));
template <class IOp, class OpClass, class Index>
auto asx(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>
auto assign(const OpClass& in) const auto assign(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET> -> decltype(this->template asx<IAssign>(in));
(mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>
auto assignExpr(const OpClass& in) const auto assignExpr(const OpClass& in) const
-> decltype(in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in))); -> decltype(this->template asxExpr<IAssign>(in));
template <class OpClass, class Index> template <class OpClass, class Index>
auto assign(const OpClass& in, const std::shared_ptr<Index>& i) const auto assign(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(this->template asx<IAssign>(in,i));
(mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>
auto plus(const OpClass& in) const auto plus(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET> -> decltype(this->template asx<IPlus>(in));
(mOrigDataPtr,*this,in))));
template <class OpClass, class Index> template <class OpClass, class Index>
auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(this->template asx<IPlus>(in,i));
(mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>
OperationRoot& operator=(const OpClass& in); OperationRoot& operator=(const OpClass& in);

View file

@ -88,7 +88,7 @@ namespace MultiArrayHelper
static_assert(LAST >= NextOpType::SIZE, "inconsistent array positions"); static_assert(LAST >= NextOpType::SIZE, "inconsistent array positions");
static constexpr size_t NEXT = LAST - NextOpType::SIZE; static constexpr size_t NEXT = LAST - NextOpType::SIZE;
typedef decltype(std::get<N>(ops).template vget<V>(Getter<NEXT>::template getX<ETuple>( pos ))) ArgT; typedef decltype(std::get<N>(ops).template vget<V>(Getter<NEXT>::template getX<ETuple>( pos ))) ArgT;
return PackNum<N-1>::template mkVOpExpr<NEXT,ETuple,OpTuple,OpFunction,ArgT,Args...> return PackNum<N-1>::template mkVOpExpr<NEXT,V,ETuple,OpTuple,OpFunction,ArgT,Args...>
( f, pos, ops, std::get<N>(ops).template vget<V>(Getter<NEXT>::template getX<ETuple>( pos )), args...); ( f, pos, ops, std::get<N>(ops).template vget<V>(Getter<NEXT>::template getX<ETuple>( pos )), args...);
} }

View file

@ -35,6 +35,9 @@ namespace MultiArrayHelper
virtual size_t size() const = 0; virtual size_t size() const = 0;
virtual const size_t& val() const = 0; virtual const size_t& val() const = 0;
//virtual size_t rootSteps() const = 0; //virtual size_t rootSteps() const = 0;
virtual bool operator==(const ExtBase& in) const = 0;
virtual bool operator==(size_t in) const = 0;
virtual std::shared_ptr<ExtBase> operator+(const ExtBase& in) const = 0; virtual std::shared_ptr<ExtBase> operator+(const ExtBase& in) const = 0;
virtual std::shared_ptr<ExtBase> operator*(size_t in) const = 0; virtual std::shared_ptr<ExtBase> operator*(size_t in) const = 0;
virtual void zero() = 0; virtual void zero() = 0;
@ -75,6 +78,12 @@ namespace MultiArrayHelper
virtual const size_t& val() const override final { return mExt.val(); } virtual const size_t& val() const override final { return mExt.val(); }
virtual void zero() override final { mExt.zero(); } virtual void zero() override final { mExt.zero(); }
virtual bool operator==(const ExtBase& in) const override final
{ return mExt == dynamic_cast<const ExtT<ExtType>&>(in).mExt; }
virtual bool operator==(size_t in) const override final
{ return mExt == in; }
virtual DExt operator+(const ExtBase& in) const override final virtual DExt operator+(const ExtBase& in) const override final
{ return std::make_shared<ExtT<ExtType>>( mExt + dynamic_cast<const ExtT<ExtType>&>(in).mExt ); } { return std::make_shared<ExtT<ExtType>>( mExt + dynamic_cast<const ExtT<ExtType>&>(in).mExt ); }
virtual DExt operator*(size_t in) const override final virtual DExt operator*(size_t in) const override final
@ -122,6 +131,11 @@ namespace MultiArrayHelper
template <class Y> template <class Y>
DExtTX(const Y& y) : mDExt(std::make_shared<ExtT<Y>>(y)) {} DExtTX(const Y& y) : mDExt(std::make_shared<ExtT<Y>>(y)) {}
*/ */
bool operator==(const DExtTX& in) const
{ return *mDExt == *in.mDExt and mNext == in.mNext; }
bool operator==(size_t in) const
{ return *mDExt == in and mNext == in; }
template <class Y> template <class Y>
DExtTX(const DExtTX<Y>& in) : mDExt(in.mDExt), mNext(in.mNext) {} DExtTX(const DExtTX<Y>& in) : mDExt(in.mDExt), mNext(in.mNext) {}