change ma templ args -> explicit subranges (compiles, unit tests work)
This commit is contained in:
parent
b50620a451
commit
f99e55d4fd
7 changed files with 239 additions and 254 deletions
|
@ -107,15 +107,15 @@ namespace MultiArrayTools
|
|||
class ContainerIndex;
|
||||
|
||||
// multi_array.h
|
||||
template <typename T, class Range>
|
||||
template <typename T, class... SRanges>
|
||||
class MultiArrayBase;
|
||||
|
||||
// multi_array.h
|
||||
template <typename T, class Range>
|
||||
template <typename T, class... SRanges>
|
||||
class MutableMultiArrayBase;
|
||||
|
||||
// multi_array.h
|
||||
template <typename T, class Range>
|
||||
template <typename T, class... SRanges>
|
||||
class MultiArray;
|
||||
|
||||
// multi_array_operation.h
|
||||
|
|
|
@ -41,21 +41,15 @@ namespace {
|
|||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef ContainerRangeFactory<SRange> CRF;
|
||||
typedef CRF::oType CRange;
|
||||
|
||||
MATest_1Dim()
|
||||
{
|
||||
swapFactory<SRF>(rfbptr, {'x', 'y', 'l', 'f', 'g'} );
|
||||
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<CRF>(rfbptr, srptr);
|
||||
crptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||
std::shared_ptr<SRange> srptr;
|
||||
std::shared_ptr<CRange> crptr;
|
||||
std::vector<double> vv = { 3.141, 2.718, 1.618, 0.693, 0.577 };
|
||||
};
|
||||
|
||||
|
@ -70,13 +64,6 @@ namespace {
|
|||
typedef MultiRangeFactory<SRange,SRange> MRF;
|
||||
typedef MRF::oType MRange;
|
||||
|
||||
typedef ContainerRangeFactory<MRange,SRange> CRF;
|
||||
typedef CRF::oType CRange;
|
||||
|
||||
typedef ContainerRangeFactory<SRange> CRF2;
|
||||
typedef CRF2::oType CRange2;
|
||||
|
||||
|
||||
MATest_MDim()
|
||||
{
|
||||
swapFactory<SRF>(rfbptr, {'x', 'y'} );
|
||||
|
@ -96,8 +83,6 @@ namespace {
|
|||
swapMFactory<MRF>(rfbptr, sr1ptr, sr2ptr);
|
||||
mrptr = std::dynamic_pointer_cast<MRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<CRF>(rfbptr, mrptr, sr3ptr);
|
||||
crptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||
|
@ -106,7 +91,6 @@ namespace {
|
|||
std::shared_ptr<SRange> sr3ptr;
|
||||
std::shared_ptr<SRange> sr4ptr;
|
||||
std::shared_ptr<MRange> mrptr;
|
||||
std::shared_ptr<CRange> crptr;
|
||||
std::vector<double> vv = { 2.917, 9.436, 0.373, 7.192, 7.315, 1.536, 4.892, 0.280,
|
||||
8.870, 4.790, 8.215, 5.063, 1.530, 3.084, 1.609, 4.847,
|
||||
8.175, 0.112, 6.712, 6.408, 1.959, 0.331, 4.209, 2.951 };
|
||||
|
@ -114,7 +98,7 @@ namespace {
|
|||
|
||||
TEST_F(MATest_1Dim, SimpleCall)
|
||||
{
|
||||
MultiArray<double,MATest_1Dim::CRange> ma(crptr, vv);
|
||||
MultiArray<double,MATest_1Dim::SRange> ma(srptr, vv);
|
||||
EXPECT_EQ( ma.size(), 5);
|
||||
EXPECT_EQ( ma.isConst(), false);
|
||||
EXPECT_EQ( ma.isSlice(), false);
|
||||
|
@ -131,7 +115,7 @@ namespace {
|
|||
TEST_F(MATest_1Dim, ForLoop)
|
||||
{
|
||||
std::vector<double> v2 = { 0.693 , 2.718, 3.141, 1.618, 9.98 };
|
||||
MultiArray<double,MATest_1Dim::CRange> ma(crptr, std::move( v2 ) );
|
||||
MultiArray<double,MATest_1Dim::SRange> ma(srptr, std::move( v2 ) );
|
||||
size_t cnt = 0;
|
||||
for(auto el: ma){
|
||||
|
||||
|
@ -157,14 +141,12 @@ namespace {
|
|||
{
|
||||
swapFactory<SRF>( rfbptr, { 'a', 'c', 'e', 'g', 'i' } );
|
||||
std::shared_ptr<SRange> sr2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
swapMFactory<CRF>( rfbptr, sr2 );
|
||||
std::shared_ptr<CRange> cr2 = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||
|
||||
MultiArray<double,MATest_1Dim::CRange> ma(crptr, vv);
|
||||
MultiArray<double,MATest_1Dim::SRange> ma(srptr, vv);
|
||||
auto i = ma.beginIndex();
|
||||
EXPECT_EQ( ma[ i.at('x') ], 3.141);
|
||||
|
||||
auto ma2 = ma.format( cr2 );
|
||||
auto ma2 = ma.format( sr2 );
|
||||
auto j = ma2.beginIndex();
|
||||
|
||||
EXPECT_EQ( ma[ j.at('a') ], 3.141);
|
||||
|
@ -176,7 +158,7 @@ namespace {
|
|||
|
||||
TEST_F(MATest_MDim, SimpleCall)
|
||||
{
|
||||
MultiArray<double,MATest_MDim::CRange> ma(crptr, vv);
|
||||
MultiArray<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
|
||||
EXPECT_EQ( ma.size(), 24 );
|
||||
EXPECT_EQ( ma.range()->dim(), 2 );
|
||||
|
||||
|
@ -193,7 +175,7 @@ namespace {
|
|||
|
||||
TEST_F(MATest_MDim, ReFormat)
|
||||
{
|
||||
MultiArray<double,MATest_MDim::CRange> ma(crptr, vv);
|
||||
MultiArray<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
|
||||
|
||||
auto ma2 = ma.format( sr4ptr );
|
||||
auto i = ma2.beginIndex();
|
||||
|
|
|
@ -8,136 +8,137 @@ namespace MultiArrayTools
|
|||
* MultiArrayBase::const_iterator *
|
||||
**************************************/
|
||||
|
||||
template <typename T, class CRange>
|
||||
MultiArrayBase<T,CRange>::const_iterator::const_iterator(const MultiArrayBase<T,CRange>& ma):
|
||||
template <typename T, class... SRanges>
|
||||
MultiArrayBase<T,SRanges...>::const_iterator::const_iterator(const MultiArrayBase<T,SRanges...>& ma):
|
||||
mMAPtr(&ma), mPos(0) { }
|
||||
|
||||
template <typename T, class CRange>
|
||||
MultiArrayBase<T,CRange>::const_iterator::const_iterator(const MultiArrayBase<T,CRange>& ma,
|
||||
template <typename T, class... SRanges>
|
||||
MultiArrayBase<T,SRanges...>::const_iterator::const_iterator(const MultiArrayBase<T,SRanges...>& ma,
|
||||
const typename CRange::IndexType& index):
|
||||
mMAPtr(&ma), mPos(index.pos()) { }
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator==(const const_iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::const_iterator::operator==(const const_iterator& it) const
|
||||
{
|
||||
return mMAPtr == it.mMAPtr and mPos == it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator!=(const const_iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::const_iterator::operator!=(const const_iterator& it) const
|
||||
{
|
||||
return mMAPtr != it.mMAPtr or mPos != it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const T& MultiArrayBase<T,CRange>::const_iterator::operator*() const
|
||||
template <typename T, class... SRanges>
|
||||
const T& MultiArrayBase<T,SRanges...>::const_iterator::operator*() const
|
||||
{
|
||||
return mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T const* MultiArrayBase<T,CRange>::const_iterator::operator->() const
|
||||
template <typename T, class... SRanges>
|
||||
T const* MultiArrayBase<T,SRanges...>::const_iterator::operator->() const
|
||||
{
|
||||
return &mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator& MultiArrayBase<T,CRange>::const_iterator::operator++()
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator& MultiArrayBase<T,SRanges...>::const_iterator::operator++()
|
||||
{
|
||||
++mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::const_iterator::operator++(int)
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator MultiArrayBase<T,SRanges...>::const_iterator::operator++(int)
|
||||
{
|
||||
const_iterator tmp(*this);
|
||||
++mPos;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator& MultiArrayBase<T,CRange>::const_iterator::operator--()
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator& MultiArrayBase<T,SRanges...>::const_iterator::operator--()
|
||||
{
|
||||
--mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::const_iterator::operator--(int)
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator MultiArrayBase<T,SRanges...>::const_iterator::operator--(int)
|
||||
{
|
||||
const_iterator tmp(*this);
|
||||
--mPos;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator& MultiArrayBase<T,CRange>::const_iterator::operator+=(int diff)
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator& MultiArrayBase<T,SRanges...>::const_iterator::operator+=(int diff)
|
||||
{
|
||||
mPos += diff;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator& MultiArrayBase<T,CRange>::const_iterator::operator-=(int diff)
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator& MultiArrayBase<T,SRanges...>::const_iterator::operator-=(int diff)
|
||||
{
|
||||
mPos -= diff;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::const_iterator::operator+(int num) const
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator MultiArrayBase<T,SRanges...>::const_iterator::operator+(int num) const
|
||||
{
|
||||
const_iterator tmp(*this);
|
||||
tmp += num;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::const_iterator::operator-(int num) const
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator MultiArrayBase<T,SRanges...>::const_iterator::operator-(int num) const
|
||||
{
|
||||
const_iterator tmp(*this);
|
||||
tmp -= num;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
int MultiArrayBase<T,CRange>::const_iterator::operator-(const const_iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
int MultiArrayBase<T,SRanges...>::const_iterator::operator-(const const_iterator& it) const
|
||||
{
|
||||
return mPos - it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const T& MultiArrayBase<T,CRange>::const_iterator::operator[](int num) const
|
||||
template <typename T, class... SRanges>
|
||||
const T& MultiArrayBase<T,SRanges...>::const_iterator::operator[](int num) const
|
||||
{
|
||||
return *(operator+(num));
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator<(const const_iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::const_iterator::operator<(const const_iterator& it) const
|
||||
{
|
||||
return mPos < it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator>(const const_iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::const_iterator::operator>(const const_iterator& it) const
|
||||
{
|
||||
return mPos > it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator<=(const const_iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::const_iterator::operator<=(const const_iterator& it) const
|
||||
{
|
||||
return mPos <= it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator>=(const const_iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::const_iterator::operator>=(const const_iterator& it) const
|
||||
{
|
||||
return mPos >= it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename CRange::IndexType MultiArrayBase<T,CRange>::const_iterator::index() const
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::IndexType
|
||||
MultiArrayBase<T,SRanges...>::const_iterator::index() const
|
||||
{
|
||||
auto i = mMAPtr->beginIndex();
|
||||
i = mPos;
|
||||
|
@ -148,61 +149,67 @@ namespace MultiArrayTools
|
|||
* MultiArrayBase *
|
||||
**********************/
|
||||
|
||||
template <typename T, class CRange>
|
||||
MultiArrayBase<T,CRange>::MultiArrayBase(const std::shared_ptr<CRange>& range) : mRange(range) {}
|
||||
template <typename T, class... SRanges>
|
||||
MultiArrayBase<T,SRanges...>::MultiArrayBase(const std::shared_ptr<SRanges>&... ranges)
|
||||
{
|
||||
ContainerRangeFactory<SRanges...> crf(ranges...);
|
||||
mRange = std::dynamic_pointer_cast<ContainerRange<SRanges...> >( crf.create() );
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
size_t MultiArrayBase<T,CRange>::size() const
|
||||
template <typename T, class... SRanges>
|
||||
size_t MultiArrayBase<T,SRanges...>::size() const
|
||||
{
|
||||
return mRange->size();
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::begin() const
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator MultiArrayBase<T,SRanges...>::begin() const
|
||||
{
|
||||
return const_iterator(*this, beginIndex());
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::end() const
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::const_iterator MultiArrayBase<T,SRanges...>::end() const
|
||||
{
|
||||
return const_iterator(*this, endIndex());
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename CRange::IndexType MultiArrayBase<T,CRange>::beginIndex() const
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::IndexType
|
||||
MultiArrayBase<T,SRanges...>::beginIndex() const
|
||||
{
|
||||
return mRange->begin();
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename CRange::IndexType MultiArrayBase<T,CRange>::endIndex() const
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::IndexType
|
||||
MultiArrayBase<T,SRanges...>::endIndex() const
|
||||
{
|
||||
return mRange->end();
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const std::shared_ptr<CRange>& MultiArrayBase<T,CRange>::range() const
|
||||
template <typename T, class... SRanges>
|
||||
const std::shared_ptr<typename MultiArrayBase<T,SRanges...>::CRange>&
|
||||
MultiArrayBase<T,SRanges...>::range() const
|
||||
{
|
||||
return mRange;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::isConst() const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::isConst() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
template <class... SubRanges>
|
||||
ConstOperationRoot<T,SubRanges...>
|
||||
MultiArrayBase<T,CRange>::operator()(std::shared_ptr<typename SubRanges::IndexType>&... inds) const
|
||||
template <typename T, class... SRanges>
|
||||
ConstOperationRoot<T,SRanges...>
|
||||
MultiArrayBase<T,SRanges...>::operator()(std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
||||
{
|
||||
return ConstOperationRoot<T,SubRanges...>(*this, inds...);
|
||||
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::isInit() const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::isInit() const
|
||||
{
|
||||
return mInit;
|
||||
}
|
||||
|
@ -211,156 +218,157 @@ namespace MultiArrayTools
|
|||
* MutableMultiArrayBase::iterator *
|
||||
****************************************/
|
||||
|
||||
template <typename T, class CRange>
|
||||
MutableMultiArrayBase<T,CRange>::iterator::iterator(MutableMultiArrayBase<T,CRange>& ma):
|
||||
template <typename T, class... SRanges>
|
||||
MutableMultiArrayBase<T,SRanges...>::iterator::iterator(MutableMultiArrayBase<T,SRanges...>& ma):
|
||||
mMAPtr(&ma), mPos(0)
|
||||
{ }
|
||||
|
||||
template <typename T, class CRange>
|
||||
MutableMultiArrayBase<T,CRange>::iterator::iterator(MutableMultiArrayBase<T,CRange>& ma,
|
||||
template <typename T, class... SRanges>
|
||||
MutableMultiArrayBase<T,SRanges...>::iterator::iterator(MutableMultiArrayBase<T,SRanges...>& ma,
|
||||
const typename CRange::IndexType& index):
|
||||
mMAPtr(&ma), mPos(index.pos())
|
||||
{ }
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator==(const iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MutableMultiArrayBase<T,SRanges...>::iterator::operator==(const iterator& it) const
|
||||
{
|
||||
return mMAPtr == it.mMAPtr and mPos == it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator!=(const iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MutableMultiArrayBase<T,SRanges...>::iterator::operator!=(const iterator& it) const
|
||||
{
|
||||
return mMAPtr != it.mMAPtr or mPos != it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const T& MutableMultiArrayBase<T,CRange>::iterator::operator*() const
|
||||
template <typename T, class... SRanges>
|
||||
const T& MutableMultiArrayBase<T,SRanges...>::iterator::operator*() const
|
||||
{
|
||||
return mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T const* MutableMultiArrayBase<T,CRange>::iterator::operator->() const
|
||||
template <typename T, class... SRanges>
|
||||
T const* MutableMultiArrayBase<T,SRanges...>::iterator::operator->() const
|
||||
{
|
||||
return &mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T& MutableMultiArrayBase<T,CRange>::iterator::operator*()
|
||||
template <typename T, class... SRanges>
|
||||
T& MutableMultiArrayBase<T,SRanges...>::iterator::operator*()
|
||||
{
|
||||
return mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T* MutableMultiArrayBase<T,CRange>::iterator::operator->()
|
||||
template <typename T, class... SRanges>
|
||||
T* MutableMultiArrayBase<T,SRanges...>::iterator::operator->()
|
||||
{
|
||||
return &mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator& MutableMultiArrayBase<T,CRange>::iterator::operator++()
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator& MutableMultiArrayBase<T,SRanges...>::iterator::operator++()
|
||||
{
|
||||
++mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::iterator::operator++(int)
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator MutableMultiArrayBase<T,SRanges...>::iterator::operator++(int)
|
||||
{
|
||||
iterator tmp(*this);
|
||||
++mPos;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator& MutableMultiArrayBase<T,CRange>::iterator::operator--()
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator& MutableMultiArrayBase<T,SRanges...>::iterator::operator--()
|
||||
{
|
||||
--mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::iterator::operator--(int)
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator MutableMultiArrayBase<T,SRanges...>::iterator::operator--(int)
|
||||
{
|
||||
iterator tmp(*this);
|
||||
--mPos;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator& MutableMultiArrayBase<T,CRange>::iterator::operator+=(int diff)
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator& MutableMultiArrayBase<T,SRanges...>::iterator::operator+=(int diff)
|
||||
{
|
||||
mPos += diff;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator& MutableMultiArrayBase<T,CRange>::iterator::operator-=(int diff)
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator& MutableMultiArrayBase<T,SRanges...>::iterator::operator-=(int diff)
|
||||
{
|
||||
mPos -= diff;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::iterator::operator+(int num) const
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator MutableMultiArrayBase<T,SRanges...>::iterator::operator+(int num) const
|
||||
{
|
||||
iterator tmp(*this);
|
||||
tmp += num;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::iterator::operator-(int num) const
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator MutableMultiArrayBase<T,SRanges...>::iterator::operator-(int num) const
|
||||
{
|
||||
iterator tmp(*this);
|
||||
tmp -= num;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
int MutableMultiArrayBase<T,CRange>::iterator::operator-(const iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
int MutableMultiArrayBase<T,SRanges...>::iterator::operator-(const iterator& it) const
|
||||
{
|
||||
return mPos - it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const T& MutableMultiArrayBase<T,CRange>::iterator::operator[](int num) const
|
||||
template <typename T, class... SRanges>
|
||||
const T& MutableMultiArrayBase<T,SRanges...>::iterator::operator[](int num) const
|
||||
{
|
||||
return *(operator+(num));
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T& MutableMultiArrayBase<T,CRange>::iterator::operator[](int num)
|
||||
template <typename T, class... SRanges>
|
||||
T& MutableMultiArrayBase<T,SRanges...>::iterator::operator[](int num)
|
||||
{
|
||||
return *(operator+(num));
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator<(const iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MutableMultiArrayBase<T,SRanges...>::iterator::operator<(const iterator& it) const
|
||||
{
|
||||
return mPos < it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator>(const iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MutableMultiArrayBase<T,SRanges...>::iterator::operator>(const iterator& it) const
|
||||
{
|
||||
return mPos > it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator<=(const iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MutableMultiArrayBase<T,SRanges...>::iterator::operator<=(const iterator& it) const
|
||||
{
|
||||
return mPos <= it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator>=(const iterator& it) const
|
||||
template <typename T, class... SRanges>
|
||||
bool MutableMultiArrayBase<T,SRanges...>::iterator::operator>=(const iterator& it) const
|
||||
{
|
||||
return mPos >= it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename CRange::IndexType MutableMultiArrayBase<T,CRange>::iterator::index() const
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::IndexType
|
||||
MutableMultiArrayBase<T,SRanges...>::iterator::index() const
|
||||
{
|
||||
auto i = mMAPtr->beginIndex();
|
||||
i = mPos;
|
||||
|
@ -371,51 +379,50 @@ namespace MultiArrayTools
|
|||
* MutableMultiArrayBase *
|
||||
******************************/
|
||||
|
||||
template <typename T, class CRange>
|
||||
MutableMultiArrayBase<T,CRange>::MutableMultiArrayBase(const std::shared_ptr<CRange>& range) :
|
||||
MultiArrayBase<T,CRange>(range) {}
|
||||
template <typename T, class... SRanges>
|
||||
MutableMultiArrayBase<T,SRanges...>::MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges) :
|
||||
MultiArrayBase<T,SRanges...>(ranges...) {}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::begin()
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator MutableMultiArrayBase<T,SRanges...>::begin()
|
||||
{
|
||||
return iterator(*this, MAB::beginIndex());
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::end()
|
||||
template <typename T, class... SRanges>
|
||||
typename MutableMultiArrayBase<T,SRanges...>::iterator MutableMultiArrayBase<T,SRanges...>::end()
|
||||
{
|
||||
return iterator(*this, MAB::endIndex());
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::isConst() const
|
||||
template <typename T, class... SRanges>
|
||||
bool MutableMultiArrayBase<T,SRanges...>::isConst() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
template <class... SubRanges>
|
||||
OperationRoot<T,SubRanges...>
|
||||
MutableMultiArrayBase<T,CRange>::operator()(std::shared_ptr<typename SubRanges::IndexType>&... inds)
|
||||
template <typename T, class... SRanges>
|
||||
OperationRoot<T,SRanges...>
|
||||
MutableMultiArrayBase<T,SRanges...>::operator()(std::shared_ptr<typename SRanges::IndexType>&... inds)
|
||||
{
|
||||
return OperationRoot<T,SubRanges...>(*this, inds...);
|
||||
return OperationRoot<T,SRanges...>(*this, inds...);
|
||||
}
|
||||
|
||||
/*******************
|
||||
* MultiArray *
|
||||
*******************/
|
||||
|
||||
template <typename T, class CRange>
|
||||
MultiArray<T,CRange>::MultiArray(const std::shared_ptr<CRange>& range) :
|
||||
MutableMultiArrayBase<T,CRange>(range),
|
||||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges) :
|
||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
||||
mCont(MAB::mRange->size())
|
||||
{
|
||||
MAB::mInit = true;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
MultiArray<T,CRange>::MultiArray(const std::shared_ptr<CRange>& range, const std::vector<T>& vec) :
|
||||
MutableMultiArrayBase<T,CRange>(range),
|
||||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, const std::vector<T>& vec) :
|
||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
||||
mCont(vec)
|
||||
{
|
||||
MAB::mInit = true;
|
||||
|
@ -424,9 +431,9 @@ namespace MultiArrayTools
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
MultiArray<T,CRange>::MultiArray(const std::shared_ptr<CRange>& range, std::vector<T>&& vec) :
|
||||
MutableMultiArrayBase<T,CRange>(range),
|
||||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, std::vector<T>&& vec) :
|
||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
||||
mCont(vec)
|
||||
{
|
||||
MAB::mInit = true;
|
||||
|
@ -434,11 +441,11 @@ namespace MultiArrayTools
|
|||
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
/*
|
||||
template <typename T, class... SRanges>
|
||||
template <class Range2, class Range3>
|
||||
MultiArray<T,CRange>::MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in) :
|
||||
MutableMultiArrayBase<T,CRange>(merge(in.range(), in[ in.beginIndex() ].range()))
|
||||
MultiArray<T,SRanges...>::MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in) :
|
||||
MutableMultiArrayBase<T,SRanges...>(merge(in.range(), in[ in.beginIndex() ].range()))
|
||||
// assert that Range2 has always same extension
|
||||
{
|
||||
MAB::mInit = true;
|
||||
|
@ -448,11 +455,11 @@ namespace MultiArrayTools
|
|||
}
|
||||
assert(mCont.size() == MAB::mRange->size());
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
template <typename T, class CRange>
|
||||
template <typename T, class... SRanges>
|
||||
template <class Range2, class Range3>
|
||||
MultiArray<T,CRange>& MultiArray<T,CRange>::operator=(const MultiArray<MultiArray<T,Range2>,Range3> in)
|
||||
MultiArray<T,SRanges...>& MultiArray<T,SRanges...>::operator=(const MultiArray<MultiArray<T,Range2>,Range3> in)
|
||||
{
|
||||
MAB::mRange.reset(new Range(merge(in.range(), in[ in.beginIndex() ].range())));
|
||||
// assert that Range2 has always same extension
|
||||
|
@ -464,65 +471,64 @@ namespace MultiArrayTools
|
|||
return *this;
|
||||
} */
|
||||
|
||||
template <typename T, class CRange>
|
||||
T& MultiArray<T,CRange>::operator[](const typename CRange::IndexType& i)
|
||||
template <typename T, class... SRanges>
|
||||
T& MultiArray<T,SRanges...>::operator[](const typename CRange::IndexType& i)
|
||||
{
|
||||
return mCont[ i.pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const T& MultiArray<T,CRange>::operator[](const typename CRange::IndexType& i) const
|
||||
template <typename T, class... SRanges>
|
||||
const T& MultiArray<T,SRanges...>::operator[](const typename CRange::IndexType& i) const
|
||||
{
|
||||
return mCont[ i.pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T& MultiArray<T,CRange>::at(const typename CRange::IndexType::MetaType& meta)
|
||||
template <typename T, class... SRanges>
|
||||
T& MultiArray<T,SRanges...>::at(const typename CRange::IndexType::MetaType& meta)
|
||||
{
|
||||
return mCont[ MAB::beginIndex().at(meta).pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const T& MultiArray<T,CRange>::at(const typename CRange::IndexType::MetaType& meta) const
|
||||
template <typename T, class... SRanges>
|
||||
const T& MultiArray<T,SRanges...>::at(const typename CRange::IndexType::MetaType& meta) const
|
||||
{
|
||||
return mCont[ MAB::beginIndex().at(meta).pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArray<T,CRange>::isConst() const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArray<T,SRanges...>::isConst() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArray<T,CRange>::isSlice() const
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArray<T,SRanges...>::isSlice() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
template <class Range2>
|
||||
MultiArray<T,Range2> MultiArray<T,CRange>::format(const std::shared_ptr<Range2>& nr)
|
||||
template <typename T, class... SRanges>
|
||||
template <class... SRanges2>
|
||||
MultiArray<T,SRanges2...> MultiArray<T,SRanges...>::format(const std::shared_ptr<SRanges2>&... nrs)
|
||||
{
|
||||
assert(MAB::mRange->size() == nr->size());
|
||||
return MultiArray<T,Range2>( nr, std::move(mCont) );
|
||||
return MultiArray<T,SRanges2...>( nrs... , std::move(mCont) );
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const T* MultiArray<T,CRange>::data() const
|
||||
template <typename T, class... SRanges>
|
||||
const T* MultiArray<T,SRanges...>::data() const
|
||||
{
|
||||
return mCont.data();
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T* MultiArray<T,CRange>::data()
|
||||
template <typename T, class... SRanges>
|
||||
T* MultiArray<T,SRanges...>::data()
|
||||
{
|
||||
return mCont.data();
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename T, class CRange>
|
||||
void MultiArray<T,CRange>::manipulate(ManipulatorBase<T>& mb,
|
||||
template <typename T, class... SRanges>
|
||||
void MultiArray<T,SRanges...>::manipulate(ManipulatorBase<T>& mb,
|
||||
const typename Range::IndexType& manBegin,
|
||||
const typename Range::IndexType& manEnd)
|
||||
{
|
||||
|
@ -539,28 +545,28 @@ namespace MultiArrayTools
|
|||
/*
|
||||
template <typename T, class Range, class Function>
|
||||
FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range) :
|
||||
MultiArrayBase<T,CRange>(range), mFunc() {}
|
||||
MultiArrayBase<T,SRanges...>(range), mFunc() {}
|
||||
*/
|
||||
template <typename T, class CRange, class Function>
|
||||
FunctionalMultiArray<T,CRange,Function>::FunctionalMultiArray(const std::shared_ptr<CRange>& range,
|
||||
template <typename T, class Function, class... SRanges>
|
||||
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges,
|
||||
const Function& func) :
|
||||
MultiArrayBase<T,CRange>(range), mFunc(func) {}
|
||||
MultiArrayBase<T,SRanges...>(ranges...), mFunc(func) {}
|
||||
|
||||
template <typename T, class CRange, class Function>
|
||||
const T& FunctionalMultiArray<T,CRange,Function>::operator[](const typename CRange::IndexType& i) const
|
||||
template <typename T, class Function, class... SRanges>
|
||||
const T& FunctionalMultiArray<T,Function,SRanges...>::operator[](const typename CRange::IndexType& i) const
|
||||
{
|
||||
mVal = mFunc(i);
|
||||
return mVal;
|
||||
}
|
||||
|
||||
template <typename T, class CRange, class Function>
|
||||
bool FunctionalMultiArray<T,CRange,Function>::isConst() const
|
||||
template <typename T, class Function, class... SRanges>
|
||||
bool FunctionalMultiArray<T,Function,SRanges...>::isConst() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, class CRange, class Function>
|
||||
bool FunctionalMultiArray<T,CRange,Function>::isSlice() const
|
||||
template <typename T, class Function, class... SRanges>
|
||||
bool FunctionalMultiArray<T,Function,SRanges...>::isSlice() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,14 @@ namespace MultiArrayTools
|
|||
{
|
||||
|
||||
// Explicitely specify subranges in template argument !!!
|
||||
template <typename T, class CRange>
|
||||
template <typename T, class... SRanges>
|
||||
class MultiArrayBase
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T value_type;
|
||||
typedef ContainerRange<SRanges...> CRange;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
class const_iterator : public std::iterator<std::random_access_iterator_tag,T>
|
||||
{
|
||||
|
@ -63,15 +65,15 @@ namespace MultiArrayTools
|
|||
bool operator>=(const const_iterator& it) const;
|
||||
|
||||
// Multi Array specific:
|
||||
typename CRange::IndexType index() const;
|
||||
|
||||
typename ContainerRange<SRanges...>::IndexType index() const;
|
||||
|
||||
protected:
|
||||
MultiArrayBase const* mMAPtr = nullptr;
|
||||
size_t mPos;
|
||||
};
|
||||
|
||||
DEFAULT_MEMBERS(MultiArrayBase);
|
||||
MultiArrayBase(const std::shared_ptr<CRange>& range);
|
||||
MultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
||||
|
||||
virtual ~MultiArrayBase() = default;
|
||||
|
||||
|
@ -86,15 +88,14 @@ namespace MultiArrayTools
|
|||
virtual const_iterator begin() const;
|
||||
virtual const_iterator end() const;
|
||||
|
||||
virtual typename CRange::IndexType beginIndex() const;
|
||||
virtual typename CRange::IndexType endIndex() const;
|
||||
virtual IndexType beginIndex() const;
|
||||
virtual IndexType endIndex() const;
|
||||
|
||||
virtual const std::shared_ptr<CRange>& range() const;
|
||||
|
||||
virtual bool isConst() const;
|
||||
|
||||
template <class... SubRanges>
|
||||
ConstOperationRoot<T,SubRanges...> operator()(std::shared_ptr<typename SubRanges::IndexType>&... inds) const;
|
||||
ConstOperationRoot<T,SRanges...> operator()(std::shared_ptr<typename SRanges::IndexType>&... inds) const;
|
||||
|
||||
virtual bool isInit() const;
|
||||
|
||||
|
@ -104,13 +105,14 @@ namespace MultiArrayTools
|
|||
|
||||
};
|
||||
|
||||
template <typename T, class CRange>
|
||||
class MutableMultiArrayBase : public MultiArrayBase<T,CRange>
|
||||
template <typename T, class... SRanges>
|
||||
class MutableMultiArrayBase : public MultiArrayBase<T,SRanges...>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator;
|
||||
typedef MultiArrayBase<T,CRange> MAB;
|
||||
typedef ContainerRange<SRanges...> CRange;
|
||||
typedef typename MultiArrayBase<T,SRanges...>::const_iterator const_iterator;
|
||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
class iterator : public std::iterator<std::random_access_iterator_tag,T>,
|
||||
|
@ -163,7 +165,7 @@ namespace MultiArrayTools
|
|||
|
||||
|
||||
DEFAULT_MEMBERS(MutableMultiArrayBase);
|
||||
MutableMultiArrayBase(const std::shared_ptr<CRange>& range);
|
||||
MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
||||
|
||||
virtual T& operator[](const IndexType& i) = 0;
|
||||
virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0;
|
||||
|
@ -175,27 +177,27 @@ namespace MultiArrayTools
|
|||
|
||||
virtual bool isConst() const override;
|
||||
|
||||
template <class... SubRanges>
|
||||
OperationRoot<T,SubRanges...> operator()(std::shared_ptr<typename SubRanges::IndexType>&... inds);
|
||||
OperationRoot<T,SRanges...> operator()(std::shared_ptr<typename SRanges::IndexType>&... inds);
|
||||
};
|
||||
|
||||
template <typename T, class CRange>
|
||||
class MultiArray : public MutableMultiArrayBase<T,CRange>
|
||||
template <typename T, class... SRanges>
|
||||
class MultiArray : public MutableMultiArrayBase<T,SRanges...>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef MultiArrayBase<T,CRange> MAB;
|
||||
typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator;
|
||||
typedef typename MutableMultiArrayBase<T,CRange>::iterator iterator;
|
||||
typedef ContainerRange<SRanges...> CRange;
|
||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
||||
typedef typename MultiArrayBase<T,SRanges...>::const_iterator const_iterator;
|
||||
typedef typename MutableMultiArrayBase<T,SRanges...>::iterator iterator;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
DEFAULT_MEMBERS(MultiArray);
|
||||
MultiArray(const std::shared_ptr<CRange>& range);
|
||||
MultiArray(const std::shared_ptr<CRange>& range, const std::vector<T>& vec);
|
||||
MultiArray(const std::shared_ptr<CRange>& range, std::vector<T>&& vec);
|
||||
MultiArray(const std::shared_ptr<SRanges>&... ranges);
|
||||
MultiArray(const std::shared_ptr<SRanges>&... ranges, const std::vector<T>& vec);
|
||||
MultiArray(const std::shared_ptr<SRanges>&... ranges, std::vector<T>&& vec);
|
||||
|
||||
template <class Range2, class Range3>
|
||||
MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
||||
// template <class Range2, class Range3>
|
||||
// MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
||||
|
||||
// implement contstructor using FunctionalMultiArray as Input !!!
|
||||
|
||||
|
@ -210,8 +212,8 @@ namespace MultiArrayTools
|
|||
virtual bool isConst() const override;
|
||||
virtual bool isSlice() const override;
|
||||
|
||||
template <class Range2>
|
||||
MultiArray<T,Range2> format(const std::shared_ptr<Range2>& nr); // reformat array using 'nr' which in
|
||||
template <class... SRanges2>
|
||||
MultiArray<T,SRanges2...> format(const std::shared_ptr<SRanges2>&... nrs); // reformat array using 'nr' which in
|
||||
// total must have the same size as mRange
|
||||
|
||||
const T* data() const override;
|
||||
|
@ -221,24 +223,26 @@ namespace MultiArrayTools
|
|||
// const typename CRange::IndexType& manBegin,
|
||||
// const typename CRange::IndexType& manEnd);
|
||||
|
||||
template <typename U, class RangeX>
|
||||
template <typename U, class... SRanges2>
|
||||
friend class MultiArray;
|
||||
|
||||
private:
|
||||
std::vector<T> mCont;
|
||||
};
|
||||
|
||||
template <typename T, class CRange, class Function>
|
||||
class FunctionalMultiArray : public MultiArrayBase<T,CRange>
|
||||
template <typename T, class Function, class... SRanges>
|
||||
class FunctionalMultiArray : public MultiArrayBase<T,SRanges...>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ContainerRange<SRanges...> CRange;
|
||||
typedef MultiArrayBase<T,CRange> MAB;
|
||||
typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
DEFAULT_MEMBERS(FunctionalMultiArray);
|
||||
//FunctionalMultiArray(const CRange& range);
|
||||
FunctionalMultiArray(const std::shared_ptr<CRange>& range, const Function& func);
|
||||
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const Function& func);
|
||||
|
||||
virtual const T& operator[](const IndexType& i) const override;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... Ranges>
|
||||
OperationMaster<T,Ranges...>::
|
||||
OperationMaster(MutableMultiArrayBase<T,CRange>& ma, const OperationBase<T>& second,
|
||||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OperationBase<T>& second,
|
||||
std::shared_ptr<typename CRange::IndexType>& index) :
|
||||
mSecond(second), mArrayRef(ma), mIndex()
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... Ranges>
|
||||
ConstOperationRoot<T,Ranges...>::
|
||||
ConstOperationRoot(const MultiArrayBase<T,CRange>& ma,
|
||||
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||
OperationBase<T>(), OperationTemplate<ConstOperationRoot<T,Ranges...> >(this),
|
||||
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
|
||||
|
@ -86,7 +86,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... Ranges>
|
||||
OperationRoot<T,Ranges...>::
|
||||
OperationRoot(MutableMultiArrayBase<T,CRange>& ma,
|
||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||
MutableOperationBase<T>(), OperationTemplate<OperationRoot<T,Ranges...> >(this),
|
||||
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace MultiArrayTools
|
|||
typedef ContainerRange<Ranges...> CRange;
|
||||
typedef typename MultiRange<Ranges...>::IndexType IndexType;
|
||||
|
||||
OperationMaster(MutableMultiArrayBase<T,CRange>& ma, const OperationBase<T>& second,
|
||||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OperationBase<T>& second,
|
||||
std::shared_ptr<typename CRange::IndexType>& index);
|
||||
|
||||
virtual T& get() override;
|
||||
|
@ -80,7 +80,7 @@ namespace MultiArrayTools
|
|||
|
||||
//void performAssignment(const OperationBase<T>& in);
|
||||
OperationBase<T> const& mSecond;
|
||||
MutableMultiArrayBase<T,CRange>& mArrayRef;
|
||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
};
|
||||
|
||||
|
@ -96,14 +96,14 @@ namespace MultiArrayTools
|
|||
typedef ContainerRange<Ranges...> CRange;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
ConstOperationRoot(const MultiArrayBase<T,CRange>& ma,
|
||||
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
virtual const T& get() const override;
|
||||
|
||||
protected:
|
||||
|
||||
MultiArrayBase<T,CRange> const& mArrayRef;
|
||||
MultiArrayBase<T,Ranges...> const& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
};
|
||||
|
||||
|
@ -118,7 +118,7 @@ namespace MultiArrayTools
|
|||
typedef ContainerRange<Ranges...> CRange;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
OperationRoot(MutableMultiArrayBase<T,CRange>& ma,
|
||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
OperationMaster<T,Ranges...> operator=(const OperationBase<T>& in);
|
||||
|
@ -128,7 +128,7 @@ namespace MultiArrayTools
|
|||
|
||||
protected:
|
||||
|
||||
MutableMultiArrayBase<T,CRange>& mArrayRef;
|
||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,33 +40,26 @@ namespace {
|
|||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef ContainerRangeFactory<SRange> CRF;
|
||||
typedef CRF::oType CRange;
|
||||
|
||||
OpTest_1Dim()
|
||||
{
|
||||
swapFactory<SRF>(rfbptr, {'a', 'l', 'f', 'g'} );
|
||||
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<CRF>(rfbptr, srptr);
|
||||
crptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||
std::shared_ptr<SRange> srptr;
|
||||
std::shared_ptr<CRange> crptr;
|
||||
std::vector<double> v1 = { 2.917, 9.436, 0.373, 7.192 };
|
||||
std::vector<double> v2 = { 8.870, 4.790, 8.215, 5.063 };
|
||||
};
|
||||
|
||||
TEST_F(OpTest_1Dim, ExecOp)
|
||||
{
|
||||
MultiArray<double,CRange> ma1(crptr, v1);
|
||||
MultiArray<double,CRange> ma2(crptr, v2);
|
||||
MultiArray<double,CRange> res(crptr);
|
||||
MultiArray<double,SRange> ma1(srptr, v1);
|
||||
MultiArray<double,SRange> ma2(srptr, v2);
|
||||
MultiArray<double,SRange> res(srptr);
|
||||
|
||||
auto i = std::dynamic_pointer_cast<SRange::IndexType>( srptr->index() );
|
||||
res.operator()<SRange>(i) = ma1.operator()<SRange>(i) + ma2.operator()<SRange>(i);
|
||||
res(i) = ma1(i) + ma2(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 );
|
||||
|
|
Loading…
Reference in a new issue