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

View file

@ -32,8 +32,8 @@ namespace MultiArrayTools
public:
ContainerIndex() = delete;
ContainerIndex(const ContainerIndex& in);
ContainerIndex& operator=(const ContainerIndex& in);
//ContainerIndex(const ContainerIndex& in);
//ContainerIndex& operator=(const ContainerIndex& in);
template <class MRange>
ContainerIndex(const std::shared_ptr<MRange>& range);
@ -62,7 +62,7 @@ namespace MultiArrayTools
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>
FunctionalMultiArray<T,CRange,Function>::FunctionalMultiArray(const std::shared_ptr<CRange>& range,
const Function& func) :
MultiArrayBase<T,CRange>(range), mFunc(func) { /*CHECK;*/ }
MultiArrayBase<T,CRange>(range), mFunc(func) {}
template <typename T, class CRange, class Function>
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()
{
MultiRangeFactory<Ranges...> mrf( index->range() );
mIndex = mrf.create();
CHECK;
std::shared_ptr<MultiRange<Ranges...> > mr =
std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
mIndex = std::make_shared<IndexType>( mr->begin() );
(*mIndex) = *index;
CHECK;
for(*mIndex = 0; mIndex->pos() != mIndex->max(); ++(*mIndex)){
get() = mSecond.get();
}
CHECK;
}
template <typename T, class... Ranges>
@ -72,15 +71,13 @@ namespace MultiArrayTools
OperationBase<T>(), OperationTemplate<ConstOperationRoot<T,Ranges...> >(this),
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
{
CHECK;
mIndex(indices...);
CHECK;
}
template <typename T, class... Ranges>
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),
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
{
CHECK;
(*mIndex)(indices...);
CHECK;
}
template <typename T, class... Ranges>
@ -108,13 +103,13 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
const T& OperationRoot<T,Ranges...>::get() const
{
return mArrayRef[ *mIndex ];
return mArrayRef[ (*mIndex)() ];
}
template <typename T, class... Ranges>
T& OperationRoot<T,Ranges...>::get()
{
return mArrayRef[ *mIndex ];
return mArrayRef[ (*mIndex)() ];
}
/***********************

View file

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

View file

@ -32,8 +32,8 @@ namespace MultiArrayTools
MultiIndex() = delete;
// NO DEFAULT HERE !!!
// ( have to assign sub-indices (ptr!) correctly )
MultiIndex(const MultiIndex& in);
MultiIndex& operator=(const MultiIndex& in);
//MultiIndex(const MultiIndex& in);
//MultiIndex& operator=(const MultiIndex& in);
MultiIndex& operator=(ContainerIndex<Indices...>& ci);
template <class MRange>
@ -65,7 +65,7 @@ namespace MultiArrayTools
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);
auto i = std::dynamic_pointer_cast<SRange::IndexType>( srptr->index() );
CHECK;
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

View file

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