2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
#ifndef __functional_multi_array__
|
|
|
|
#define __functional_multi_array__
|
|
|
|
|
|
|
|
#include "multi_array_base.h"
|
2018-03-21 16:11:05 +01:00
|
|
|
#include "slice.h"
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2018-03-21 19:18:57 +01:00
|
|
|
|
2018-07-20 19:13:42 +02:00
|
|
|
template <bool HASMETACONT>
|
|
|
|
struct ToMAObject
|
|
|
|
{
|
|
|
|
template <class Index>
|
|
|
|
static auto mk(const std::shared_ptr<Index>& i)
|
|
|
|
-> MultiArray<typename Index::MetaType, typename Index::RangeType>
|
|
|
|
{
|
|
|
|
std::vector<typename Index::MetaType> vv(i->range()->size());
|
|
|
|
for(Index j = (*i); j.pos() != j.max(); ++j){
|
|
|
|
vv[j.pos()] = j.meta();
|
2018-07-29 19:17:26 +02:00
|
|
|
}
|
|
|
|
return MultiArray<typename Index::MetaType, typename Index::RangeType>( i->range(), vv );
|
2018-07-20 19:13:42 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ToMAObject<true>
|
|
|
|
{
|
|
|
|
template <class Index>
|
|
|
|
static auto mk(const std::shared_ptr<Index>& i)
|
|
|
|
-> ConstSlice<typename Index::MetaType, typename Index::RangeType>
|
|
|
|
{
|
|
|
|
return ConstSlice<typename Index::MetaType, typename Index::RangeType>( i->range(), i->metaPtr() );
|
|
|
|
}
|
|
|
|
};
|
2018-07-29 19:17:26 +02:00
|
|
|
|
2018-03-21 19:18:57 +01:00
|
|
|
template <class Index>
|
2018-07-20 19:13:42 +02:00
|
|
|
auto mkMAObject(const std::shared_ptr<Index>& i)
|
2018-07-29 19:17:26 +02:00
|
|
|
-> std::shared_ptr<decltype(ToMAObject<Index::RangeType::HASMETACONT>::mk(i))>
|
2018-07-20 19:13:42 +02:00
|
|
|
{
|
2018-07-29 19:17:26 +02:00
|
|
|
return std::make_shared<decltype(ToMAObject<Index::RangeType::HASMETACONT>::mk(i))>
|
|
|
|
(ToMAObject<Index::RangeType::HASMETACONT>::mk(i));
|
2018-07-20 19:13:42 +02:00
|
|
|
}
|
2018-07-29 19:17:26 +02:00
|
|
|
/*
|
|
|
|
template <bool HASMETACONT>
|
|
|
|
struct ToOpObject
|
|
|
|
{
|
|
|
|
template <class Index>
|
|
|
|
static auto mk(const std::shared_ptr<Index>& ind)
|
|
|
|
-> MetaOperationRoot<typename Index::RangeType>
|
|
|
|
{
|
|
|
|
typedef typename Index::RangeType RangeType;
|
|
|
|
MultiRangeFactory<RangeType> mrf(ind->range());
|
|
|
|
auto mr = std::dynamic_pointer_cast<RangeType>( mrf.create() );
|
|
|
|
typedef typename MultiRange<RangeType>::IndexType::MetaType value_type;
|
|
|
|
ContainerIndex<value_type,Index> ci(mr,0);
|
|
|
|
return MetaOperationRoot<typename Index::RangeType>(ci);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ToOpObject<true>
|
|
|
|
{
|
|
|
|
template <class Index>
|
|
|
|
static auto mk(const std::shared_ptr<Index>& ind)
|
|
|
|
-> ConstOperationRoot<typename Index::MetaType,
|
|
|
|
typename Index::RangeType>
|
|
|
|
{
|
|
|
|
return ConstOperationRoot<typename Index::MetaType,
|
|
|
|
typename Index::RangeType>( mkMAObject(ind), ind);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*/
|
2018-03-21 19:18:57 +01:00
|
|
|
|
2018-07-29 19:17:26 +02:00
|
|
|
template <bool HASMETACONT>
|
|
|
|
struct ToOpObject
|
|
|
|
{
|
|
|
|
template <class Index>
|
|
|
|
static auto mk(const std::shared_ptr<Index>& ind)
|
|
|
|
-> ConstOperationRoot<typename Index::MetaType,
|
|
|
|
typename Index::RangeType>
|
|
|
|
{
|
|
|
|
return ConstOperationRoot<typename Index::MetaType,
|
|
|
|
typename Index::RangeType>( mkMAObject(ind), ind);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
auto mkOpObject(const std::shared_ptr<Index>& i)
|
|
|
|
-> decltype(ToOpObject<Index::RangeType::HASMETACONT>::mk(i))
|
|
|
|
{
|
|
|
|
return ToOpObject<Index::RangeType::HASMETACONT>::mk(i);
|
|
|
|
}
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
|
|
|
class FunctionalMultiArray : public MultiArrayBase<T,SRanges...>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef ContainerRange<T,SRanges...> CRange;
|
2018-03-22 11:13:00 +01:00
|
|
|
typedef MultiArrayBase<T,SRanges...> MAB;
|
2018-03-21 19:18:57 +01:00
|
|
|
//typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator;
|
|
|
|
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
|
|
|
//typedef typename CRange::IndexType IndexType;
|
2018-03-22 11:13:00 +01:00
|
|
|
typedef MultiArray<T,SRanges...> MAType;
|
2018-08-20 17:50:04 +02:00
|
|
|
typedef T value_type;
|
2018-03-22 11:13:00 +01:00
|
|
|
|
2018-03-21 16:11:05 +01:00
|
|
|
private:
|
|
|
|
mutable T mVal;
|
2018-09-12 20:56:55 +02:00
|
|
|
std::shared_ptr<Function> mFunc;
|
2018-03-21 16:11:05 +01:00
|
|
|
|
2018-03-22 11:13:00 +01:00
|
|
|
mutable std::shared_ptr<MAType> mMaPtr;
|
|
|
|
|
2018-03-21 16:11:05 +01:00
|
|
|
public:
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
DEFAULT_MEMBERS(FunctionalMultiArray);
|
2018-09-12 20:56:55 +02:00
|
|
|
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const std::shared_ptr<Function>& func);
|
2018-03-21 19:18:57 +01:00
|
|
|
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges);
|
2018-08-20 17:50:04 +02:00
|
|
|
FunctionalMultiArray(const typename CRange::Space& space);
|
2018-09-12 20:56:55 +02:00
|
|
|
FunctionalMultiArray(const typename CRange::Space& space, const std::shared_ptr<Function>& func);
|
2018-03-21 19:18:57 +01:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
virtual const T& operator[](const IndexType& i) const override;
|
2018-03-21 20:00:32 +01:00
|
|
|
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const override;
|
|
|
|
virtual const T* data() const override;
|
2018-03-21 19:18:57 +01:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
virtual bool isConst() const override;
|
|
|
|
virtual bool isSlice() const override;
|
|
|
|
|
2018-08-06 15:20:06 +02:00
|
|
|
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
2018-07-16 18:52:02 +02:00
|
|
|
|
2018-03-17 20:25:16 +01:00
|
|
|
// EVALUTAION CLASS ??!!!!
|
2018-03-21 16:11:05 +01:00
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
auto exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
2018-07-29 19:17:26 +02:00
|
|
|
// -> decltype( mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( mkMAObject( inds ), inds) ... ) );
|
|
|
|
-> decltype( mkOperation( mFunc, mkOpObject(inds) ... ) );
|
|
|
|
|
2018-03-22 11:13:00 +01:00
|
|
|
virtual ConstOperationRoot<T,SRanges...>
|
2018-07-21 18:05:53 +02:00
|
|
|
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override;
|
2018-03-17 20:25:16 +01:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
};
|
|
|
|
|
2018-03-21 19:18:57 +01:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
} // namespace MultiArrayTools
|
|
|
|
|
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|