im com
This commit is contained in:
parent
d5bf63ac82
commit
3b0f67eb47
4 changed files with 90 additions and 19 deletions
|
@ -59,31 +59,58 @@ namespace {
|
|||
std::vector<double> vv = { 3.141, 2.718, 1.618, 0.693, 0.577 };
|
||||
};
|
||||
|
||||
/*
|
||||
class MATest_1Dim : public ::testing::Test
|
||||
|
||||
class MATest_MDim : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef ContainerRangeFactory<SRange> CRF;
|
||||
typedef MultiRangeFactory<SRange,SRange> MRF;
|
||||
typedef MRF::oType MRange;
|
||||
|
||||
typedef ContainerRangeFactory<MRange,SRange> CRF;
|
||||
typedef CRF::oType CRange;
|
||||
|
||||
MATest_1Dim()
|
||||
{
|
||||
swapFactory<SRF>(rfbptr, {'x', 'y', 'l', 'f', 'g'} );
|
||||
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
typedef ContainerRangeFactory<SRange> CRF2;
|
||||
typedef CRF2::oType CRange2;
|
||||
|
||||
swapMFactory<CRF>(rfbptr, srptr);
|
||||
|
||||
MATest_MDim()
|
||||
{
|
||||
swapFactory<SRF>(rfbptr, {'x', 'y'} );
|
||||
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapFactory<SRF>(rfbptr, {'a', 'l', 'f', 'g'} );
|
||||
sr2ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapFactory<SRF>(rfbptr, {'1', '2', '3'} );
|
||||
sr3ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapFactory<SRF>(rfbptr, { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X' } );
|
||||
sr4ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<MRF>(rfbptr, sr1ptr, sr2ptr);
|
||||
mrptr = std::dynamic_pointer_cast<MRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<CRF>(rfbptr, mrptr, sr3ptr);
|
||||
crptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||
std::shared_ptr<SRange> srptr;
|
||||
std::shared_ptr<SRange> sr1ptr;
|
||||
std::shared_ptr<SRange> sr2ptr;
|
||||
std::shared_ptr<SRange> sr3ptr;
|
||||
std::shared_ptr<SRange> sr4ptr;
|
||||
std::shared_ptr<MRange> mrptr;
|
||||
std::shared_ptr<CRange> crptr;
|
||||
std::vector<double> vv = { 3.141, 2.718, 1.618, 0.693, 0.577 };
|
||||
};*/
|
||||
std::vector<double> vv = { 2.917, 9.436, 0.373, 7.192, 7.315, 1.536, 4.892, 0.280,
|
||||
8.870, 4.790, 8.215, 5.063, 1.530, 3.084, 1.609, 4.847,
|
||||
8.175, 0.112, 6.712, 6.408, 1.959, 0.331, 4.209, 2.951 };
|
||||
};
|
||||
|
||||
TEST_F(MATest_1Dim, SimpleCall)
|
||||
{
|
||||
|
@ -146,6 +173,36 @@ namespace {
|
|||
EXPECT_EQ( ma[ j.at('g') ], 0.693);
|
||||
EXPECT_EQ( ma[ j.at('i') ], 0.577);
|
||||
}
|
||||
|
||||
TEST_F(MATest_MDim, SimpleCall)
|
||||
{
|
||||
MultiArray<double,MATest_MDim::CRange> ma(crptr, vv);
|
||||
EXPECT_EQ( ma.size(), 24 );
|
||||
EXPECT_EQ( ma.range().dim(), 2 );
|
||||
|
||||
auto i = ma.beginIndex();
|
||||
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '1' ) ) ], 2.917);
|
||||
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '2' ) ) ], 9.436);
|
||||
|
||||
EXPECT_EQ( ma.at( mkt( mkt('x', 'a'), '1' ) ), 2.917);
|
||||
EXPECT_EQ( ma.at( mkt( mkt('x', 'a'), '2' ) ), 9.436);
|
||||
|
||||
ma.at( mkt( mkt('x', 'a'), '2' ) ) = 4.444;
|
||||
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '2' ) ) ], 4.444 );
|
||||
}
|
||||
|
||||
TEST_F(MATest_MDim, ReFormat)
|
||||
{
|
||||
MultiArray<double,MATest_MDim::CRange> ma(crptr, vv);
|
||||
|
||||
auto ma2 = ma.format( sr4ptr );
|
||||
auto i = ma2.beginIndex();
|
||||
EXPECT_EQ( ma2.at('A') , 2.917 );
|
||||
EXPECT_EQ( ma2[ i.at('G') ], 4.892 );
|
||||
EXPECT_EQ( ma2.at('J') , 4.790 );
|
||||
EXPECT_EQ( ma2[ i.at('M') ], 1.530 );
|
||||
EXPECT_EQ( ma2.at('W') , 4.209 );
|
||||
}
|
||||
|
||||
|
||||
} // end namespace
|
||||
|
|
|
@ -519,6 +519,18 @@ namespace MultiArrayTools
|
|||
return mCont[ i.pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T& MultiArray<T,CRange>::at(const typename CRange::IndexType::MetaType& meta)
|
||||
{
|
||||
return mCont[ MAB::beginIndex().at(meta).pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
const T& MultiArray<T,CRange>::at(const typename CRange::IndexType::MetaType& meta) const
|
||||
{
|
||||
return mCont[ MAB::beginIndex().at(meta).pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
bool MultiArray<T,CRange>::isConst() const
|
||||
{
|
||||
|
|
|
@ -75,6 +75,7 @@ namespace MultiArrayTools
|
|||
virtual ~MultiArrayBase() = default;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -167,7 +168,8 @@ namespace MultiArrayTools
|
|||
MutableMultiArrayBase(const std::shared_ptr<CRange>& range);
|
||||
|
||||
virtual T& operator[](const IndexType& i) = 0;
|
||||
|
||||
virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0;
|
||||
|
||||
virtual T* data() = 0;
|
||||
|
||||
virtual iterator begin();
|
||||
|
@ -218,9 +220,11 @@ namespace MultiArrayTools
|
|||
//template <class Range2, class Range3>
|
||||
//MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
||||
|
||||
T& operator[](const IndexType& i) override;
|
||||
const T& operator[](const IndexType& i) const override;
|
||||
|
||||
virtual T& operator[](const IndexType& i) override;
|
||||
virtual const T& operator[](const IndexType& i) const override;
|
||||
virtual T& at(const typename CRange::IndexType::MetaType& meta) override;
|
||||
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const override;
|
||||
|
||||
virtual bool isConst() const override;
|
||||
virtual bool isSlice() const override;
|
||||
|
||||
|
|
|
@ -22,12 +22,10 @@ namespace MultiArrayTools
|
|||
|
||||
typedef T value_type;
|
||||
|
||||
MultiArrayOperationBase() /*{ CHECK; }*/ = default;
|
||||
MultiArrayOperationBase() = default;
|
||||
virtual ~MultiArrayOperationBase();
|
||||
|
||||
virtual size_t argNum() const = 0;
|
||||
const IndefinitIndexBase& index() const = 0;
|
||||
|
||||
virtual const T& get() const = 0;
|
||||
};
|
||||
|
||||
|
@ -36,7 +34,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
public:
|
||||
|
||||
MutableMultiArrayOperationBase() /*{ CHECK; }*/ = default;
|
||||
MutableMultiArrayOperationBase() = default;
|
||||
virtual T& get() = 0;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue