2d opcont test

This commit is contained in:
Christian Zimmermann 2022-11-27 04:28:46 +01:00
parent 059093241b
commit 8513b6dcd3
4 changed files with 50 additions and 8 deletions

View file

@ -137,6 +137,12 @@ namespace CNORXZ
{
return MIndex<I1,I2>(a.THIS(),b.THIS());
}
template <class I1, class I2, typename MType1, typename MType2>
decltype(auto) operator*(const IndexPtr<I1,MType1>& a, const IndexPtr<I2,MType2>& b)
{
return std::make_shared<MIndex<I1,I2>>(a->THIS(), b->THIS());
}
}
#endif

View file

@ -98,6 +98,9 @@ namespace CNORXZ
template <class I1, class I2, typename MType1, typename MType2>
decltype(auto) operator*(const IndexInterface<I1,MType1>& a,
const IndexInterface<I2,MType2>& b);
template <class I1, class I2, typename MType1, typename MType2>
decltype(auto) operator*(const IndexPtr<I1,MType1>& a, const IndexPtr<I2,MType2>& b);
}
#endif

View file

@ -26,7 +26,7 @@ namespace CNORXZ
template <class PosT>
inline decltype(auto) For<L,Xpr,F>::operator()(const PosT& last) const
{
if constexpr(std::is_same<F,NoF>::value){
if constexpr(std::is_same<typename std::remove_reference<F>::type,NoF>::value){
for(SizeT i = 0; i != mSize; ++i){
const auto pos = last + mExt * UPos(i);
mXpr(pos);
@ -47,7 +47,7 @@ namespace CNORXZ
template <SizeT L, class Xpr, class F>
inline decltype(auto) For<L,Xpr,F>::operator()() const
{
if constexpr(std::is_same<F,NoF>::value){
if constexpr(std::is_same<typename std::remove_reference<F>::type,NoF>::value){
for(SizeT i = 0; i != mSize; ++i){
const auto pos = mExt * UPos(i);
mXpr(pos);

View file

@ -47,6 +47,8 @@ namespace
{
protected:
typedef MIndex<CIndex,CIndex> MCCI;
OpCont_CR_CR_Test()
{
mSize1 = 7;
@ -57,6 +59,16 @@ namespace
mData12 = Numbers::get(off+mSize1+mSize2, mSize1*mSize2);
auto cra = CRangeFactory(mSize1).create();
auto crb = CRangeFactory(mSize2).create();
mCIa1 = std::make_shared<CIndex>(cra);
mCIa2 = std::make_shared<CIndex>(cra);
mCIb1 = std::make_shared<CIndex>(crb);
mCIb2 = std::make_shared<CIndex>(crb);
mCCa1a2 = std::make_shared<MCCI>(mCIa1,mCIa2);
mCCa2a1 = std::make_shared<MCCI>(mCIa2,mCIa1);
//mCCa1a2 = mCIa1*mCIa2;
//mCCa2a1 = mCIa2*mCIa1;
mOCa1a2.init(mCCa1a2);
mORa2a1.init(mData12.data(), mCCa2a1);
}
SizeT mSize1;
@ -64,12 +76,14 @@ namespace
Vector<Double> mData1;
Vector<Double> mData2;
Vector<Double> mData12;
Sptr<CIndex> mCI1;
Sptr<CIndex> mCI2;
OpCont<double,CIndex> mOp1;
COpRoot<double,CIndex> mOp2;
OpCont<double,CIndex> mOp3;
COpRoot<double,CIndex> mOp4;
Sptr<CIndex> mCIa1;
Sptr<CIndex> mCIa2;
Sptr<CIndex> mCIb1;
Sptr<CIndex> mCIb2;
Sptr<MCCI> mCCa1a2;
Sptr<MCCI> mCCa2a1;
OpCont<double,MCCI> mOCa1a2;
COpRoot<double,MCCI> mORa2a1;
};
TEST_F(OpCont_CR_Test, Basics)
@ -131,4 +145,23 @@ namespace
}
}
TEST_F(OpCont_CR_CR_Test, Basics)
{
EXPECT_EQ(mOCa1a2.rootSteps(mCIa1->id()).val(), mCIa2->pmax().val());
EXPECT_EQ(mOCa1a2.rootSteps(mCIa2->id()).val(), 1u);
EXPECT_EQ(mORa2a1.rootSteps(mCIa1->id()).val(), 1u);
EXPECT_EQ(mORa2a1.rootSteps(mCIa2->id()).val(), mCIa1->pmax().val());
}
TEST_F(OpCont_CR_CR_Test, Assignment)
{
mOCa1a2 = mORa2a1;
for(SizeT i = 0; i != mCIa1->pmax().val(); ++i){
for(SizeT j = 0; j != mCIa2->pmax().val(); ++j){
const SizeT jS = mCIa2->pmax().val();
const SizeT iS = mCIa1->pmax().val();
EXPECT_EQ(mOCa1a2.data()[i*jS+j], mORa2a1.data()[j*iS+i]);
}
}
}
}