intermediate commit

This commit is contained in:
Christian Zimmermann 2017-02-13 16:42:22 +01:00
parent 2d5d7770b0
commit 5a369fb08a
2 changed files with 62 additions and 25 deletions

View file

@ -153,17 +153,24 @@ namespace ME
* MultiArray * * MultiArray *
*******************/ *******************/
template <typename T, class... Is> template <typename T, class Range>
T& MultiArray<T,Is...>::operator()(const Is&... is) T& MultiArray<T,Is...>::operator()(const typename Range::indexType& i)
{ {
return mCont[varpos(0, is...)]; return i.pos();
} }
template <typename T, class... Is> template <typename T, class Range>
const T& MultiArray<T,Is...>::operator()(const Is&... is) const const T& MultiArray<T,Is...>::operator()(const typename Range::indexType& i) const
{ {
return mCont[varpos(0, is...)]; return i.pos();
} }
/***************************
* MultiArrayOperation *
***************************/
} // end namespace ME } // end namespace ME

View file

@ -75,19 +75,24 @@ namespace ME
virtual size_t size() const = 0; virtual size_t size() const = 0;
virtual Index begin() = 0; virtual Index begin() = 0;
virtual Index end() = 0; virtual Index end() = 0;
virtual RangeBase* base() = 0; virtual RangeBase<Index>* base() = 0;
virtual bool isSubRange() const; virtual bool isSubRange() const;
protected:
mutable std::string mName;
}; };
template <class Range>
auto cross(const Range& r1, const Range& r2) -> /**/;
template <class Range1, class Range2>
auto cross(const Range1& r1, const Range2& r2) -> /**/;
template <class Index> template <class Index>
class SubRangeBase : public RangeBase<Index> class SubRangeBase : public RangeBase<Index>
{ {
public: public:
virtual bool isSubRange() const override; virtual bool isSubRange() const override;
protected: protected:
RangeBase* mBase; RangeBase<Index>* mBase;
std::vector<bool> mOccupation; std::vector<bool> mOccupation;
}; };
@ -115,6 +120,9 @@ namespace ME
static size_t dim = sizeof...(Ranges); static size_t dim = sizeof...(Ranges);
template <size_t N>
auto get() -> decltype( std::get<N>(mSpace) );
protected: protected:
std::tuple<Ranges...> mSpace; std::tuple<Ranges...> mSpace;
}; };
@ -141,10 +149,15 @@ namespace ME
virtual size_t dim() const = 0; virtual size_t dim() const = 0;
virtual size_t pos() const; // = mPos; implement !!! virtual size_t pos() const; // = mPos; implement !!!
std::string& name();
const std::string& name() const;
protected: protected:
// translate index into position // translate index into position
virtual size_t evaluate(const Index& in) const = 0; virtual size_t evaluate(const Index& in) const = 0;
std::string mName;
size_t mPos; size_t mPos;
RangeBase<Index>* mRange; RangeBase<Index>* mRange;
}; };
@ -201,8 +214,8 @@ namespace ME
MultiArray(const Range& range); // !!!! MultiArray(const Range& range); // !!!!
template <typename... Strings> template <class Operation, typename... Strings>
MultiArrayOperation<T,Range>& operator()(const Strings&... str) const; MultiArrayOperation<T,Range>& operator()(Operation op, const Strings&... str) const;
T& operator()(const typename Range::indexType& i); // implement T& operator()(const typename Range::indexType& i); // implement
const T& operator()(const typename Range::indexType& i) const; // implement const T& operator()(const typename Range::indexType& i) const; // implement
@ -213,23 +226,39 @@ namespace ME
std::shared_ptr<Range> mRange; std::shared_ptr<Range> mRange;
}; };
template <typename T, class Range>
/***************************
* MultiArrayOperation *
***************************/
template <typename T, class Range, class Operation>
class MultiArrayOperation class MultiArrayOperation
{ {
public: public:
template <class Range2> // only creates maximum output range
MultiArrayOperation<T,Range2> operation(/*some operation*/) const; MultiArrayOperation<T,Range,UnaryOperation> operation(UnaryOperation uo) const;
template <class Range2, class Range3> // only creates maximum output range
MultiArrayOperation<T,Range3> operation(const MultiArrayOperation<T,Range2>& in, /*some operation*/) const; template <class Range2, class BinaryOperation, class AnyOperation>
auto operation(const MultiArrayOperation<T, Range2, AnyOperation>& in,
BinaryOperation bo) const
-> MultiArrayOperation<T, decltype( cross( Range, Range2 ) ), BinaryOperation>;
// execute AnyOperation
// exception if range types are inconsitent with names
template<class Range2, class AnyOperation>
MultiArrayOperation& operator=(const MultiArrayOperation<T, Range2, AnyOperation>& in);
private:
MultiArray<T,Range>& mMaRef;
std::map<size_t,std::string> mIndexNameMap;
// execute operation
template <typename... Strings>
MultiArray<T,Range> operator()(const Strings&... str);
}; };
// ========= // =========
// Code that should finally work: // Code that should finally work:
@ -237,8 +266,9 @@ namespace ME
MultiArray<double,/*Tensor*/,/*Tensor*/,/*3DSpace*/,/*3DSpace*/> ma2; MultiArray<double,/*Tensor*/,/*Tensor*/,/*3DSpace*/,/*3DSpace*/> ma2;
MultiArray<double,/*Tensor*/,/*Tensor*/,/*Tensor*/,/*3DSpace*/,/*3DSpace*/,/*3DSpace*/> ma3; MultiArray<double,/*Tensor*/,/*Tensor*/,/*Tensor*/,/*3DSpace*/,/*3DSpace*/,/*3DSpace*/> 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 } // end namespace ME