two tests work again, oputest does not...

This commit is contained in:
Christian Zimmermann 2017-12-12 16:16:09 +01:00
parent f691c9ea66
commit e798de6469
9 changed files with 51 additions and 38 deletions

View file

@ -54,6 +54,8 @@ namespace MultiArrayTools
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
ContainerIndex& operator()(); // -> sync; just to shorten the code
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); }
private:
//ContainerIndex(const ContainerIndex& in);
@ -91,14 +93,14 @@ namespace MultiArrayTools
return *i;
}
static int S_pp(ContainerIndex* i, intptr_t idxPtrNum)
static int S_pp(ContainerIndex* i, std::intptr_t idxPtrNum)
{
int tmp = PackNum<sizeof...(Indices)-1>::pp(i->mIPack, i->mBlockSizes, idxPtrNum);
i->mPos += tmp;
return tmp;
}
static int S_mm(ContainerIndex* i, intptr_t idxPtrNum)
static int S_mm(ContainerIndex* i, std::intptr_t idxPtrNum)
{
int tmp = PackNum<sizeof...(Indices)-1>::mm(i->mIPack, i->mBlockSizes, idxPtrNum);
i->mPos -= tmp;

View file

@ -23,7 +23,8 @@ namespace MultiArrayTools
auto getIndex(std::shared_ptr<RangeType> range)
-> std::shared_ptr<typename RangeType::IndexType>
{
return std::dynamic_pointer_cast<typename RangeType::IndexType>( range->index() );
return std::dynamic_pointer_cast<IndexWrapper<typename RangeType::IndexType> >
( range->index() )->get();
}
}

View file

@ -36,7 +36,7 @@ namespace MultiArrayTools
virtual size_t max() const = 0;
virtual std::shared_ptr<RangeBase> rangePtr() const = 0;
virtual std::shared_ptr<VirtualIndexWrapperBase> getPtr(size_t n) const = 0;
virtual intptr_t getPtrNum() const = 0;
virtual std::intptr_t getPtrNum() const = 0;
virtual size_t getStepSize(size_t n) const = 0;
};
@ -59,7 +59,7 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(IndexWrapper);
IndexWrapper(std::shared_ptr<I> idxPtr);
IndexWrapper(std::shared_ptr<I> idxPtr) : mIdxPtr(idxPtr) {}
virtual IndexType type() const override { return mIdxPtr->type(); }
virtual size_t dim() const override { return mIdxPtr->dim(); }
@ -67,9 +67,11 @@ namespace MultiArrayTools
virtual size_t max() const override { return mIdxPtr->max(); }
virtual std::shared_ptr<RangeBase> rangePtr() const override { return mIdxPtr->vrange(); }
virtual std::shared_ptr<VirtualIndexWrapperBase> getPtr(size_t n) const override { return mIdxPtr->getVPtr(n); }
virtual intptr_t getPtrNum() const override { return static_cast<intptr_t>( mIdxPtr.get() ); }
virtual std::intptr_t getPtrNum() const override { return reinterpret_cast<std::intptr_t>( mIdxPtr.get() ); }
virtual size_t getStepSize(size_t n) const override { return mIdxPtr->getStepSize(n); }
std::shared_ptr<I> get() const { return mIdxPtr; } // unwrap
private:
std::shared_ptr<I> mIdxPtr;
};
@ -89,12 +91,12 @@ namespace MultiArrayTools
IndexType type() const { return I::S_type(THIS()); }
IndexInterface& operator=(size_t pos) { return I::S_ass_op(THIS(), pos); }
IndexInterface& operator++() { return I::S_pp_op(THIS()); }
IndexInterface& operator--() { return I::S_mm_op(THIS()); }
I& operator=(size_t pos) { return I::S_ass_op(THIS(), pos); }
I& operator++() { return I::S_pp_op(THIS()); }
I& operator--() { return I::S_mm_op(THIS()); }
int pp(std::shared_ptr<IndexInterface>& idxPtr) { return I::S_pp(THIS()); }
int mm(std::shared_ptr<IndexInterface>& idxPtr) { return I::S_mm(THIS()); }
int pp(std::intptr_t idxPtrNum) { return I::S_pp(THIS(), idxPtrNum); }
int mm(std::intptr_t idxPtrNum) { return I::S_mm(THIS(), idxPtrNum); }
bool operator==(const IndexInterface& in) const;
bool operator!=(const IndexInterface& in) const;
@ -123,7 +125,7 @@ namespace MultiArrayTools
std::string id() const { return I::S_id(THIS()); }
MetaType meta() const { return I::S_meta(THIS()); }
IndexInterface& at(const MetaType& meta) { return I::S_at(THIS(), meta); }
I& at(const MetaType& meta) { return I::S_at(THIS(), meta); }
private:
@ -131,6 +133,8 @@ namespace MultiArrayTools
friend I;
IndexInterface() { mId = indexId(); }
IndexInterface(const IndexInterface& in) = default;
IndexInterface& operator=(const IndexInterface& in) = default;
IndexInterface(IndexInterface&& in) = default;
IndexInterface& operator=(IndexInterface&& in) = default;
@ -156,9 +160,9 @@ namespace MultiArrayTools
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& range,
size_t pos) : mRangePtr(range),
mPos(pos),
mMax(mRangePtr->size())
size_t pos) : mRangePtr(range),
mPos(pos),
mMax(mRangePtr->size())
{
mId = indexId();
}

View file

@ -77,7 +77,8 @@ namespace MultiArrayTools
virtual ~MultiArrayBase() = default;
virtual const T& operator[](const typename CRange::IndexType& i) const = 0;
virtual const T& operator[](const IndexType& i) const = 0;
//virtual const T& operator[](const typename CRange::IndexType& i) const = 0;
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const = 0;
virtual const T* data() const = 0;

View file

@ -410,8 +410,8 @@ namespace MultiArrayTools
mIndex = std::make_shared<IndexType>( mr->begin() );
(*mIndex) = *index;
auto blockIndex = seekBlockIndex( mIndex, second);
intptr_t blockIndexNum = blockIndex->getPtrNum();
auto blockIndex = seekBlockIndex( make_viwb( mIndex ), second);
std::intptr_t blockIndexNum = blockIndex->getPtrNum();
block(blockIndex);
second.block(blockIndex);
@ -438,7 +438,7 @@ namespace MultiArrayTools
template <typename T, class OpClass, class... Ranges>
std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const std::shared_ptr<VIWB> blockIndex) const
{
std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) );
std::vector<BTSS> btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) );
mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max());
return btv;
}
@ -474,7 +474,7 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const std::shared_ptr<VIWB> blockIndex) const
{
std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) );
std::vector<BTSS> btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) );
mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max());
return btv;
}
@ -524,7 +524,7 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
std::vector<BTSS> OperationRoot<T,Ranges...>::block(const std::shared_ptr<VIWB> blockIndex) const
{
std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) );
std::vector<BTSS> btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) );
mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max());
return btv;
}

View file

@ -70,6 +70,8 @@ namespace MultiArrayTools
// Do NOT share index instances between two or more MultiIndex instances
MultiIndex& operator()(std::shared_ptr<Indices>&... indices);
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); }
private:
friend IB;
@ -98,14 +100,14 @@ namespace MultiArrayTools
return *i;
}
static int S_pp(MultiIndex* i, intptr_t idxPtrNum)
static int S_pp(MultiIndex* i, std::intptr_t idxPtrNum)
{
int tmp = PackNum<sizeof...(Indices)-1>::pp(i->mIPack, i->mBlockSizes, idxPtrNum);
i->mPos += tmp;
return tmp;
}
static int S_mm(MultiIndex* i, intptr_t idxPtrNum)
static int S_mm(MultiIndex* i, std::intptr_t idxPtrNum)
{
int tmp = PackNum<sizeof...(Indices)-1>::mm(i->mIPack, i->mBlockSizes, idxPtrNum);
i->mPos -= tmp;

View file

@ -164,7 +164,7 @@ namespace {
std::vector<double> cv1;
std::vector<double> cv2;
};
/*
TEST_F(OpTest_Performance, PCheck)
{
MultiArray<double,MRange> ma2(mrptr, cv2);
@ -203,7 +203,7 @@ namespace {
//EXPECT_EQ( xround( res.at(mkt(700,900)) ), xround(res2[700*vs1 + 900]) );
}
*/
TEST_F(OpTest_1Dim, ExecOp)
{
MultiArray<double,SRange> ma1(srptr, v1);
@ -211,6 +211,7 @@ namespace {
MultiArray<double,SRange> res(srptr);
auto i = MAT::getIndex( srptr );
res(i) = ma1(i) + ma2(i);
EXPECT_EQ( fabs( res.at('a') - (2.917+8.870) ) < 0.0001, true);

View file

@ -85,11 +85,11 @@ namespace MultiArrayHelper
template <class... Indices>
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
intptr_t idxPtrNum)
std::intptr_t idxPtrNum)
{
auto& siPtr = std::get<N>(ip);
//VCHECK(siPtr.id());
if(static_cast<intptr_t>(siPtr.get()) == idxPtrNum){
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
return PackNum<N-1>::pp(ip, bs, idxPtrNum);
}
else {
@ -121,10 +121,10 @@ namespace MultiArrayHelper
template <class... Indices>
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
intptr_t idxPtrNum)
std::intptr_t idxPtrNum)
{
auto& siPtr = std::get<N>(ip);
if(static_cast<intptr_t>(siPtr.get()) == idxPtrNum){
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
return std::get<N>(bs) + PackNum<N-1>::mm(ip, bs, idxPtrNum);
}
else {
@ -300,10 +300,10 @@ namespace MultiArrayHelper
template <class... Indices>
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
intptr_t idxPtrNum)
std::intptr_t idxPtrNum)
{
auto& siPtr = std::get<0>(ip);
if(static_cast<intptr_t>(siPtr.get()) == idxPtrNum){
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
return std::get<0>(bs);
}
else {
@ -322,10 +322,10 @@ namespace MultiArrayHelper
template <class... Indices>
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
intptr_t idxPtrNum)
std::intptr_t idxPtrNum)
{
auto& siPtr = std::get<0>(ip);
if(static_cast<intptr_t>(siPtr.get()) == idxPtrNum){
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
return std::get<0>(bs);
//return 1;
}

View file

@ -29,6 +29,8 @@ namespace MultiArrayTools
SingleIndex& operator=(size_t pos) { IB::operator=(pos); return *this; }
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); }
private:
friend IB;
@ -58,13 +60,13 @@ namespace MultiArrayTools
return *i;
}
static int S_pp(SingleIndex* i, intptr_t idxPtrNum)
static int S_pp(SingleIndex* i, std::intptr_t idxPtrNum)
{
++(*i);
return 1;
}
static int S_mm(SingleIndex* i, intptr_t idxPtrNum)
static int S_mm(SingleIndex* i, std::intptr_t idxPtrNum)
{
--(*i);
return 1;