some debug attempts
This commit is contained in:
parent
07febad83a
commit
1cc96663a4
6 changed files with 68 additions and 25 deletions
|
@ -17,7 +17,7 @@ namespace MultiArrayTools
|
|||
class IndefinitIndexBase
|
||||
{
|
||||
public:
|
||||
|
||||
DEFAULT_MEMBERS(IndefinitIndexBase);
|
||||
virtual ~IndefinitIndexBase() {}
|
||||
|
||||
virtual IndefinitIndexBase& operator=(size_t pos) = 0;
|
||||
|
@ -53,8 +53,6 @@ namespace MultiArrayTools
|
|||
|
||||
protected:
|
||||
|
||||
DEFAULT_MEMBERS(IndefinitIndexBase);
|
||||
|
||||
std::string mName;
|
||||
size_t mPos;
|
||||
|
||||
|
@ -65,6 +63,9 @@ namespace MultiArrayTools
|
|||
class IndexBase : public IndefinitIndexBase
|
||||
{
|
||||
public:
|
||||
|
||||
DEFAULT_MEMBERS(IndexBase);
|
||||
IndexBase(RangeBase<Index> const* range);
|
||||
|
||||
//virtual size_t pos() const override; // = mPos; implement !!!
|
||||
virtual size_t max() const override;
|
||||
|
@ -74,10 +75,6 @@ namespace MultiArrayTools
|
|||
|
||||
protected:
|
||||
|
||||
DEFAULT_MEMBERS(IndexBase);
|
||||
|
||||
IndexBase(RangeBase<Index> const* range);
|
||||
|
||||
// translate index into position
|
||||
virtual size_t evaluate(const Index& in) const = 0;
|
||||
RangeBase<Index> const* mRange;
|
||||
|
|
|
@ -26,10 +26,13 @@ namespace MultiArrayTools
|
|||
MultiArrayOperationBase<T,Range>&
|
||||
MultiArrayOperationBase<T,Range>::operator=(const MultiArrayOperationBase<T,Range>& in)
|
||||
{
|
||||
CHECK;
|
||||
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
|
||||
VCHECK(iref.pos());
|
||||
VCHECK(in.mIibPtr->pos());
|
||||
VCHECK(in.get());
|
||||
get() = in.get();
|
||||
}
|
||||
return *this;
|
||||
|
@ -70,7 +73,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
void MultiArrayOperationBase<T,Range>::linkIndicesTo(IndefinitIndexBase* target)
|
||||
void MultiArrayOperationBase<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const
|
||||
{
|
||||
mIibPtr->linkTo(target);
|
||||
}
|
||||
|
@ -86,6 +89,18 @@ namespace MultiArrayTools
|
|||
{
|
||||
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 *
|
||||
|
@ -140,7 +155,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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);
|
||||
TupleIndicesLinker<sizeof...(Ranges)>::linkTupleIndicesTo(mSecs, target);
|
||||
|
|
|
@ -21,7 +21,8 @@ namespace MultiArrayTools
|
|||
|
||||
MultiArrayOperationBase(MultiArray<T,Range>& ma, const Name& nm);
|
||||
MultiArrayOperationBase& operator=(const MultiArrayOperationBase& in);
|
||||
|
||||
//MultiArrayOperationBase(const MultiArrayOperationBase& in) = default;
|
||||
|
||||
virtual ~MultiArrayOperationBase();
|
||||
|
||||
// execute AnyOperation
|
||||
|
@ -50,17 +51,20 @@ namespace MultiArrayTools
|
|||
|
||||
IndefinitIndexBase* index();
|
||||
|
||||
virtual void linkIndicesTo(IndefinitIndexBase* target);
|
||||
virtual void linkIndicesTo(IndefinitIndexBase* target) const;
|
||||
|
||||
virtual T& get();
|
||||
virtual const T& get() const;
|
||||
|
||||
virtual T& get(IndefinitIndexBase* iibPtr);
|
||||
virtual const T& get(IndefinitIndexBase* iibPtr) const;
|
||||
|
||||
protected:
|
||||
|
||||
// HERE !!!!!!
|
||||
|
||||
MultiArray<T,Range>& mArrayRef;
|
||||
IndefinitIndexBase* mIibPtr = nullptr;
|
||||
IndefinitIndexBase mutable* mIibPtr = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
@ -74,14 +78,14 @@ namespace MultiArrayTools
|
|||
MultiArrayOperation(Operation& op, MultiArrayOperationBase<T,Ranges>&... secs);
|
||||
virtual size_t argNum() const override;
|
||||
|
||||
virtual void linkIndicesTo(IndefinitIndexBase* target) override;
|
||||
virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
|
||||
|
||||
virtual T& get() override;
|
||||
virtual const T& get() const override;
|
||||
|
||||
protected:
|
||||
|
||||
T mVal;
|
||||
mutable T mVal;
|
||||
Operation mOp;
|
||||
std::tuple<MultiArrayOperationBase<T,Ranges>... > mSecs;
|
||||
};
|
||||
|
|
|
@ -79,9 +79,9 @@ namespace MultiArrayTools
|
|||
IndefinitIndexBase& si = index.get(digit);
|
||||
si.setPos( si.pos() + num );
|
||||
size_t oor = si.outOfRange();
|
||||
if(oor and digit != index.dim() - 1){
|
||||
plus(index, digit + 1, 1);
|
||||
plus(index, digit, oor - si.max());
|
||||
if(oor and digit != 0){
|
||||
plus(index, digit - 1, 1);
|
||||
plus(index, digit, oor - si.max() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,8 +127,8 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
|
||||
{
|
||||
IIB::setPos( IIB::pos() + 1 );
|
||||
plus(*this, 0, 1);
|
||||
plus(*this, sizeof...(Indices)-1, 1);
|
||||
IIB::setPos( evaluate(*this) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,18 @@ namespace MultiArrayTools
|
|||
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>
|
||||
IndefinitIndexBase& MultiIndex<Indices...>::operator=(size_t pos)
|
||||
{
|
||||
|
@ -173,7 +185,8 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
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>
|
||||
|
@ -388,6 +401,7 @@ namespace MultiArrayTools
|
|||
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) -= 1;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
IndexSetter<sizeof...(Ranges)-1>::setEnd(is,mSpace);
|
||||
return MultiIndex<typename Ranges::IndexType...>(this, is);
|
||||
return ++MultiIndex<typename Ranges::IndexType...>(this, is);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ namespace MultiArrayTools
|
|||
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 MultiRangeType rangeType() const override;
|
||||
|
||||
|
|
|
@ -115,15 +115,24 @@ namespace {
|
|||
auto i = ma2.begin();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
//ma2("alpha","beta");
|
||||
//ma("beta","alpha");
|
||||
CHECK;
|
||||
ma2("alpha","beta") = ma("beta","alpha");
|
||||
VCHECK(i(i1 = 0,i2 = 0).pos());
|
||||
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);
|
||||
|
||||
VCHECK(i(i1 = 0,i2 = 1).pos());
|
||||
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);
|
||||
|
||||
VCHECK(i(i1 = 0,i2 = 2).pos());
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue