From 5a369fb08ac6c6bcb8a5859f5d83585845a3eb0f Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 13 Feb 2017 16:42:22 +0100 Subject: [PATCH] intermediate commit --- src/me.cc | 19 +++++++++++----- src/me.h | 68 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/me.cc b/src/me.cc index 890ee39..498db26 100644 --- a/src/me.cc +++ b/src/me.cc @@ -153,17 +153,24 @@ namespace ME * MultiArray * *******************/ - template - T& MultiArray::operator()(const Is&... is) + template + T& MultiArray::operator()(const typename Range::indexType& i) { - return mCont[varpos(0, is...)]; + return i.pos(); } - template - const T& MultiArray::operator()(const Is&... is) const + template + const T& MultiArray::operator()(const typename Range::indexType& i) const { - return mCont[varpos(0, is...)]; + return i.pos(); } + + + /*************************** + * MultiArrayOperation * + ***************************/ + + } // end namespace ME diff --git a/src/me.h b/src/me.h index b16e9fa..ca0466c 100644 --- a/src/me.h +++ b/src/me.h @@ -75,19 +75,24 @@ namespace ME virtual size_t size() const = 0; virtual Index begin() = 0; virtual Index end() = 0; - virtual RangeBase* base() = 0; + virtual RangeBase* base() = 0; virtual bool isSubRange() const; - protected: - mutable std::string mName; + }; + template + auto cross(const Range& r1, const Range& r2) -> /**/; + + template + auto cross(const Range1& r1, const Range2& r2) -> /**/; + template class SubRangeBase : public RangeBase { public: virtual bool isSubRange() const override; protected: - RangeBase* mBase; + RangeBase* mBase; std::vector mOccupation; }; @@ -114,7 +119,10 @@ namespace ME public: static size_t dim = sizeof...(Ranges); - + + template + auto get() -> decltype( std::get(mSpace) ); + protected: std::tuple mSpace; }; @@ -140,10 +148,15 @@ namespace ME virtual size_t dim() const = 0; virtual size_t pos() const; // = mPos; implement !!! + + std::string& name(); + const std::string& name() const; protected: // translate index into position virtual size_t evaluate(const Index& in) const = 0; + + std::string mName; size_t mPos; RangeBase* mRange; @@ -201,8 +214,8 @@ namespace ME MultiArray(const Range& range); // !!!! - template - MultiArrayOperation& operator()(const Strings&... str) const; + template + MultiArrayOperation& operator()(Operation op, const Strings&... str) const; T& operator()(const typename Range::indexType& i); // implement const T& operator()(const typename Range::indexType& i) const; // implement @@ -213,32 +226,49 @@ namespace ME std::shared_ptr mRange; }; - template + + /*************************** + * MultiArrayOperation * + ***************************/ + + template class MultiArrayOperation { public: - template - MultiArrayOperation operation(/*some operation*/) const; + // only creates maximum output range + MultiArrayOperation operation(UnaryOperation uo) const; + + // only creates maximum output range + template + auto operation(const MultiArrayOperation& in, + BinaryOperation bo) const + -> MultiArrayOperation; - template - MultiArrayOperation operation(const MultiArrayOperation& in, /*some operation*/) const; - // execute operation - template - MultiArray operator()(const Strings&... str); + // execute AnyOperation + // exception if range types are inconsitent with names + template + MultiArrayOperation& operator=(const MultiArrayOperation& in); + + + private: + MultiArray& mMaRef; + + std::map mIndexNameMap; + }; - // ========= // Code that should finally work: MultiArray ma1; MultiArray ma2; MultiArray ma3; - - ma3 = ( ma1("mu","nu","x","y") * ma2("nu","lambda","y","z") )("mu","nu","lambda","x","y","z"); - + + ma3("mu","nu","lambda","x","y","z") = ma1("mu","nu","x","y") * ma2("nu","lambda","y","z"); + // operator= operation() + ("mu","nu","lambda","x","y","z") <--- ("mu","nu","x","y","nu","lambda","y","z") } // end namespace ME