make first operation test run (index copying not supported at the moment)

This commit is contained in:
Christian Zimmermann 2017-08-11 16:45:03 +02:00
parent 0412be2349
commit b50620a451
8 changed files with 27 additions and 30 deletions

View file

@ -14,7 +14,7 @@ namespace MultiArrayTools
/********************** /**********************
* ContainerIndex * * ContainerIndex *
**********************/ **********************/
/*
template <class... Indices> template <class... Indices>
ContainerIndex<Indices...>::ContainerIndex(const ContainerIndex& in) : ContainerIndex<Indices...>::ContainerIndex(const ContainerIndex& in) :
IndexInterface<std::tuple<typename Indices::MetaType...> >(in) IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
@ -31,7 +31,7 @@ namespace MultiArrayTools
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this; return *this;
} }
*/
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) :
@ -145,7 +145,7 @@ namespace MultiArrayTools
} }
template <class... Indices> template <class... Indices>
const std::shared_ptr<typename ContainerIndex<Indices...>::RangeType>& ContainerIndex<Indices...>::range() const; std::shared_ptr<typename ContainerIndex<Indices...>::RangeType> ContainerIndex<Indices...>::range() const
{ {
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
} }

View file

@ -32,8 +32,8 @@ namespace MultiArrayTools
public: public:
ContainerIndex() = delete; ContainerIndex() = delete;
ContainerIndex(const ContainerIndex& in); //ContainerIndex(const ContainerIndex& in);
ContainerIndex& operator=(const ContainerIndex& in); //ContainerIndex& operator=(const ContainerIndex& in);
template <class MRange> template <class MRange>
ContainerIndex(const std::shared_ptr<MRange>& range); ContainerIndex(const std::shared_ptr<MRange>& range);
@ -62,7 +62,7 @@ namespace MultiArrayTools
ContainerIndex& operator()(); // -> sync; just to shorten the code ContainerIndex& operator()(); // -> sync; just to shorten the code
const std::shared_ptr<RangeType>& range() const; std::shared_ptr<RangeType> range() const;
}; };

View file

@ -544,7 +544,7 @@ namespace MultiArrayTools
template <typename T, class CRange, class Function> template <typename T, class CRange, class Function>
FunctionalMultiArray<T,CRange,Function>::FunctionalMultiArray(const std::shared_ptr<CRange>& range, FunctionalMultiArray<T,CRange,Function>::FunctionalMultiArray(const std::shared_ptr<CRange>& range,
const Function& func) : const Function& func) :
MultiArrayBase<T,CRange>(range), mFunc(func) { /*CHECK;*/ } MultiArrayBase<T,CRange>(range), mFunc(func) {}
template <typename T, class CRange, class Function> template <typename T, class CRange, class Function>
const T& FunctionalMultiArray<T,CRange,Function>::operator[](const typename CRange::IndexType& i) const const T& FunctionalMultiArray<T,CRange,Function>::operator[](const typename CRange::IndexType& i) const

View file

@ -39,14 +39,13 @@ namespace MultiArrayTools
mSecond(second), mArrayRef(ma), mIndex() mSecond(second), mArrayRef(ma), mIndex()
{ {
MultiRangeFactory<Ranges...> mrf( index->range() ); MultiRangeFactory<Ranges...> mrf( index->range() );
mIndex = mrf.create(); std::shared_ptr<MultiRange<Ranges...> > mr =
CHECK; std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
mIndex = std::make_shared<IndexType>( mr->begin() );
(*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>
@ -72,15 +71,13 @@ namespace MultiArrayTools
OperationBase<T>(), OperationTemplate<ConstOperationRoot<T,Ranges...> >(this), OperationBase<T>(), OperationTemplate<ConstOperationRoot<T,Ranges...> >(this),
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) ) 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)() ];
} }
/*********************** /***********************
@ -94,9 +91,7 @@ namespace MultiArrayTools
MutableOperationBase<T>(), OperationTemplate<OperationRoot<T,Ranges...> >(this), MutableOperationBase<T>(), OperationTemplate<OperationRoot<T,Ranges...> >(this),
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) ) 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>
@ -108,13 +103,13 @@ 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)() ];
} }
/*********************** /***********************

View file

@ -13,7 +13,8 @@ namespace MultiArrayTools
/****************** /******************
* MultiIndex * * MultiIndex *
******************/ ******************/
/*
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>::MultiIndex(const MultiIndex<Indices...>& in) : MultiIndex<Indices...>::MultiIndex(const MultiIndex<Indices...>& in) :
IndexInterface<std::tuple<typename Indices::MetaType...> >(in) IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
@ -30,15 +31,12 @@ namespace MultiArrayTools
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this; return *this;
} }
*/
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(ContainerIndex<Indices...>& ci) MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(ContainerIndex<Indices...>& ci)
{ {
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;
} }
@ -155,7 +153,7 @@ namespace MultiArrayTools
} }
template <class... Indices> template <class... Indices>
const std::shared_ptr<typename MultiIndex<Indices...>::RangeType>& MultiIndex<Indices...>::range() const std::shared_ptr<typename MultiIndex<Indices...>::RangeType> MultiIndex<Indices...>::range() const
{ {
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
} }

View file

@ -32,8 +32,8 @@ namespace MultiArrayTools
MultiIndex() = delete; 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=(ContainerIndex<Indices...>& ci); MultiIndex& operator=(ContainerIndex<Indices...>& ci);
template <class MRange> template <class MRange>
@ -65,7 +65,7 @@ namespace MultiArrayTools
virtual size_t dim() const override; virtual size_t dim() const override;
const std::shared_ptr<RangeType>& range() const; std::shared_ptr<RangeType> range() const;
}; };
/************************* /*************************

View file

@ -66,8 +66,12 @@ namespace {
MultiArray<double,CRange> res(crptr); MultiArray<double,CRange> res(crptr);
auto i = std::dynamic_pointer_cast<SRange::IndexType>( srptr->index() ); auto i = std::dynamic_pointer_cast<SRange::IndexType>( srptr->index() );
CHECK;
res.operator()<SRange>(i) = ma1.operator()<SRange>(i) + ma2.operator()<SRange>(i); res.operator()<SRange>(i) = ma1.operator()<SRange>(i) + ma2.operator()<SRange>(i);
EXPECT_EQ( fabs( res.at('a') - (2.917+8.870) ) < 0.0001, true);
EXPECT_EQ( fabs( res.at('l') - (9.436+4.790) ) < 0.0001, true );
EXPECT_EQ( fabs( res.at('f') - (0.373+8.215) ) < 0.0001, true );
EXPECT_EQ( fabs( res.at('g') - (7.192+5.063) ) < 0.0001, true );
} }
} // anonymous namspace } // anonymous namspace

View file

@ -23,10 +23,10 @@ namespace MultiArrayTools
typedef U MetaType; typedef U MetaType;
typedef SingleRange<U,TYPE> RangeType; typedef SingleRange<U,TYPE> RangeType;
DEFAULT_MEMBERS_X(SingleIndex); //DEFAULT_MEMBERS_X(SingleIndex);
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range); SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
virtual SingleIndex& operator=(size_t pos) override; virtual SingleIndex& operator=(size_t pos) override;
virtual SingleIndex& operator++() override; virtual SingleIndex& operator++() override;
virtual SingleIndex& operator--() override; virtual SingleIndex& operator--() override;