two tests work again, oputest does not...
This commit is contained in:
parent
f691c9ea66
commit
e798de6469
9 changed files with 51 additions and 38 deletions
|
@ -54,6 +54,8 @@ namespace MultiArrayTools
|
||||||
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
||||||
ContainerIndex& operator()(); // -> sync; just to shorten the code
|
ContainerIndex& operator()(); // -> sync; just to shorten the code
|
||||||
|
|
||||||
|
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//ContainerIndex(const ContainerIndex& in);
|
//ContainerIndex(const ContainerIndex& in);
|
||||||
|
@ -91,14 +93,14 @@ namespace MultiArrayTools
|
||||||
return *i;
|
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);
|
int tmp = PackNum<sizeof...(Indices)-1>::pp(i->mIPack, i->mBlockSizes, idxPtrNum);
|
||||||
i->mPos += tmp;
|
i->mPos += tmp;
|
||||||
return 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);
|
int tmp = PackNum<sizeof...(Indices)-1>::mm(i->mIPack, i->mBlockSizes, idxPtrNum);
|
||||||
i->mPos -= tmp;
|
i->mPos -= tmp;
|
||||||
|
|
|
@ -23,7 +23,8 @@ namespace MultiArrayTools
|
||||||
auto getIndex(std::shared_ptr<RangeType> range)
|
auto getIndex(std::shared_ptr<RangeType> range)
|
||||||
-> std::shared_ptr<typename RangeType::IndexType>
|
-> 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace MultiArrayTools
|
||||||
virtual size_t max() const = 0;
|
virtual size_t max() const = 0;
|
||||||
virtual std::shared_ptr<RangeBase> rangePtr() const = 0;
|
virtual std::shared_ptr<RangeBase> rangePtr() const = 0;
|
||||||
virtual std::shared_ptr<VirtualIndexWrapperBase> getPtr(size_t n) 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;
|
virtual size_t getStepSize(size_t n) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
DEFAULT_MEMBERS(IndexWrapper);
|
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 IndexType type() const override { return mIdxPtr->type(); }
|
||||||
virtual size_t dim() const override { return mIdxPtr->dim(); }
|
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 size_t max() const override { return mIdxPtr->max(); }
|
||||||
virtual std::shared_ptr<RangeBase> rangePtr() const override { return mIdxPtr->vrange(); }
|
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 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); }
|
virtual size_t getStepSize(size_t n) const override { return mIdxPtr->getStepSize(n); }
|
||||||
|
|
||||||
|
std::shared_ptr<I> get() const { return mIdxPtr; } // unwrap
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<I> mIdxPtr;
|
std::shared_ptr<I> mIdxPtr;
|
||||||
};
|
};
|
||||||
|
@ -89,12 +91,12 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
IndexType type() const { return I::S_type(THIS()); }
|
IndexType type() const { return I::S_type(THIS()); }
|
||||||
|
|
||||||
IndexInterface& operator=(size_t pos) { return I::S_ass_op(THIS(), pos); }
|
I& operator=(size_t pos) { return I::S_ass_op(THIS(), pos); }
|
||||||
IndexInterface& operator++() { return I::S_pp_op(THIS()); }
|
I& operator++() { return I::S_pp_op(THIS()); }
|
||||||
IndexInterface& operator--() { return I::S_mm_op(THIS()); }
|
I& operator--() { return I::S_mm_op(THIS()); }
|
||||||
|
|
||||||
int pp(std::shared_ptr<IndexInterface>& idxPtr) { return I::S_pp(THIS()); }
|
int pp(std::intptr_t idxPtrNum) { return I::S_pp(THIS(), idxPtrNum); }
|
||||||
int mm(std::shared_ptr<IndexInterface>& idxPtr) { return I::S_mm(THIS()); }
|
int mm(std::intptr_t idxPtrNum) { return I::S_mm(THIS(), idxPtrNum); }
|
||||||
|
|
||||||
bool operator==(const IndexInterface& in) const;
|
bool operator==(const IndexInterface& in) const;
|
||||||
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()); }
|
std::string id() const { return I::S_id(THIS()); }
|
||||||
|
|
||||||
MetaType meta() const { return I::S_meta(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:
|
private:
|
||||||
|
@ -131,6 +133,8 @@ namespace MultiArrayTools
|
||||||
friend I;
|
friend I;
|
||||||
|
|
||||||
IndexInterface() { mId = indexId(); }
|
IndexInterface() { mId = indexId(); }
|
||||||
|
IndexInterface(const IndexInterface& in) = default;
|
||||||
|
IndexInterface& operator=(const IndexInterface& in) = default;
|
||||||
IndexInterface(IndexInterface&& in) = default;
|
IndexInterface(IndexInterface&& in) = default;
|
||||||
IndexInterface& operator=(IndexInterface&& in) = default;
|
IndexInterface& operator=(IndexInterface&& in) = default;
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,8 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
virtual ~MultiArrayBase() = default;
|
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& at(const typename CRange::IndexType::MetaType& meta) const = 0;
|
||||||
|
|
||||||
virtual const T* data() const = 0;
|
virtual const T* data() const = 0;
|
||||||
|
|
|
@ -410,8 +410,8 @@ namespace MultiArrayTools
|
||||||
mIndex = std::make_shared<IndexType>( mr->begin() );
|
mIndex = std::make_shared<IndexType>( mr->begin() );
|
||||||
(*mIndex) = *index;
|
(*mIndex) = *index;
|
||||||
|
|
||||||
auto blockIndex = seekBlockIndex( mIndex, second);
|
auto blockIndex = seekBlockIndex( make_viwb( mIndex ), second);
|
||||||
intptr_t blockIndexNum = blockIndex->getPtrNum();
|
std::intptr_t blockIndexNum = blockIndex->getPtrNum();
|
||||||
|
|
||||||
block(blockIndex);
|
block(blockIndex);
|
||||||
second.block(blockIndex);
|
second.block(blockIndex);
|
||||||
|
@ -438,7 +438,7 @@ namespace MultiArrayTools
|
||||||
template <typename T, class OpClass, class... Ranges>
|
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> 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());
|
mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max());
|
||||||
return btv;
|
return btv;
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const std::shared_ptr<VIWB> blockIndex) const
|
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());
|
mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max());
|
||||||
return btv;
|
return btv;
|
||||||
}
|
}
|
||||||
|
@ -524,7 +524,7 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
std::vector<BTSS> OperationRoot<T,Ranges...>::block(const std::shared_ptr<VIWB> blockIndex) const
|
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());
|
mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max());
|
||||||
return btv;
|
return btv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ namespace MultiArrayTools
|
||||||
// Do NOT share index instances between two or more MultiIndex instances
|
// Do NOT share index instances between two or more MultiIndex instances
|
||||||
MultiIndex& operator()(std::shared_ptr<Indices>&... indices);
|
MultiIndex& operator()(std::shared_ptr<Indices>&... indices);
|
||||||
|
|
||||||
|
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend IB;
|
friend IB;
|
||||||
|
@ -98,14 +100,14 @@ namespace MultiArrayTools
|
||||||
return *i;
|
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);
|
int tmp = PackNum<sizeof...(Indices)-1>::pp(i->mIPack, i->mBlockSizes, idxPtrNum);
|
||||||
i->mPos += tmp;
|
i->mPos += tmp;
|
||||||
return 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);
|
int tmp = PackNum<sizeof...(Indices)-1>::mm(i->mIPack, i->mBlockSizes, idxPtrNum);
|
||||||
i->mPos -= tmp;
|
i->mPos -= tmp;
|
||||||
|
|
|
@ -164,7 +164,7 @@ namespace {
|
||||||
std::vector<double> cv1;
|
std::vector<double> cv1;
|
||||||
std::vector<double> cv2;
|
std::vector<double> cv2;
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
TEST_F(OpTest_Performance, PCheck)
|
TEST_F(OpTest_Performance, PCheck)
|
||||||
{
|
{
|
||||||
MultiArray<double,MRange> ma2(mrptr, cv2);
|
MultiArray<double,MRange> ma2(mrptr, cv2);
|
||||||
|
@ -203,7 +203,7 @@ namespace {
|
||||||
//EXPECT_EQ( xround( res.at(mkt(700,900)) ), xround(res2[700*vs1 + 900]) );
|
//EXPECT_EQ( xround( res.at(mkt(700,900)) ), xround(res2[700*vs1 + 900]) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
TEST_F(OpTest_1Dim, ExecOp)
|
TEST_F(OpTest_1Dim, ExecOp)
|
||||||
{
|
{
|
||||||
MultiArray<double,SRange> ma1(srptr, v1);
|
MultiArray<double,SRange> ma1(srptr, v1);
|
||||||
|
@ -211,6 +211,7 @@ namespace {
|
||||||
MultiArray<double,SRange> res(srptr);
|
MultiArray<double,SRange> res(srptr);
|
||||||
|
|
||||||
auto i = MAT::getIndex( srptr );
|
auto i = MAT::getIndex( srptr );
|
||||||
|
|
||||||
res(i) = ma1(i) + ma2(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('a') - (2.917+8.870) ) < 0.0001, true);
|
||||||
|
|
|
@ -85,11 +85,11 @@ namespace MultiArrayHelper
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
intptr_t idxPtrNum)
|
std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
auto& siPtr = std::get<N>(ip);
|
auto& siPtr = std::get<N>(ip);
|
||||||
//VCHECK(siPtr.id());
|
//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);
|
return PackNum<N-1>::pp(ip, bs, idxPtrNum);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -121,10 +121,10 @@ namespace MultiArrayHelper
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
intptr_t idxPtrNum)
|
std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
auto& siPtr = std::get<N>(ip);
|
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);
|
return std::get<N>(bs) + PackNum<N-1>::mm(ip, bs, idxPtrNum);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -300,10 +300,10 @@ namespace MultiArrayHelper
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
intptr_t idxPtrNum)
|
std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
auto& siPtr = std::get<0>(ip);
|
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 std::get<0>(bs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -322,10 +322,10 @@ namespace MultiArrayHelper
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
intptr_t idxPtrNum)
|
std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
auto& siPtr = std::get<0>(ip);
|
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 std::get<0>(bs);
|
||||||
//return 1;
|
//return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
SingleIndex& operator=(size_t pos) { IB::operator=(pos); return *this; }
|
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:
|
private:
|
||||||
|
|
||||||
friend IB;
|
friend IB;
|
||||||
|
@ -58,13 +60,13 @@ namespace MultiArrayTools
|
||||||
return *i;
|
return *i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int S_pp(SingleIndex* i, intptr_t idxPtrNum)
|
static int S_pp(SingleIndex* i, std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
++(*i);
|
++(*i);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int S_mm(SingleIndex* i, intptr_t idxPtrNum)
|
static int S_mm(SingleIndex* i, std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
--(*i);
|
--(*i);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue