some debug attempts

This commit is contained in:
Christian Zimmermann 2017-02-22 00:43:38 +01:00
parent 07febad83a
commit 1cc96663a4
6 changed files with 68 additions and 25 deletions

View file

@ -17,7 +17,7 @@ namespace MultiArrayTools
class IndefinitIndexBase class IndefinitIndexBase
{ {
public: public:
DEFAULT_MEMBERS(IndefinitIndexBase);
virtual ~IndefinitIndexBase() {} virtual ~IndefinitIndexBase() {}
virtual IndefinitIndexBase& operator=(size_t pos) = 0; virtual IndefinitIndexBase& operator=(size_t pos) = 0;
@ -53,8 +53,6 @@ namespace MultiArrayTools
protected: protected:
DEFAULT_MEMBERS(IndefinitIndexBase);
std::string mName; std::string mName;
size_t mPos; size_t mPos;
@ -66,6 +64,9 @@ namespace MultiArrayTools
{ {
public: public:
DEFAULT_MEMBERS(IndexBase);
IndexBase(RangeBase<Index> const* range);
//virtual size_t pos() const override; // = mPos; implement !!! //virtual size_t pos() const override; // = mPos; implement !!!
virtual size_t max() const override; virtual size_t max() const override;
virtual bool toNull() const override; virtual bool toNull() const override;
@ -74,10 +75,6 @@ namespace MultiArrayTools
protected: protected:
DEFAULT_MEMBERS(IndexBase);
IndexBase(RangeBase<Index> const* range);
// translate index into position // translate index into position
virtual size_t evaluate(const Index& in) const = 0; virtual size_t evaluate(const Index& in) const = 0;
RangeBase<Index> const* mRange; RangeBase<Index> const* mRange;

View file

@ -26,10 +26,13 @@ namespace MultiArrayTools
MultiArrayOperationBase<T,Range>& MultiArrayOperationBase<T,Range>&
MultiArrayOperationBase<T,Range>::operator=(const MultiArrayOperationBase<T,Range>& in) MultiArrayOperationBase<T,Range>::operator=(const MultiArrayOperationBase<T,Range>& in)
{ {
CHECK;
in.linkIndicesTo(mIibPtr); in.linkIndicesTo(mIibPtr);
for(*mIibPtr = mArrayRef.begin(); *mIibPtr != mArrayRef.end(); ++(*mIibPtr)){ IndexType& iref = dynamic_cast<IndexType&>(*mIibPtr);
for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){
// build in vectorization later // build in vectorization later
VCHECK(iref.pos());
VCHECK(in.mIibPtr->pos());
VCHECK(in.get());
get() = in.get(); get() = in.get();
} }
return *this; return *this;
@ -70,7 +73,7 @@ namespace MultiArrayTools
} }
template <typename T, class Range> template <typename T, class Range>
void MultiArrayOperationBase<T,Range>::linkIndicesTo(IndefinitIndexBase* target) void MultiArrayOperationBase<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const
{ {
mIibPtr->linkTo(target); mIibPtr->linkTo(target);
} }
@ -87,6 +90,18 @@ namespace MultiArrayTools
return mArrayRef[*dynamic_cast<IndexType*>(mIibPtr)]; return mArrayRef[*dynamic_cast<IndexType*>(mIibPtr)];
} }
template <typename T, class Range>
T& MultiArrayOperationBase<T,Range>::get(IndefinitIndexBase* iibPtr)
{
return mArrayRef[*dynamic_cast<IndexType*>(iibPtr)];
}
template <typename T, class Range>
const T& MultiArrayOperationBase<T,Range>::get(IndefinitIndexBase* iibPtr) const
{
return mArrayRef[*dynamic_cast<IndexType*>(iibPtr)];
}
/***************************** /*****************************
* MultiArrayOperation * * MultiArrayOperation *
*****************************/ *****************************/
@ -140,7 +155,7 @@ namespace MultiArrayTools
} }
template <typename T, class Range, class Operation, class... Ranges> template <typename T, class Range, class Operation, class... Ranges>
void MultiArrayOperation<T,Range,Operation,Ranges...>::linkIndicesTo(IndefinitIndexBase* target) void MultiArrayOperation<T,Range,Operation,Ranges...>::linkIndicesTo(IndefinitIndexBase* target) const
{ {
OB::mIibPtr->linkTo(target); OB::mIibPtr->linkTo(target);
TupleIndicesLinker<sizeof...(Ranges)>::linkTupleIndicesTo(mSecs, target); TupleIndicesLinker<sizeof...(Ranges)>::linkTupleIndicesTo(mSecs, target);

View file

@ -21,6 +21,7 @@ namespace MultiArrayTools
MultiArrayOperationBase(MultiArray<T,Range>& ma, const Name& nm); MultiArrayOperationBase(MultiArray<T,Range>& ma, const Name& nm);
MultiArrayOperationBase& operator=(const MultiArrayOperationBase& in); MultiArrayOperationBase& operator=(const MultiArrayOperationBase& in);
//MultiArrayOperationBase(const MultiArrayOperationBase& in) = default;
virtual ~MultiArrayOperationBase(); virtual ~MultiArrayOperationBase();
@ -50,17 +51,20 @@ namespace MultiArrayTools
IndefinitIndexBase* index(); IndefinitIndexBase* index();
virtual void linkIndicesTo(IndefinitIndexBase* target); virtual void linkIndicesTo(IndefinitIndexBase* target) const;
virtual T& get(); virtual T& get();
virtual const T& get() const; virtual const T& get() const;
virtual T& get(IndefinitIndexBase* iibPtr);
virtual const T& get(IndefinitIndexBase* iibPtr) const;
protected: protected:
// HERE !!!!!! // HERE !!!!!!
MultiArray<T,Range>& mArrayRef; MultiArray<T,Range>& mArrayRef;
IndefinitIndexBase* mIibPtr = nullptr; IndefinitIndexBase mutable* mIibPtr = nullptr;
}; };
@ -74,14 +78,14 @@ namespace MultiArrayTools
MultiArrayOperation(Operation& op, MultiArrayOperationBase<T,Ranges>&... secs); MultiArrayOperation(Operation& op, MultiArrayOperationBase<T,Ranges>&... secs);
virtual size_t argNum() const override; virtual size_t argNum() const override;
virtual void linkIndicesTo(IndefinitIndexBase* target) override; virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
virtual T& get() override; virtual T& get() override;
virtual const T& get() const override; virtual const T& get() const override;
protected: protected:
T mVal; mutable T mVal;
Operation mOp; Operation mOp;
std::tuple<MultiArrayOperationBase<T,Ranges>... > mSecs; std::tuple<MultiArrayOperationBase<T,Ranges>... > mSecs;
}; };

View file

@ -79,9 +79,9 @@ namespace MultiArrayTools
IndefinitIndexBase& si = index.get(digit); IndefinitIndexBase& si = index.get(digit);
si.setPos( si.pos() + num ); si.setPos( si.pos() + num );
size_t oor = si.outOfRange(); size_t oor = si.outOfRange();
if(oor and digit != index.dim() - 1){ if(oor and digit != 0){
plus(index, digit + 1, 1); plus(index, digit - 1, 1);
plus(index, digit, oor - si.max()); plus(index, digit, oor - si.max() - 1);
} }
} }
@ -127,8 +127,8 @@ namespace MultiArrayTools
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++() MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
{ {
IIB::setPos( IIB::pos() + 1 ); plus(*this, sizeof...(Indices)-1, 1);
plus(*this, 0, 1); IIB::setPos( evaluate(*this) );
return *this; return *this;
} }
@ -156,6 +156,18 @@ namespace MultiArrayTools
return *this; return *this;
} }
template <class... Indices>
bool MultiIndex<Indices...>::operator==(const MultiIndex<Indices...>& in)
{
return IB::mRange == in.mRange and IIB::pos() == in.pos();
}
template <class... Indices>
bool MultiIndex<Indices...>::operator!=(const MultiIndex<Indices...>& in)
{
return IB::mRange != in.mRange or IIB::pos() != in.pos();
}
template <class... Indices> template <class... Indices>
IndefinitIndexBase& MultiIndex<Indices...>::operator=(size_t pos) IndefinitIndexBase& MultiIndex<Indices...>::operator=(size_t pos)
{ {
@ -173,7 +185,8 @@ namespace MultiArrayTools
template <class... Indices> template <class... Indices>
size_t MultiIndex<Indices...>::evaluate(const MultiIndex<Indices...>& in) const size_t MultiIndex<Indices...>::evaluate(const MultiIndex<Indices...>& in) const
{ {
return Evaluation<sizeof...(Indices)-1>::evaluate(in); size_t res = Evaluation<sizeof...(Indices)-1>::evaluate(in);
return res;
} }
template <class... Indices> template <class... Indices>
@ -388,6 +401,7 @@ namespace MultiArrayTools
static void setEnd(std::tuple<typename Ranges::IndexType...>& i, const std::tuple<Ranges...>& r) static void setEnd(std::tuple<typename Ranges::IndexType...>& i, const std::tuple<Ranges...>& r)
{ {
std::get<N>(i) = std::get<N>(r).end(); std::get<N>(i) = std::get<N>(r).end();
std::get<N>(i) -= 1;
IndexSetter<N-1>::setEnd(i,r); IndexSetter<N-1>::setEnd(i,r);
} }
}; };
@ -405,6 +419,7 @@ namespace MultiArrayTools
static void setEnd(std::tuple<typename Ranges::IndexType...>& i, const std::tuple<Ranges...>& r) static void setEnd(std::tuple<typename Ranges::IndexType...>& i, const std::tuple<Ranges...>& r)
{ {
std::get<0>(i) = std::get<0>(r).end(); std::get<0>(i) = std::get<0>(r).end();
std::get<0>(i) -= 1;
} }
}; };
@ -449,6 +464,6 @@ namespace MultiArrayTools
{ {
std::tuple<typename Ranges::IndexType...> is; std::tuple<typename Ranges::IndexType...> is;
IndexSetter<sizeof...(Ranges)-1>::setEnd(is,mSpace); IndexSetter<sizeof...(Ranges)-1>::setEnd(is,mSpace);
return MultiIndex<typename Ranges::IndexType...>(this, is); return ++MultiIndex<typename Ranges::IndexType...>(this, is);
} }
} }

View file

@ -43,6 +43,9 @@ namespace MultiArrayTools
virtual MultiIndex& operator+=(int n) override; virtual MultiIndex& operator+=(int n) override;
virtual MultiIndex& operator-=(int n) override; virtual MultiIndex& operator-=(int n) override;
bool operator==(const MultiIndex& in);
bool operator!=(const MultiIndex& in);
virtual IIB& operator=(size_t pos) override; virtual IIB& operator=(size_t pos) override;
virtual MultiRangeType rangeType() const override; virtual MultiRangeType rangeType() const override;

View file

@ -115,15 +115,24 @@ namespace {
auto i = ma2.begin(); auto i = ma2.begin();
auto i1 = i.template getIndex<0>(); auto i1 = i.template getIndex<0>();
auto i2 = i.template getIndex<1>(); auto i2 = i.template getIndex<1>();
//ma2("alpha","beta");
//ma("beta","alpha");
CHECK; CHECK;
ma2("alpha","beta") = ma("beta","alpha"); ma2("alpha","beta") = ma("beta","alpha");
VCHECK(i(i1 = 0,i2 = 0).pos());
EXPECT_EQ(ma2[i(i1 = 0,i2 = 0)],-5); EXPECT_EQ(ma2[i(i1 = 0,i2 = 0)],-5);
VCHECK(i(i1 = 1,i2 = 0).pos());
EXPECT_EQ(ma2[i(i1 = 1,i2 = 0)],6); EXPECT_EQ(ma2[i(i1 = 1,i2 = 0)],6);
VCHECK(i(i1 = 0,i2 = 1).pos());
EXPECT_EQ(ma2[i(i1 = 0,i2 = 1)],2); EXPECT_EQ(ma2[i(i1 = 0,i2 = 1)],2);
VCHECK(i(i1 = 1,i2 = 1).pos());
EXPECT_EQ(ma2[i(i1 = 1,i2 = 1)],1); EXPECT_EQ(ma2[i(i1 = 1,i2 = 1)],1);
VCHECK(i(i1 = 0,i2 = 2).pos());
EXPECT_EQ(ma2[i(i1 = 0,i2 = 2)],9); EXPECT_EQ(ma2[i(i1 = 0,i2 = 2)],9);
VCHECK(i(i1 = 1,i2 = 2).pos());
EXPECT_EQ(ma2[i(i1 = 1,i2 = 2)],54); EXPECT_EQ(ma2[i(i1 = 1,i2 = 2)],54);
} }