im com
This commit is contained in:
parent
a9611b40e5
commit
0412be2349
15 changed files with 192 additions and 156 deletions
|
@ -27,6 +27,9 @@ add_executable(mautest src/ma_unit_test.cc)
|
||||||
target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES})
|
target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES})
|
||||||
add_test(NAME mautest COMMAND mautest)
|
add_test(NAME mautest COMMAND mautest)
|
||||||
|
|
||||||
|
add_executable(oputest src/op_unit_test.cc)
|
||||||
|
target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES})
|
||||||
|
add_test(NAME oputest COMMAND oputest)
|
||||||
|
|
||||||
#install(TARGETS testm DESTINATION install)
|
#install(TARGETS testm DESTINATION install)
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,11 @@
|
||||||
__class_name__(__class_name__&& in) = default; \
|
__class_name__(__class_name__&& in) = default; \
|
||||||
__class_name__& operator=(__class_name__&& in) = default
|
__class_name__& operator=(__class_name__&& in) = default
|
||||||
|
|
||||||
|
#define DEFAULT_MEMBERS_X(__class_name__) __class_name__(const __class_name__& in) = default; \
|
||||||
|
__class_name__& operator=(const __class_name__& in) = default; \
|
||||||
|
__class_name__(__class_name__&& in) = default; \
|
||||||
|
__class_name__& operator=(__class_name__&& in) = default
|
||||||
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
@ -112,30 +117,39 @@ namespace MultiArrayTools
|
||||||
// multi_array.h
|
// multi_array.h
|
||||||
template <typename T, class Range>
|
template <typename T, class Range>
|
||||||
class MultiArray;
|
class MultiArray;
|
||||||
|
|
||||||
|
// multi_array_operation.h
|
||||||
|
template <typename T>
|
||||||
|
class OperationBase;
|
||||||
|
|
||||||
|
// multi_array_operation.h
|
||||||
|
template <typename T>
|
||||||
|
class MutableOperationBase;
|
||||||
|
|
||||||
|
// multi_array_operation.h
|
||||||
|
template <class OperationClass>
|
||||||
|
class OperationTemplate;
|
||||||
|
|
||||||
|
// multi_array_operation.h
|
||||||
|
template <typename T, class... Ranges>
|
||||||
|
class OperationMaster;
|
||||||
|
|
||||||
|
// multi_array_operation.h
|
||||||
|
template <typename T, class... Ranges>
|
||||||
|
class OperationRoot;
|
||||||
|
|
||||||
|
// multi_array_operation.h
|
||||||
|
template <typename T, class... Ranges>
|
||||||
|
class ConstOperationRoot;
|
||||||
|
|
||||||
|
// multi_array_operation.h
|
||||||
|
template <typename T, class OpFunction, class... Ops>
|
||||||
|
class Operation;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// multi_array_operation.h
|
|
||||||
template <typename T>
|
|
||||||
class MultiArrayOperationBase;
|
|
||||||
|
|
||||||
// multi_array_operation.h
|
|
||||||
template <typename T>
|
|
||||||
class MutableMultiArrayOperationBase;
|
|
||||||
|
|
||||||
// multi_array_operation.h
|
|
||||||
template <typename T, class Range>
|
|
||||||
class MultiArrayOperationRoot;
|
|
||||||
|
|
||||||
// multi_array_operation.h
|
|
||||||
template <typename T, class Range>
|
|
||||||
class ConstMultiArrayOperationRoot;
|
|
||||||
|
|
||||||
// multi_array_operation.h
|
// multi_array_operation.h
|
||||||
template <typename T, class InRange, class TotalInRange, class OutRange, class TotalRange>
|
template <typename T, class InRange, class TotalInRange, class OutRange, class TotalRange>
|
||||||
class MultiArrayOperationMap;
|
class MultiArrayOperationMap;
|
||||||
|
|
||||||
// multi_array_operation.h
|
|
||||||
template <typename T, class Operation, class... MAOps>
|
|
||||||
class MultiArrayOperation;
|
|
||||||
|
|
||||||
// multi_array_operation.h
|
// multi_array_operation.h
|
||||||
template <typename T, class ContractOperation, class Range, class... MAOps>
|
template <typename T, class ContractOperation, class Range, class... MAOps>
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
ContainerIndex<Indices...>::ContainerIndex(const ContainerIndex& in) :
|
ContainerIndex<Indices...>::ContainerIndex(const ContainerIndex& in) :
|
||||||
IndexInterface<std::tuple<decltype(Indices().meta())...> >(in)
|
IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
|
||||||
{
|
{
|
||||||
PackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
PackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
||||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||||
|
@ -35,7 +35,7 @@ namespace MultiArrayTools
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class MRange>
|
template <class MRange>
|
||||||
ContainerIndex<Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range) :
|
ContainerIndex<Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range) :
|
||||||
IndexInterface<std::tuple<decltype(Indices().meta())...> >(range, 0)
|
IndexInterface<std::tuple<typename Indices::MetaType...> >(range, 0)
|
||||||
{
|
{
|
||||||
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
||||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||||
|
@ -109,7 +109,14 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return *std::get<N>( mIPack );
|
return *std::get<N>( mIPack );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
template <size_t N>
|
||||||
|
auto ContainerIndex<Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
|
||||||
|
{
|
||||||
|
return std::get<N>( mIPack );
|
||||||
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
bool ContainerIndex<Indices...>::first() const
|
bool ContainerIndex<Indices...>::first() const
|
||||||
{
|
{
|
||||||
|
@ -136,6 +143,12 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return sync();
|
return sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
const std::shared_ptr<typename ContainerIndex<Indices...>::RangeType>& ContainerIndex<Indices...>::range() const;
|
||||||
|
{
|
||||||
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************
|
/*****************************
|
||||||
* ContainerRangeFactory *
|
* ContainerRangeFactory *
|
||||||
|
@ -197,7 +210,13 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return std::get<N>( mSpace );
|
return std::get<N>( mSpace );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
const typename ContainerRange<Ranges...>::SpaceType& ContainerRange<Ranges...>::space() const
|
||||||
|
{
|
||||||
|
return mSpace;
|
||||||
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::begin() const
|
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::begin() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,21 +15,22 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
class ContainerIndex : public IndexInterface<std::tuple<decltype(Indices().meta())...> >
|
class ContainerIndex : public IndexInterface<std::tuple<typename Indices::MetaType...> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef IndexBase IB;
|
typedef IndexBase IB;
|
||||||
typedef std::tuple<decltype(Indices().meta())...> MetaType;
|
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
||||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||||
typedef IndexInterface<std::tuple<decltype(Indices().meta())...> > IndexI;
|
typedef IndexInterface<std::tuple<typename Indices::MetaType...> > IndexI;
|
||||||
|
typedef ContainerRange<typename Indices::RangeType...> RangeType;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool mExternControl = false;
|
bool mExternControl = false;
|
||||||
IndexPack mIPack;
|
IndexPack mIPack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContainerIndex() = default;
|
ContainerIndex() = delete;
|
||||||
|
|
||||||
ContainerIndex(const ContainerIndex& in);
|
ContainerIndex(const ContainerIndex& in);
|
||||||
ContainerIndex& operator=(const ContainerIndex& in);
|
ContainerIndex& operator=(const ContainerIndex& in);
|
||||||
|
@ -54,10 +55,14 @@ namespace MultiArrayTools
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
|
||||||
|
|
||||||
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
||||||
|
|
||||||
ContainerIndex& operator()(); // -> sync; just to shorten the code
|
ContainerIndex& operator()(); // -> sync; just to shorten the code
|
||||||
|
|
||||||
|
const std::shared_ptr<RangeType>& range() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,6 +113,8 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
||||||
|
|
||||||
|
const SpaceType& space() const;
|
||||||
|
|
||||||
virtual IndexType begin() const override;
|
virtual IndexType begin() const override;
|
||||||
virtual IndexType end() const override;
|
virtual IndexType end() const override;
|
||||||
|
|
|
@ -178,7 +178,7 @@ namespace {
|
||||||
{
|
{
|
||||||
MultiArray<double,MATest_MDim::CRange> ma(crptr, vv);
|
MultiArray<double,MATest_MDim::CRange> ma(crptr, vv);
|
||||||
EXPECT_EQ( ma.size(), 24 );
|
EXPECT_EQ( ma.size(), 24 );
|
||||||
EXPECT_EQ( ma.range().dim(), 2 );
|
EXPECT_EQ( ma.range()->dim(), 2 );
|
||||||
|
|
||||||
auto i = ma.beginIndex();
|
auto i = ma.beginIndex();
|
||||||
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '1' ) ) ], 2.917);
|
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '1' ) ) ], 2.917);
|
||||||
|
|
|
@ -182,9 +182,9 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class CRange>
|
template <typename T, class CRange>
|
||||||
const CRange& MultiArrayBase<T,CRange>::range() const
|
const std::shared_ptr<CRange>& MultiArrayBase<T,CRange>::range() const
|
||||||
{
|
{
|
||||||
return *mRange;
|
return mRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class CRange>
|
template <typename T, class CRange>
|
||||||
|
@ -192,26 +192,15 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
template <typename T, class CRange>
|
template <typename T, class CRange>
|
||||||
template <class... NameTypes>
|
template <class... SubRanges>
|
||||||
ConstMultiArrayOperationRoot<T,CRange> MultiArrayBase<T,CRange>::operator()(const NameTypes&... str) const
|
ConstOperationRoot<T,SubRanges...>
|
||||||
|
MultiArrayBase<T,CRange>::operator()(std::shared_ptr<typename SubRanges::IndexType>&... inds) const
|
||||||
{
|
{
|
||||||
return ConstMultiArrayOperationRoot<T,CRange>(*this, Name("master", str...));
|
return ConstOperationRoot<T,SubRanges...>(*this, inds...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class CRange>
|
|
||||||
template <class NameType>
|
|
||||||
ConstMultiArrayOperationRoot<T,CRange> MultiArrayBase<T,CRange>::operator()(const NameType& name, bool master) const
|
|
||||||
{
|
|
||||||
if(master){
|
|
||||||
return ConstMultiArrayOperationRoot<T,CRange>(*this, name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return operator()(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
template <typename T, class CRange>
|
template <typename T, class CRange>
|
||||||
bool MultiArrayBase<T,CRange>::isInit() const
|
bool MultiArrayBase<T,CRange>::isInit() const
|
||||||
{
|
{
|
||||||
|
@ -403,47 +392,15 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
template <typename T, class CRange>
|
|
||||||
template <class... NameTypes>
|
|
||||||
MultiArrayOperationRoot<T,CRange> MutableMultiArrayBase<T,CRange>::operator()(const NameTypes&... str)
|
|
||||||
{
|
|
||||||
return MultiArrayOperationRoot<T,CRange>(*this, Name("master", str...));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class CRange>
|
template <typename T, class CRange>
|
||||||
template <class NameType>
|
template <class... SubRanges>
|
||||||
MultiArrayOperationRoot<T,CRange> MutableMultiArrayBase<T,CRange>::operator()(const NameType& name, bool master)
|
OperationRoot<T,SubRanges...>
|
||||||
|
MutableMultiArrayBase<T,CRange>::operator()(std::shared_ptr<typename SubRanges::IndexType>&... inds)
|
||||||
{
|
{
|
||||||
//CHECK;
|
return OperationRoot<T,SubRanges...>(*this, inds...);
|
||||||
if(master){
|
|
||||||
return MultiArrayOperationRoot<T,CRange>(*this, name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return operator()(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class CRange>
|
|
||||||
template <class... NameTypes>
|
|
||||||
ConstMultiArrayOperationRoot<T,CRange> MutableMultiArrayBase<T,CRange>::operator()(const NameTypes&... str) const
|
|
||||||
{
|
|
||||||
return ConstMultiArrayOperationRoot<T,CRange>(*this, Name("master", str...));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class CRange>
|
|
||||||
template <class NameType>
|
|
||||||
ConstMultiArrayOperationRoot<T,CRange> MutableMultiArrayBase<T,CRange>::operator()(const NameType& name, bool master) const
|
|
||||||
{
|
|
||||||
//CHECK;
|
|
||||||
if(master){
|
|
||||||
return ConstMultiArrayOperationRoot<T,CRange>(*this, name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return operator()(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*******************
|
/*******************
|
||||||
* MultiArray *
|
* MultiArray *
|
||||||
*******************/
|
*******************/
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Explicitely specify subranges in template argument !!!
|
||||||
template <typename T, class CRange>
|
template <typename T, class CRange>
|
||||||
class MultiArrayBase
|
class MultiArrayBase
|
||||||
{
|
{
|
||||||
|
@ -88,16 +89,13 @@ namespace MultiArrayTools
|
||||||
virtual typename CRange::IndexType beginIndex() const;
|
virtual typename CRange::IndexType beginIndex() const;
|
||||||
virtual typename CRange::IndexType endIndex() const;
|
virtual typename CRange::IndexType endIndex() const;
|
||||||
|
|
||||||
virtual const CRange& range() const;
|
virtual const std::shared_ptr<CRange>& range() const;
|
||||||
|
|
||||||
virtual bool isConst() const;
|
virtual bool isConst() const;
|
||||||
/*
|
|
||||||
template <class... NameTypes>
|
|
||||||
ConstMultiArrayOperationRoot<T,CRange> operator()(const NameTypes&... str) const;
|
|
||||||
|
|
||||||
template <class NameType>
|
template <class... SubRanges>
|
||||||
ConstMultiArrayOperationRoot<T,CRange> operator()(const NameType& name, bool master) const;
|
ConstOperationRoot<T,SubRanges...> operator()(std::shared_ptr<typename SubRanges::IndexType>&... inds) const;
|
||||||
*/
|
|
||||||
virtual bool isInit() const;
|
virtual bool isInit() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -176,25 +174,9 @@ namespace MultiArrayTools
|
||||||
virtual iterator end();
|
virtual iterator end();
|
||||||
|
|
||||||
virtual bool isConst() const override;
|
virtual bool isConst() const override;
|
||||||
/*
|
|
||||||
template <class... NameTypes>
|
|
||||||
ConstMultiArrayOperationRoot<T,CRange> operator()(bool x, const NameTypes&... str) const
|
|
||||||
{
|
|
||||||
return MAB::operator()(str...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... NameTypes>
|
template <class... SubRanges>
|
||||||
ConstMultiArrayOperationRoot<T,CRange> operator()(const NameTypes&... str) const;
|
OperationRoot<T,SubRanges...> operator()(std::shared_ptr<typename SubRanges::IndexType>&... inds);
|
||||||
|
|
||||||
template <class NameType>
|
|
||||||
ConstMultiArrayOperationRoot<T,CRange> operator()(const NameType& name, bool master) const;
|
|
||||||
|
|
||||||
template <class... NameTypes>
|
|
||||||
MultiArrayOperationRoot<T,CRange> operator()(const NameTypes&... str);
|
|
||||||
|
|
||||||
template <class NameType>
|
|
||||||
MultiArrayOperationRoot<T,CRange> operator()(const NameType& name, bool master);
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, class CRange>
|
template <typename T, class CRange>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "single_range.h"
|
#include "single_range.h"
|
||||||
#include "multi_range.h"
|
#include "multi_range.h"
|
||||||
#include "container_range.h"
|
#include "container_range.h"
|
||||||
//#include "multi_array_operation.h"
|
#include "multi_array_operation.h"
|
||||||
#include "multi_array.h"
|
#include "multi_array.h"
|
||||||
//#include "slice.h"
|
//#include "slice.h"
|
||||||
//#include "manipulator.h"
|
//#include "manipulator.h"
|
||||||
|
|
|
@ -17,11 +17,15 @@ namespace MultiArrayTools
|
||||||
* OperationTemplate *
|
* OperationTemplate *
|
||||||
***************************/
|
***************************/
|
||||||
|
|
||||||
|
template <class OperationClass>
|
||||||
|
OperationTemplate<OperationClass>::OperationTemplate(OperationClass* oc) : mOc(oc) {}
|
||||||
|
|
||||||
template <class OperationClass>
|
template <class OperationClass>
|
||||||
template <class Second>
|
template <class Second>
|
||||||
Operation<OperationClass,Second> OperationTemplate<OperationClass>::operator+(Second&& in) const
|
Operation<double,std::plus<double>,OperationClass,Second>
|
||||||
|
OperationTemplate<OperationClass>::operator+(const Second& in) const
|
||||||
{
|
{
|
||||||
return Operation<double,std::plus<double>,OperationClass,Second>(*this, in);
|
return Operation<double,std::plus<double>,OperationClass,Second>(*mOc, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
|
@ -30,26 +34,31 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
OperationMaster<T,Ranges...>::
|
OperationMaster<T,Ranges...>::
|
||||||
OperationMaster(MutableMultiArrayBase& ma,
|
OperationMaster(MutableMultiArrayBase<T,CRange>& ma, const OperationBase<T>& second,
|
||||||
std::shared_ptr<ContainerRange<Ranges...>::IndexType>& index) :
|
std::shared_ptr<typename CRange::IndexType>& index) :
|
||||||
mArrayRef(ma), mIndex()
|
mSecond(second), mArrayRef(ma), mIndex()
|
||||||
{
|
{
|
||||||
|
MultiRangeFactory<Ranges...> mrf( index->range() );
|
||||||
|
mIndex = mrf.create();
|
||||||
|
CHECK;
|
||||||
(*mIndex) = *index;
|
(*mIndex) = *index;
|
||||||
|
CHECK;
|
||||||
for(*mIndex = 0; mIndex->pos() != mIndex->max(); ++(*mIndex)){
|
for(*mIndex = 0; mIndex->pos() != mIndex->max(); ++(*mIndex)){
|
||||||
get() = mSecond.get();
|
get() = mSecond.get();
|
||||||
}
|
}
|
||||||
|
CHECK;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
T& OperationMaster<T,Ranges...>::get()
|
T& OperationMaster<T,Ranges...>::get()
|
||||||
{
|
{
|
||||||
return mArrayRef.data()[ mIndex.pos() ];
|
return mArrayRef.data()[ mIndex->pos() ];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
const T& OperationMaster<T,Ranges...>::get() const
|
const T& OperationMaster<T,Ranges...>::get() const
|
||||||
{
|
{
|
||||||
return mArrayRef.data()[ mIndex.pos() ];
|
return mArrayRef.data()[ mIndex->pos() ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
|
@ -57,18 +66,21 @@ namespace MultiArrayTools
|
||||||
****************************/
|
****************************/
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
ConstOperationRoot<T,CRange,Ranges...>::
|
ConstOperationRoot<T,Ranges...>::
|
||||||
ConstOperationRoot(const MultiArrayBase<T,CRange>& ma,
|
ConstOperationRoot(const MultiArrayBase<T,CRange>& ma,
|
||||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||||
mArrayRef(ma), mIndex(mArrayRef)
|
OperationBase<T>(), OperationTemplate<ConstOperationRoot<T,Ranges...> >(this),
|
||||||
|
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
|
||||||
{
|
{
|
||||||
|
CHECK;
|
||||||
mIndex(indices...);
|
mIndex(indices...);
|
||||||
|
CHECK;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
const T& ConstOperationRoot<T,Ranges...>::get() const
|
const T& ConstOperationRoot<T,Ranges...>::get() const
|
||||||
{
|
{
|
||||||
return mArrayRef[ mIndex ];
|
return mArrayRef[ *mIndex ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
|
@ -79,9 +91,12 @@ namespace MultiArrayTools
|
||||||
OperationRoot<T,Ranges...>::
|
OperationRoot<T,Ranges...>::
|
||||||
OperationRoot(MutableMultiArrayBase<T,CRange>& ma,
|
OperationRoot(MutableMultiArrayBase<T,CRange>& ma,
|
||||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||||
mArrayRef(ma), mIndex(mArrayRef)
|
MutableOperationBase<T>(), OperationTemplate<OperationRoot<T,Ranges...> >(this),
|
||||||
|
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
|
||||||
{
|
{
|
||||||
mIndex(indices...);
|
CHECK;
|
||||||
|
(*mIndex)(indices...);
|
||||||
|
CHECK;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
|
@ -93,26 +108,28 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
const T& OperationRoot<T,Ranges...>::get() const
|
const T& OperationRoot<T,Ranges...>::get() const
|
||||||
{
|
{
|
||||||
return mArrayRef[ mIndex ];
|
return mArrayRef[ *mIndex ];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
T& OperationRoot<T,Ranges...>::get()
|
T& OperationRoot<T,Ranges...>::get()
|
||||||
{
|
{
|
||||||
return mArrayRef[ mIndex ];
|
return mArrayRef[ *mIndex ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
* OperationRoot *
|
* OperationRoot *
|
||||||
***********************/
|
***********************/
|
||||||
|
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
Operation<T,OpFunction,Ops...>::Operation(Ops&&... ops) : mOps(ops...) {}
|
Operation<T,OpFunction,Ops...>::Operation(const Ops&... ops) :
|
||||||
|
OperationBase<T>(), OperationTemplate<Operation<T,OpFunction,Ops...> >(this),
|
||||||
|
mOps(ops...) {}
|
||||||
|
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
const T& Operation<T,OpFunction,Ops...>::get() const
|
const T& Operation<T,OpFunction,Ops...>::get() const
|
||||||
{
|
{
|
||||||
mRes = F(mOps);
|
mRes = PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mOps);
|
||||||
return mRes;
|
return mRes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
#include "index_base.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
@ -26,9 +25,6 @@ namespace MultiArrayTools
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
typedef std::map<Name,std::shared_ptr<IndexBase> > IndexList;
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class OperationBase
|
class OperationBase
|
||||||
{
|
{
|
||||||
|
@ -37,7 +33,7 @@ namespace MultiArrayTools
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
OperationBase() = default;
|
OperationBase() = default;
|
||||||
virtual ~OperationBase();
|
virtual ~OperationBase() = default;
|
||||||
|
|
||||||
//virtual size_t argNum() const = 0;
|
//virtual size_t argNum() const = 0;
|
||||||
virtual const T& get() const = 0;
|
virtual const T& get() const = 0;
|
||||||
|
@ -56,9 +52,13 @@ namespace MultiArrayTools
|
||||||
class OperationTemplate
|
class OperationTemplate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
OperationTemplate(OperationClass* oc);
|
||||||
|
|
||||||
template <class Second>
|
template <class Second>
|
||||||
Operation<OperationClass,Second> operator+(const Second& in) const;
|
Operation<double,std::plus<double>,OperationClass,Second> operator+(const Second& in) const;
|
||||||
|
private:
|
||||||
|
OperationClass* mOc;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
|
@ -67,10 +67,11 @@ namespace MultiArrayTools
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef OperationBase<T> OB;
|
typedef OperationBase<T> OB;
|
||||||
|
typedef ContainerRange<Ranges...> CRange;
|
||||||
typedef typename MultiRange<Ranges...>::IndexType IndexType;
|
typedef typename MultiRange<Ranges...>::IndexType IndexType;
|
||||||
|
|
||||||
OperationMaster(MutableMultiArrayBase& ma, OperationBase<T>& second,
|
OperationMaster(MutableMultiArrayBase<T,CRange>& ma, const OperationBase<T>& second,
|
||||||
const ContainerRange<Ranges...>::IndexType& index);
|
std::shared_ptr<typename CRange::IndexType>& index);
|
||||||
|
|
||||||
virtual T& get() override;
|
virtual T& get() override;
|
||||||
virtual const T& get() const override;
|
virtual const T& get() const override;
|
||||||
|
@ -86,12 +87,12 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
class ConstOperationRoot : public OperationBase<T>,
|
class ConstOperationRoot : public OperationBase<T>,
|
||||||
public OperationTemplate<ConstOperationRoot<T,CRange> >
|
public OperationTemplate<ConstOperationRoot<T,Ranges...> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef OperationBase<T> OB;
|
typedef OperationBase<T> OB;
|
||||||
typedef OperationTemplate<ConstOperationRoot<T,CRange> > OT;
|
typedef OperationTemplate<ConstOperationRoot<T,Ranges...> > OT;
|
||||||
typedef ContainerRange<Ranges...> CRange;
|
typedef ContainerRange<Ranges...> CRange;
|
||||||
typedef typename CRange::IndexType IndexType;
|
typedef typename CRange::IndexType IndexType;
|
||||||
|
|
||||||
|
@ -108,12 +109,12 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
class OperationRoot : public MutableOperationBase<T>,
|
class OperationRoot : public MutableOperationBase<T>,
|
||||||
public OperationTemplate<OperationRoot<T,CRange> >
|
public OperationTemplate<OperationRoot<T,Ranges...> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef OperationBase<T> OB;
|
typedef OperationBase<T> OB;
|
||||||
typedef OperationTemplate<OperationRoot<T,CRange> > OT;
|
typedef OperationTemplate<OperationRoot<T,Ranges...> > OT;
|
||||||
typedef ContainerRange<Ranges...> CRange;
|
typedef ContainerRange<Ranges...> CRange;
|
||||||
typedef typename CRange::IndexType IndexType;
|
typedef typename CRange::IndexType IndexType;
|
||||||
|
|
||||||
|
@ -141,15 +142,16 @@ namespace MultiArrayTools
|
||||||
typedef OperationTemplate<Operation<T,OpFunction,Ops...> > OT;
|
typedef OperationTemplate<Operation<T,OpFunction,Ops...> > OT;
|
||||||
typedef OpFunction F;
|
typedef OpFunction F;
|
||||||
|
|
||||||
Operation(Ops&&... ops);
|
Operation(const Ops&... ops);
|
||||||
|
|
||||||
virtual const T& get() const override;
|
virtual const T& get() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::tuple<Ops...> mOps;
|
std::tuple<Ops...> mOps;
|
||||||
T res;
|
mutable T mRes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#include "multi_array_operation.cc"
|
#include "multi_array_operation.cc"
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
MultiIndex<Indices...>::MultiIndex(const MultiIndex<Indices...>& in) :
|
MultiIndex<Indices...>::MultiIndex(const MultiIndex<Indices...>& in) :
|
||||||
IndexInterface<std::tuple<decltype(Indices().meta())...> >(in)
|
IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
|
||||||
{
|
{
|
||||||
PackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
PackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
||||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||||
|
@ -33,17 +33,19 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(ContainerIndex<Indices...>& ci)
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(ContainerIndex<Indices...>& ci)
|
||||||
{
|
{
|
||||||
IndexI::operator=(in);
|
CHECK;
|
||||||
PackNum<sizeof...(Indices)-1>::copyInst(mIPack, ci);
|
PackNum<sizeof...(Indices)-1>::copyInst(mIPack, ci);
|
||||||
|
CHECK;
|
||||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||||
|
CHECK;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class MRange>
|
template <class MRange>
|
||||||
MultiIndex<Indices...>::MultiIndex(const std::shared_ptr<MRange>& range) :
|
MultiIndex<Indices...>::MultiIndex(const std::shared_ptr<MRange>& range) :
|
||||||
IndexInterface<std::tuple<decltype(Indices().meta())...> >(range, 0)
|
IndexInterface<std::tuple<typename Indices::MetaType...> >(range, 0)
|
||||||
{
|
{
|
||||||
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
||||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||||
|
@ -151,6 +153,12 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return IB::mPos == IB::mRangePtr->size() - 1;
|
return IB::mPos == IB::mRangePtr->size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
const std::shared_ptr<typename MultiIndex<Indices...>::RangeType>& MultiIndex<Indices...>::range() const
|
||||||
|
{
|
||||||
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
||||||
|
}
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
* MultiRangeFactory *
|
* MultiRangeFactory *
|
||||||
|
@ -167,6 +175,12 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
MultiRangeFactory<Ranges...>::MultiRangeFactory(const std::shared_ptr<ContainerRange<Ranges...> >& cr)
|
||||||
|
{
|
||||||
|
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( cr->space() ) );
|
||||||
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
||||||
|
|
|
@ -15,25 +15,26 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
class MultiIndex : public IndexInterface<std::tuple<decltype(Indices().meta())...> >
|
class MultiIndex : public IndexInterface<std::tuple<typename Indices::MetaType...> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef IndexBase IB;
|
typedef IndexBase IB;
|
||||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||||
typedef std::tuple<decltype(Indices().meta())...> MetaType;
|
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
||||||
typedef IndexInterface<MetaType> IndexI;
|
typedef IndexInterface<MetaType> IndexI;
|
||||||
|
typedef MultiRange<typename Indices::RangeType...> RangeType;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IndexPack mIPack;
|
IndexPack mIPack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MultiIndex() = default;
|
MultiIndex() = delete;
|
||||||
// NO DEFAULT HERE !!!
|
// NO DEFAULT HERE !!!
|
||||||
// ( have to assign sub-indices (ptr!) correctly )
|
// ( have to assign sub-indices (ptr!) correctly )
|
||||||
MultiIndex(const MultiIndex& in);
|
MultiIndex(const MultiIndex& in);
|
||||||
MultiIndex& operator=(const MultiIndex& in);
|
MultiIndex& operator=(const MultiIndex& in);
|
||||||
MultiIndex& operator=(const ContainerIndex<Indices...>& ci);
|
MultiIndex& operator=(ContainerIndex<Indices...>& ci);
|
||||||
|
|
||||||
template <class MRange>
|
template <class MRange>
|
||||||
MultiIndex(const std::shared_ptr<MRange>& range);
|
MultiIndex(const std::shared_ptr<MRange>& range);
|
||||||
|
@ -63,6 +64,8 @@ namespace MultiArrayTools
|
||||||
virtual bool last() const override;
|
virtual bool last() const override;
|
||||||
|
|
||||||
virtual size_t dim() const override;
|
virtual size_t dim() const override;
|
||||||
|
|
||||||
|
const std::shared_ptr<RangeType>& range() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
|
@ -78,6 +81,7 @@ namespace MultiArrayTools
|
||||||
MultiRangeFactory() = delete;
|
MultiRangeFactory() = delete;
|
||||||
MultiRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
MultiRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
||||||
MultiRangeFactory(const typename MultiRange<Ranges...>::SpaceType& space);
|
MultiRangeFactory(const typename MultiRange<Ranges...>::SpaceType& space);
|
||||||
|
MultiRangeFactory(const std::shared_ptr<ContainerRange<Ranges...> >& cr);
|
||||||
|
|
||||||
virtual std::shared_ptr<RangeBase> create() override;
|
virtual std::shared_ptr<RangeBase> create() override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace {
|
||||||
{
|
{
|
||||||
return std::make_tuple(ts...);
|
return std::make_tuple(ts...);
|
||||||
}
|
}
|
||||||
|
|
||||||
class OpTest_1Dim : public ::testing::Test
|
class OpTest_1Dim : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@ -48,7 +48,7 @@ namespace {
|
||||||
swapFactory<SRF>(rfbptr, {'a', 'l', 'f', 'g'} );
|
swapFactory<SRF>(rfbptr, {'a', 'l', 'f', 'g'} );
|
||||||
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||||
|
|
||||||
swapMFactory<CRF>(srptr);
|
swapMFactory<CRF>(rfbptr, srptr);
|
||||||
crptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
crptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +65,9 @@ namespace {
|
||||||
MultiArray<double,CRange> ma2(crptr, v2);
|
MultiArray<double,CRange> ma2(crptr, v2);
|
||||||
MultiArray<double,CRange> res(crptr);
|
MultiArray<double,CRange> res(crptr);
|
||||||
|
|
||||||
std::map<std::string,std::shared_ptr<SRange::IndexType> > m;
|
auto i = std::dynamic_pointer_cast<SRange::IndexType>( srptr->index() );
|
||||||
res(m["mu"]) = ma1(m["mu"]) + ma2(m["mu"]);
|
CHECK;
|
||||||
|
res.operator()<SRange>(i) = ma1.operator()<SRange>(i) + ma2.operator()<SRange>(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namspace
|
} // anonymous namspace
|
||||||
|
|
|
@ -147,6 +147,12 @@ namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
return std::get<sizeof...(Indices)-N-1>(pack)->max() * PackNum<N-1>::blockSize(pack);
|
return std::get<sizeof...(Indices)-N-1>(pack)->max() * PackNum<N-1>::blockSize(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, class Func, class ArgTuple, class... Args>
|
||||||
|
static T unpackArgs(const ArgTuple& tp, const Args&... args)
|
||||||
|
{
|
||||||
|
return PackNum<N-1>::template unpackArgs<T,Func>(tp, std::get<N>(tp).get(), args...);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -252,6 +258,15 @@ namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
return std::get<sizeof...(Indices)-1>(pack)->max();
|
return std::get<sizeof...(Indices)-1>(pack)->max();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, class Func, class ArgTuple, class... Args>
|
||||||
|
static T unpackArgs(const ArgTuple& tp, const Args&... args)
|
||||||
|
{
|
||||||
|
static_assert(sizeof...(Args) == std::tuple_size<ArgTuple>::value-1,
|
||||||
|
"inconsistent number of arguments");
|
||||||
|
static Func f;
|
||||||
|
return f(std::get<0>(tp).get(), args...);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,9 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
typedef IndexBase IB;
|
typedef IndexBase IB;
|
||||||
typedef U MetaType;
|
typedef U MetaType;
|
||||||
|
typedef SingleRange<U,TYPE> RangeType;
|
||||||
|
|
||||||
DEFAULT_MEMBERS(SingleIndex);
|
DEFAULT_MEMBERS_X(SingleIndex);
|
||||||
|
|
||||||
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
|
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue