fix copyInst <-> copy -- bug -> first mdim op test works
This commit is contained in:
parent
f99e55d4fd
commit
8a1cc35089
7 changed files with 96 additions and 9 deletions
|
@ -63,6 +63,7 @@ namespace MultiArrayTools
|
|||
ContainerIndex& operator()(); // -> sync; just to shorten the code
|
||||
|
||||
std::shared_ptr<RangeType> range() const;
|
||||
virtual std::string id() const override { return std::string("con") + std::to_string(IB::mId); }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,10 @@ namespace MultiArrayTools
|
|||
|
||||
IndexBase::IndexBase(const std::shared_ptr<RangeBase>& range,
|
||||
size_t pos) : mRangePtr(range),
|
||||
mPos(pos) {}
|
||||
mPos(pos)
|
||||
{
|
||||
mId = indexId();
|
||||
}
|
||||
|
||||
bool IndexBase::operator==(const IndexBase& in) const
|
||||
{
|
||||
|
|
|
@ -13,11 +13,22 @@
|
|||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
size_t indexId()
|
||||
{
|
||||
static size_t id = 0;
|
||||
++id;
|
||||
return id;
|
||||
}
|
||||
|
||||
class IndexBase
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(IndexBase);
|
||||
//DEFAULT_MEMBERS(IndexBase);
|
||||
|
||||
IndexBase() { mId = indexId(); }
|
||||
IndexBase(IndexBase&& in) = default;
|
||||
IndexBase& operator=(IndexBase&& in) = default;
|
||||
|
||||
IndexBase(const std::shared_ptr<RangeBase>& range, size_t pos);
|
||||
virtual ~IndexBase() = default;
|
||||
|
||||
|
@ -37,10 +48,12 @@ namespace MultiArrayTools
|
|||
|
||||
virtual operator size_t() const;
|
||||
|
||||
virtual std::string id() const { return std::to_string( mId ); }
|
||||
protected:
|
||||
|
||||
std::shared_ptr<RangeBase> mRangePtr;
|
||||
size_t mPos;
|
||||
size_t mId;
|
||||
};
|
||||
|
||||
template <typename MetaType>
|
||||
|
|
|
@ -66,6 +66,8 @@ namespace MultiArrayTools
|
|||
virtual size_t dim() const override;
|
||||
|
||||
std::shared_ptr<RangeType> range() const;
|
||||
|
||||
virtual std::string id() const override { return std::string("mul") + std::to_string(IB::mId); }
|
||||
};
|
||||
|
||||
/*************************
|
||||
|
|
|
@ -52,6 +52,48 @@ namespace {
|
|||
std::vector<double> v2 = { 8.870, 4.790, 8.215, 5.063 };
|
||||
};
|
||||
|
||||
class OpTest_MDim : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef MultiRangeFactory<SRange,SRange> MRF;
|
||||
typedef MRF::oType MRange;
|
||||
|
||||
OpTest_MDim()
|
||||
{
|
||||
swapFactory<SRF>(rfbptr, {'x', 'l', 'f', 'g'} );
|
||||
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapFactory<SRF>(rfbptr, {'1', '2', '3'} );
|
||||
sr2ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapFactory<SRF>(rfbptr, {'a', 'b'} );
|
||||
sr3ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapFactory<SRF>(rfbptr, {'A', 'B'} );
|
||||
sr4ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<MRF>(rfbptr, sr2ptr, sr3ptr);
|
||||
mr1ptr = std::dynamic_pointer_cast<MRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<MRF>(rfbptr, sr2ptr, sr4ptr);
|
||||
mr2ptr = std::dynamic_pointer_cast<MRange>( rfbptr->create() );
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||
std::shared_ptr<SRange> sr1ptr;
|
||||
std::shared_ptr<SRange> sr2ptr;
|
||||
std::shared_ptr<SRange> sr3ptr;
|
||||
std::shared_ptr<SRange> sr4ptr;
|
||||
std::shared_ptr<MRange> mr1ptr;
|
||||
std::shared_ptr<MRange> mr2ptr;
|
||||
std::vector<double> v1 = { 2.917, 9.436, 0.373 };
|
||||
std::vector<double> v2 = { 8.870, 4.790 };
|
||||
};
|
||||
|
||||
TEST_F(OpTest_1Dim, ExecOp)
|
||||
{
|
||||
MultiArray<double,SRange> ma1(srptr, v1);
|
||||
|
@ -67,6 +109,28 @@ namespace {
|
|||
EXPECT_EQ( fabs( res.at('g') - (7.192+5.063) ) < 0.0001, true );
|
||||
}
|
||||
|
||||
TEST_F(OpTest_MDim, ExecOp1)
|
||||
{
|
||||
MultiArray<double,SRange,SRange> res(sr2ptr,sr4ptr);
|
||||
MultiArray<double,SRange> ma1(sr2ptr, v1);
|
||||
MultiArray<double,SRange> ma2(sr4ptr, v2);
|
||||
|
||||
auto i1 = std::dynamic_pointer_cast<SRange::IndexType>( sr2ptr->index() );
|
||||
auto i2 = std::dynamic_pointer_cast<SRange::IndexType>( sr4ptr->index() );
|
||||
|
||||
res(i1,i2) = ma1(i1) + ma2(i2);
|
||||
|
||||
EXPECT_EQ( fabs( res.at(mkt('1','A')) - (2.917 + 8.870) ) < 0.0001, true );
|
||||
EXPECT_EQ( fabs( res.at(mkt('1','B')) - (2.917 + 4.790) ) < 0.0001, true );
|
||||
|
||||
EXPECT_EQ( fabs( res.at(mkt('2','A')) - (9.436 + 8.870) ) < 0.0001, true );
|
||||
EXPECT_EQ( fabs( res.at(mkt('2','B')) - (9.436 + 4.790) ) < 0.0001, true );
|
||||
|
||||
EXPECT_EQ( fabs( res.at(mkt('3','A')) - (0.373 + 8.870) ) < 0.0001, true );
|
||||
EXPECT_EQ( fabs( res.at(mkt('3','B')) - (0.373 + 4.790) ) < 0.0001, true );
|
||||
|
||||
}
|
||||
|
||||
} // anonymous namspace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
|
|
@ -109,7 +109,7 @@ namespace MultiArrayHelper
|
|||
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<N>() ) );
|
||||
PackNum<N-1>::construct(ip, range);
|
||||
}
|
||||
|
||||
/*
|
||||
template <template<class...> class IndexType, class... Indices>
|
||||
static void copy(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const IndexType<Indices...>& ind)
|
||||
|
@ -118,18 +118,19 @@ namespace MultiArrayHelper
|
|||
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( ind.template get<N>() ) );
|
||||
PackNum<N-1>::copy(ip, ind);
|
||||
}
|
||||
|
||||
*/
|
||||
template <template<class...> class IndexType, class... Indices>
|
||||
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const IndexType<Indices...>& ind)
|
||||
{
|
||||
std::get<N>(ip) = ind.template getPtr<N>() ;
|
||||
PackNum<N-1>::copy(ip, ind);
|
||||
PackNum<N-1>::copyInst(ip, ind);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
||||
{
|
||||
auto ID = std::get<N>(iPtrTup)->id();
|
||||
return std::get<N>(iPtrTup)->pos() +
|
||||
PackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
|
||||
}
|
||||
|
@ -225,7 +226,7 @@ namespace MultiArrayHelper
|
|||
|
||||
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<0>() ) );
|
||||
}
|
||||
|
||||
/*
|
||||
template <template<class...> class IndexType, class... Indices>
|
||||
static void copy(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const IndexType<Indices...>& ind)
|
||||
|
@ -233,7 +234,7 @@ namespace MultiArrayHelper
|
|||
typedef typename std::remove_reference<decltype(ind.template get<0>())>::type SubIndexType;
|
||||
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( ind.template get<0>() ) );
|
||||
}
|
||||
|
||||
*/
|
||||
template <template<class...> class IndexType, class... Indices>
|
||||
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const IndexType<Indices...>& ind)
|
||||
|
@ -244,6 +245,7 @@ namespace MultiArrayHelper
|
|||
template <class... Indices>
|
||||
static size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
||||
{
|
||||
auto ID = std::get<0>(iPtrTup)->id();
|
||||
return std::get<0>(iPtrTup)->pos();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ namespace MultiArrayTools
|
|||
virtual size_t dim() const override; // = 1
|
||||
virtual bool last() const override;
|
||||
virtual bool first() const override;
|
||||
|
||||
virtual std::string id() const override { return std::string("sin") + std::to_string(IB::mId); }
|
||||
};
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
|
|
Loading…
Reference in a new issue