From ae534e24939574993c80288d9489f06daff77c37 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 26 Nov 2018 13:13:23 +0100 Subject: [PATCH] use meta operation in fma (should be faster) --- src/include/functional_multi_array.cc.h | 12 ++++++++-- src/include/functional_multi_array.h | 5 ++-- src/include/multi_array_operation.cc.h | 32 +++++++++++++------------ src/include/multi_array_operation.h | 16 ++++++------- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/include/functional_multi_array.cc.h b/src/include/functional_multi_array.cc.h index 97086a3..fd116c0 100644 --- a/src/include/functional_multi_array.cc.h +++ b/src/include/functional_multi_array.cc.h @@ -112,7 +112,7 @@ namespace MultiArrayTools return mkOperation( mFunc, ConstOperationRoot( mkMAObject( inds ), inds ) ... ); } */ - + /* template auto FunctionalMultiArray:: exec(const std::shared_ptr&... inds) const @@ -120,5 +120,13 @@ namespace MultiArrayTools { return mkOperation( mFunc, mkOpObject(inds) ... ); } - + */ + template + auto FunctionalMultiArray:: + exec(const std::shared_ptr&... inds) const + -> Operation...> + { + return mkOperation( mFunc, MetaOperationRoot( inds ) ... ); + } + } // namespace MultiArrayTools diff --git a/src/include/functional_multi_array.h b/src/include/functional_multi_array.h index cf507c4..9bc3d6d 100644 --- a/src/include/functional_multi_array.h +++ b/src/include/functional_multi_array.h @@ -133,8 +133,9 @@ namespace MultiArrayTools auto exec(const std::shared_ptr&... inds) const // -> decltype( mkOperation( mFunc, ConstOperationRoot( mkMAObject( inds ), inds) ... ) ); - -> decltype( mkOperation( mFunc, mkOpObject(inds) ... ) ); - + //-> decltype( mkOperation( mFunc, mkOpObject(inds) ... ) ); + -> Operation...>; + virtual ConstOperationRoot operator()(const std::shared_ptr&... inds) const override; diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 087ac5e..3c24e3c 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -261,41 +261,43 @@ namespace MultiArrayTools * MetaOperationRoot * ****************************/ - template - MetaOperationRoot:: - MetaOperationRoot(const IndexType& ind) : + template + MetaOperationRoot:: + MetaOperationRoot(const std::shared_ptr& ind) : mIndex( ind ) { } - template + + template template - inline typename MetaOperationRoot::value_type - MetaOperationRoot::get(ET pos) const + inline typename MetaOperationRoot::value_type + MetaOperationRoot::get(ET pos) const { //VCHECK(pos.val()); //VCHECK(mDataPtr); //VCHECK(mDataPtr[pos.val()]) - return mIndex.meta(pos.val()); + return mIndex->range()->get( pos.val() ); } - template + template template - inline const MetaOperationRoot& MetaOperationRoot::set(ET pos) const + inline const MetaOperationRoot& MetaOperationRoot::set(ET pos) const { - mIndex = pos.val(); + assert(0); + //(*mIndex) = pos.val(); return *this; } - template - MExt MetaOperationRoot::rootSteps(std::intptr_t iPtrNum) const + template + MExt MetaOperationRoot::rootSteps(std::intptr_t iPtrNum) const { - return MExt(getStepSize( mIndex, iPtrNum )); + return MExt(getStepSize( *mIndex, iPtrNum )); //return MExt(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); } - template + template template - Expr MetaOperationRoot::loop(Expr exp) const + Expr MetaOperationRoot::loop(Expr exp) const { return exp; } diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index ba2f893..8d826a2 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -217,21 +217,19 @@ namespace MultiArrayTools return StaticCast(op); } - template - class MetaOperationRoot : public OperationTemplate, - MetaOperationRoot > + template + class MetaOperationRoot : public OperationTemplate > { public: - typedef ContainerIndex, - typename Ranges::IndexType...> IndexType; + typedef typename Range::IndexType IndexType; typedef typename IndexType::MetaType value_type; - typedef OperationBase > OT; - typedef ContainerRange CRange; + typedef OperationBase > OT; static constexpr size_t SIZE = 1; - MetaOperationRoot(const IndexType& ind); + MetaOperationRoot(const std::shared_ptr& ind); template inline value_type get(ET pos) const; @@ -248,7 +246,7 @@ namespace MultiArrayTools //MultiArrayBase const& mArrayRef; //const T* mDataPtr; - IndexType mIndex; + std::shared_ptr mIndex; }; template