diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 99ce205..9e4e1fb 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -51,7 +51,6 @@ namespace MultiArrayTools template template auto OperationBase::c(const std::shared_ptr& ind) const - -> Contraction { return Contraction(THIS(), ind); } @@ -59,7 +58,6 @@ namespace MultiArrayTools template template auto OperationBase::sl(const std::shared_ptr&... inds) const - -> ConstSlice { ConstSlice out(inds->range()...); out.define(inds...) = THIS(); @@ -69,7 +67,6 @@ namespace MultiArrayTools template template auto OperationBase::p(const std::shared_ptr&... inds) const - -> ConstOperationRoot { auto ma = std::make_shared> (inds->range()... , static_cast(0)); @@ -80,7 +77,6 @@ namespace MultiArrayTools template template auto OperationBase::to(const std::shared_ptr&... inds) const - -> MultiArray { MultiArray out(inds->range()...); out(inds...) = THIS(); @@ -90,7 +86,6 @@ namespace MultiArrayTools template template auto OperationBase::addto(const std::shared_ptr&... inds) const - -> MultiArray { MultiArray out(inds->range()..., static_cast(0)); @@ -101,7 +96,6 @@ namespace MultiArrayTools template template auto OperationBase::pto(const std::shared_ptr&... inds) const - -> MultiArray { MultiArray out(inds->range()...); out(inds...).par() = THIS(); @@ -111,7 +105,6 @@ namespace MultiArrayTools template template auto OperationBase::paddto(const std::shared_ptr&... inds) const - -> MultiArray { MultiArray out(inds->range()..., static_cast(0)); @@ -123,14 +116,12 @@ namespace MultiArrayTools template auto OperationBase::a(const std::shared_ptr>& ll, const Args&... args) const - -> Operation,OperationClass, Args...> { return Operation,OperationClass, Args...>(ll, THIS(), args...); } template auto OperationBase::ptr() const - -> OperationPointer { return OperationPointer(THIS()); } @@ -144,7 +135,30 @@ namespace MultiArrayTools return HyperOperation() } */ - + + /************************ + * AccessTemplate * + ************************/ + + template + auto AccessTemplate::get(size_t pos) + { + return THIS().get(pos); + } + + template + auto AccessTemplate::get(size_t pos) const + { + return THIS().get(pos); + } + + template + template + void AccessTemplate::exec(size_t pos, const Op& op, ExtType e) const + { + return THIS().template exec(pos,op,e); + } + /************************ * AssignmentExpr * ************************/ diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index d90cbf7..991302e 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -50,39 +50,30 @@ namespace MultiArrayTools auto operator/(const OperationBase& in) const; template - auto c(const std::shared_ptr& ind) const - -> Contraction; + auto c(const std::shared_ptr& ind) const; template - auto sl(const std::shared_ptr&... inds) const - -> ConstSlice; + auto sl(const std::shared_ptr&... inds) const; template - auto p(const std::shared_ptr&... inds) const - -> ConstOperationRoot; + auto p(const std::shared_ptr&... inds) const; template - auto to(const std::shared_ptr&... inds) const - -> MultiArray; + auto to(const std::shared_ptr&... inds) const; template - auto addto(const std::shared_ptr&... inds) const - -> MultiArray; + auto addto(const std::shared_ptr&... inds) const; template - auto pto(const std::shared_ptr&... inds) const - -> MultiArray; + auto pto(const std::shared_ptr&... inds) const; template - auto paddto(const std::shared_ptr&... inds) const - -> MultiArray; + auto paddto(const std::shared_ptr&... inds) const; template // Args = Operation Classes - auto a(const std::shared_ptr>& ll, const Args&... args) const - -> Operation,OperationClass, Args...>; + auto a(const std::shared_ptr>& ll, const Args&... args) const; - auto ptr() const - -> OperationPointer; + auto ptr() const; private: friend OperationClass; @@ -212,7 +203,65 @@ namespace MultiArrayTools template using IVPlus = IVAccess>; - + + // static polymorphism + template + class AccessTemplate + { + public: + typedef AccessClass AC; + + AccessClass& THIS() { return static_cast(*this); } + const AccessClass& THIS() const { return static_cast(*this); } + + inline auto get(size_t pos); + inline auto get(size_t pos) const; + + template + inline void exec(size_t pos, const Op& op, ExtType e) const; + }; + + template + class PointerAccess : public AccessTemplate> + { + public: + typedef T value_type; + typedef T in_type; + private: + T* mPtr; + + public: + PointerAccess(T* ptr) : mPtr(ptr) {} + + T* get(size_t pos) { return mPtr; } + T* get(size_t pos) const { return mPtr; } + + template + inline void exec(size_t pos, const Op& op, ExtType e) const + { + F::selfApply(*get(pos),op.get(e)); + } + }; + + template + class ConstPointerAccess : public AccessTemplate> + { + public: + typedef T value_type; + typedef T in_type; + private: + const T* mPtr; + + public: + ConstPointerAccess(T* ptr) : mPtr(ptr) {} + + const T* get(size_t pos) { return mPtr; } + const T* get(size_t pos) const { return mPtr; } + + template + inline void exec(size_t pos, const Op& op, ExtType e) const { assert(0); } + }; + template class AssignmentExpr : public ExpressionBase {