operation creation for functional multi_arrays

This commit is contained in:
Christian Zimmermann 2018-03-21 16:11:05 +01:00
parent 7fdaef7b2f
commit 05fbcbf7a2
6 changed files with 50 additions and 7 deletions

View file

@ -3,6 +3,7 @@
#define __functional_multi_array__ #define __functional_multi_array__
#include "multi_array_base.h" #include "multi_array_base.h"
#include "slice.h"
namespace MultiArrayTools namespace MultiArrayTools
{ {
@ -17,6 +18,13 @@ namespace MultiArrayTools
typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator; typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator;
typedef typename CRange::IndexType IndexType; typedef typename CRange::IndexType IndexType;
private:
mutable T mVal;
Function mFunc;
public:
DEFAULT_MEMBERS(FunctionalMultiArray); DEFAULT_MEMBERS(FunctionalMultiArray);
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const Function& func); FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const Function& func);
@ -27,12 +35,9 @@ namespace MultiArrayTools
// EVALUTAION CLASS ??!!!! // EVALUTAION CLASS ??!!!!
//virtual ConstOperationRoot<T,SRanges...> auto operator()(std::shared_ptr<typename SRanges::IndexType>&... inds) const
//operator()(std::shared_ptr<typename SRanges::IndexType>&... inds) const override; -> decltype( mkOperation( mFunc, ConstOperationRoot<T,SRanges...>(inds.metaPtr(), inds), ... ) )
private:
mutable T mVal;
Function mFunc;
}; };
@ -78,6 +83,15 @@ namespace MultiArrayTools
return false; return false;
} }
template <typename T, class Function, class... SRanges>
auto FunctionalMultiArray<T,Function,SRanges...>::
operator()(std::shared_ptr<typename SRanges::IndexType>&... inds) const
-> decltype( mkOperation( mFunc, ConstOperationRoot<T,SRanges...>(inds.metaPtr(), inds), ... ) )
{
return mkOperation( mFunc, ConstOperationRoot<T,SRanges...>(inds.metaPtr(), inds), ... );
}
} // namespace MultiArrayTools } // namespace MultiArrayTools
#endif #endif

View file

@ -259,6 +259,12 @@ namespace MultiArrayTools
}; };
template <class OpFunction, class... Ops>
auto mkOperation(const OpFunction& f, const Ops&... ops)
-> Operation<OpFunction::value_type,OpFunction,Ops...>
{
return Operation<OpFunction::value_type,OpFunction,Ops...>(ops...);
}
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
class Contraction : public OperationTemplate<T,Contraction<T,Op,IndexType> > class Contraction : public OperationTemplate<T,Contraction<T,Op,IndexType> >

View file

@ -60,6 +60,7 @@ namespace MultiArrayTools
std::string id() const { return THIS().id(); } std::string id() const { return THIS().id(); }
MetaType meta() const { return THIS().meta(); } MetaType meta() const { return THIS().meta(); }
MetaType metaPtr() const { return THIS().metaPtr(); }
I& at(const MetaType& meta) { return THIS().at(meta); } I& at(const MetaType& meta) { return THIS().at(meta); }
void print(size_t offset = 0) const { THIS().print(offset); } void print(size_t offset = 0) const { THIS().print(offset); }

View file

@ -45,6 +45,7 @@ namespace MultiArrayTools
static constexpr bool defaultable = true; static constexpr bool defaultable = true;
static constexpr size_t ISSTATIC = 0; static constexpr size_t ISSTATIC = 0;
static constexpr size_t SIZE = -1; static constexpr size_t SIZE = -1;
static constexpr bool HASMETACONT = false;
static SingleRangeFactory<size_t, SpaceType::NONE> factory(size_t size = 0) static SingleRangeFactory<size_t, SpaceType::NONE> factory(size_t size = 0)
{ return SingleRangeFactory<size_t, SpaceType::NONE>(size); } { return SingleRangeFactory<size_t, SpaceType::NONE>(size); }

View file

@ -51,6 +51,7 @@ namespace MultiArrayTools
static constexpr size_t ISSTATIC = 1; static constexpr size_t ISSTATIC = 1;
static constexpr size_t SIZE = mSpinNum; static constexpr size_t SIZE = mSpinNum;
static constexpr bool HASMETACONT = false;
static SingleRangeFactory<size_t, SpaceType::SPIN> factory() static SingleRangeFactory<size_t, SpaceType::SPIN> factory()
{ return SingleRangeFactory<size_t, SpaceType::SPIN>(); } { return SingleRangeFactory<size_t, SpaceType::SPIN>(); }

View file

@ -137,10 +137,30 @@ namespace MultiArrayTools
* SingleIndex * * SingleIndex *
******************/ ******************/
template <bool HASMETACONT>
struct MetaPtrSetter
{
template <typename U, class Range>
U* set(Range* r)
{
return &r->get(0);
}
};
template <>
struct MetaPtrSetter<false>
{
template <typename U, class Range>
U* set(Range* r)
{
return nullptr;
}
};
template <typename U, SpaceType TYPE> template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) : SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
IndexInterface<SingleIndex<U,TYPE>,U>(range, 0), IndexInterface<SingleIndex<U,TYPE>,U>(range, 0),
mMetaPtr(&IB::mRangePtr->get(0)) {} mMetaPtr(MetaPtrSetter<SingleIndex<U,TYPE>::HASMETACONT>::set(IB::mRangePtr)) {}
template <typename U, SpaceType TYPE> template <typename U, SpaceType TYPE>
IndexType SingleIndex<U,TYPE>::type() const IndexType SingleIndex<U,TYPE>::type() const