use meta operation in fma (should be faster)

This commit is contained in:
Christian Zimmermann 2018-11-26 13:13:23 +01:00
parent 1aa5ed10d9
commit ae534e2493
4 changed files with 37 additions and 28 deletions

View file

@ -112,7 +112,7 @@ namespace MultiArrayTools
return mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( mkMAObject( inds ), inds ) ... ); return mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( mkMAObject( inds ), inds ) ... );
} }
*/ */
/*
template <typename T, class Function, class... SRanges> template <typename T, class Function, class... SRanges>
auto FunctionalMultiArray<T,Function,SRanges...>:: auto FunctionalMultiArray<T,Function,SRanges...>::
exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
@ -120,5 +120,13 @@ namespace MultiArrayTools
{ {
return mkOperation( mFunc, mkOpObject(inds) ... ); return mkOperation( mFunc, mkOpObject(inds) ... );
} }
*/
template <typename T, class Function, class... SRanges>
auto FunctionalMultiArray<T,Function,SRanges...>::
exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
-> Operation<T,Function,MetaOperationRoot<SRanges>...>
{
return mkOperation( mFunc, MetaOperationRoot<SRanges>( inds ) ... );
}
} // namespace MultiArrayTools } // namespace MultiArrayTools

View file

@ -133,7 +133,8 @@ namespace MultiArrayTools
auto exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const auto exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
// -> decltype( mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( mkMAObject( inds ), inds) ... ) ); // -> decltype( mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( mkMAObject( inds ), inds) ... ) );
-> decltype( mkOperation( mFunc, mkOpObject(inds) ... ) ); //-> decltype( mkOperation( mFunc, mkOpObject(inds) ... ) );
-> Operation<T,Function,MetaOperationRoot<SRanges>...>;
virtual ConstOperationRoot<T,SRanges...> virtual ConstOperationRoot<T,SRanges...>
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override; operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override;

View file

@ -261,41 +261,43 @@ namespace MultiArrayTools
* MetaOperationRoot * * MetaOperationRoot *
****************************/ ****************************/
template <class... Ranges> template <class Range>
MetaOperationRoot<Ranges...>:: MetaOperationRoot<Range>::
MetaOperationRoot(const IndexType& ind) : MetaOperationRoot(const std::shared_ptr<IndexType>& ind) :
mIndex( ind ) { } mIndex( ind ) { }
template <class... Ranges>
template <class Range>
template <class ET> template <class ET>
inline typename MetaOperationRoot<Ranges...>::value_type inline typename MetaOperationRoot<Range>::value_type
MetaOperationRoot<Ranges...>::get(ET pos) const MetaOperationRoot<Range>::get(ET pos) const
{ {
//VCHECK(pos.val()); //VCHECK(pos.val());
//VCHECK(mDataPtr); //VCHECK(mDataPtr);
//VCHECK(mDataPtr[pos.val()]) //VCHECK(mDataPtr[pos.val()])
return mIndex.meta(pos.val()); return mIndex->range()->get( pos.val() );
} }
template <class... Ranges> template <class Range>
template <class ET> template <class ET>
inline const MetaOperationRoot<Ranges...>& MetaOperationRoot<Ranges...>::set(ET pos) const inline const MetaOperationRoot<Range>& MetaOperationRoot<Range>::set(ET pos) const
{ {
mIndex = pos.val(); assert(0);
//(*mIndex) = pos.val();
return *this; return *this;
} }
template <class... Ranges> template <class Range>
MExt<void> MetaOperationRoot<Ranges...>::rootSteps(std::intptr_t iPtrNum) const MExt<void> MetaOperationRoot<Range>::rootSteps(std::intptr_t iPtrNum) const
{ {
return MExt<void>(getStepSize( mIndex, iPtrNum )); return MExt<void>(getStepSize( *mIndex, iPtrNum ));
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); //return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
} }
template <class... Ranges> template <class Range>
template <class Expr> template <class Expr>
Expr MetaOperationRoot<Ranges...>::loop(Expr exp) const Expr MetaOperationRoot<Range>::loop(Expr exp) const
{ {
return exp; return exp;
} }

View file

@ -217,21 +217,19 @@ namespace MultiArrayTools
return StaticCast<T,Op>(op); return StaticCast<T,Op>(op);
} }
template <class... Ranges> template <class Range>
class MetaOperationRoot : public OperationTemplate<std::tuple<typename Ranges::IndexType...>, class MetaOperationRoot : public OperationTemplate<typename Range::MetaType,
MetaOperationRoot<Ranges...> > MetaOperationRoot<Range> >
{ {
public: public:
typedef ContainerIndex<std::tuple<typename Ranges::IndexType::MetaType...>, typedef typename Range::IndexType IndexType;
typename Ranges::IndexType...> IndexType;
typedef typename IndexType::MetaType value_type; typedef typename IndexType::MetaType value_type;
typedef OperationBase<value_type,MetaOperationRoot<Ranges...> > OT; typedef OperationBase<value_type,MetaOperationRoot<Range> > OT;
typedef ContainerRange<value_type,Ranges...> CRange;
static constexpr size_t SIZE = 1; static constexpr size_t SIZE = 1;
MetaOperationRoot(const IndexType& ind); MetaOperationRoot(const std::shared_ptr<IndexType>& ind);
template <class ET> template <class ET>
inline value_type get(ET pos) const; inline value_type get(ET pos) const;
@ -248,7 +246,7 @@ namespace MultiArrayTools
//MultiArrayBase<T,Ranges...> const& mArrayRef; //MultiArrayBase<T,Ranges...> const& mArrayRef;
//const T* mDataPtr; //const T* mDataPtr;
IndexType mIndex; std::shared_ptr<IndexType> mIndex;
}; };
template <typename T, class... Ranges> template <typename T, class... Ranges>