remove old test files

This commit is contained in:
Christian Zimmermann 2022-11-26 16:28:00 +01:00
parent 0e71d45a5b
commit 3418ec9ee1
7 changed files with 0 additions and 1922 deletions

View file

@ -1,277 +0,0 @@
// -*- C++ -*-
#include <cstdlib>
#include "gtest/gtest.h"
#include <iostream>
#include "cnorxz.h"
namespace MAT = CNORXZ;
namespace {
using namespace MAT;
template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{
vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr;
}
template <class Factory, class... Rs>
void swapMFactory(std::shared_ptr<RangeFactoryBase>& fptr, const Rs&... rs)
{
auto nptr = std::make_shared<Factory>( rs... );
fptr = nptr;
}
template <typename... Ts>
auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...))
{
return std::make_tuple(ts...);
}
class MATest_1Dim : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
MATest_1Dim()
{
swapFactory<SRF>(rfbptr, {'x', 'y', 'l', 'f', 'g'} );
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> srptr;
vector<double> vv = { 3.141, 2.718, 1.618, 0.693, 0.577 };
};
class MATest_MDim : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange> MRF;
typedef MRF::oType MRange;
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() );
}
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> mrptr;
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)
{
Array<double,MATest_1Dim::SRange> ma(srptr, vv);
EXPECT_EQ( ma.size(), 5u);
EXPECT_EQ( ma.isConst(), false);
EXPECT_EQ( ma.isSlice(), false);
auto i = ma.cbegin();
EXPECT_EQ( ma[ i.at('x') ], 3.141);
EXPECT_EQ( ma[ i.at('y') ], 2.718);
EXPECT_EQ( ma[ i.at('l') ], 1.618);
EXPECT_EQ( ma[ i.at('f') ], 0.693);
EXPECT_EQ( ma[ i.at('g') ], 0.577);
}
TEST_F(MATest_1Dim, ForLoop)
{
vector<double> v2 = { 0.693 , 2.718, 3.141, 1.618, 9.98 };
Array<double,MATest_1Dim::SRange> ma(srptr, std::move( v2 ) );
size_t cnt = 0;
for(auto el: ma){
if(cnt == 0){
EXPECT_EQ(el, 0.693);
} else if(cnt == 1u){
EXPECT_EQ(el, 2.718);
} else if(cnt == 2u){
EXPECT_EQ(el, 3.141);
} else if(cnt == 3u){
EXPECT_EQ(el, 1.618);
} else if(cnt == 4u){
EXPECT_EQ(el, 9.98);
} else {
EXPECT_EQ(cnt, 0u);
}
++cnt;
}
EXPECT_EQ(cnt, ma.size());
}
TEST_F(MATest_1Dim, ReFormat)
{
swapFactory<SRF>( rfbptr, { 'a', 'c', 'e', 'g', 'i' } );
std::shared_ptr<SRange> sr2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
Array<double,MATest_1Dim::SRange> ma(srptr, vv);
auto i = ma.cbegin();
EXPECT_EQ( ma[ i.at('x') ], 3.141);
auto ma2 = ma.format( sr2 );
auto j = ma2.cbegin();
EXPECT_EQ( ma[ j.at('a') ], 3.141);
EXPECT_EQ( ma[ j.at('c') ], 2.718);
EXPECT_EQ( ma[ j.at('e') ], 1.618);
EXPECT_EQ( ma[ j.at('g') ], 0.693);
EXPECT_EQ( ma[ j.at('i') ], 0.577);
}
TEST_F(MATest_MDim, SimpleCall)
{
Array<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
EXPECT_EQ( ma.size(), 24u );
EXPECT_EQ( ma.range()->dim(), 2u );
auto i = ma.cbegin();
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)
{
Array<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
auto ma2 = ma.format( sr4ptr );
auto i = ma2.cbegin();
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 );
}
TEST_F(MATest_MDim, SliceTest1)
{
Array<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
Slice<double,MATest_MDim::SRange> sl(sr3ptr);
auto i = MAT::getIndex(sr3ptr);
auto mi = MAT::getIndex(mrptr);
mi->at( mkt('y', 'f') );
sl.define(i) = ma(mi, i);
EXPECT_EQ( sl.at('1'), 6.712 );
EXPECT_EQ( sl.at('2'), 6.408 );
EXPECT_EQ( sl.at('3'), 1.959 );
Slice<double,SRange> sl2(sr2ptr);
auto j = MAT::getIndex(sr3ptr);
auto mj = MAT::getIndex(mrptr);
mj->at( mkt('y','a') );
j->at('2');
auto jj = mj->template getPtr<1>();
sl2.define(jj) = ma(mj, j);
EXPECT_EQ( sl2.at('a'), 3.084 );
EXPECT_EQ( sl2.at('l'), 8.175 );
EXPECT_EQ( sl2.at('f'), 6.408 );
EXPECT_EQ( sl2.at('g'), 4.209 );
Slice<double,SRange,SRange,SRange> sl3(sr3ptr, sr1ptr, sr2ptr);
mj->at( mkt('x','a') );
auto j1 = MAT::getIndex(sr1ptr);
auto j2 = MAT::getIndex(sr2ptr);
(*mj)(j1,j2);
j->at('1');
sl3.define(j, j1, j2) = ma(mj, j);
auto ci = sl3.begin();
EXPECT_EQ( sl3.at( mkt('1', 'x','a') ), 2.917 );
EXPECT_EQ( *ci, 2.917 );
EXPECT_EQ( sl3.at( mkt('2', 'x','a') ), 9.436 );
EXPECT_EQ( sl3.at( mkt('3', 'x','a') ), 0.373 );
EXPECT_EQ( sl3.at( mkt('1', 'x','l') ), 7.192 );
EXPECT_EQ( *(++ci), 7.192 );
EXPECT_EQ( sl3.at( mkt('2', 'x','l') ), 7.315 );
EXPECT_EQ( sl3.at( mkt('3', 'x','l') ), 1.536 );
EXPECT_EQ( sl3.at( mkt('1', 'x','f') ), 4.892 );
EXPECT_EQ( *(++ci), 4.892 );
EXPECT_EQ( sl3.at( mkt('2', 'x','f') ), 0.280 );
EXPECT_EQ( sl3.at( mkt('3', 'x','f') ), 8.870 );
EXPECT_EQ( sl3.at( mkt('1', 'x','g') ), 4.790 );
EXPECT_EQ( *(++ci), 4.790 );
EXPECT_EQ( sl3.at( mkt('2', 'x','g') ), 8.215 );
EXPECT_EQ( sl3.at( mkt('3', 'x','g') ), 5.063 );
EXPECT_EQ( sl3.at( mkt('1', 'y','a') ), 1.530 );
EXPECT_EQ( *(++ci), 1.530 );
EXPECT_EQ( sl3.at( mkt('2', 'y','a') ), 3.084 );
EXPECT_EQ( sl3.at( mkt('3', 'y','a') ), 1.609 );
EXPECT_EQ( sl3.at( mkt('1', 'y','l') ), 4.847 );
EXPECT_EQ( *(++ci), 4.847 );
EXPECT_EQ( sl3.at( mkt('2', 'y','l') ), 8.175 );
EXPECT_EQ( sl3.at( mkt('3', 'y','l') ), 0.112 );
EXPECT_EQ( sl3.at( mkt('1', 'y','f') ), 6.712 );
EXPECT_EQ( *(++ci), 6.712 );
EXPECT_EQ( sl3.at( mkt('2', 'y','f') ), 6.408 );
EXPECT_EQ( sl3.at( mkt('3', 'y','f') ), 1.959 );
EXPECT_EQ( sl3.at( mkt('1', 'y','g') ), 0.331 );
EXPECT_EQ( *(++ci), 0.331 );
EXPECT_EQ( sl3.at( mkt('2', 'y','g') ), 4.209 );
EXPECT_EQ( sl3.at( mkt('3', 'y','g') ), 2.951 );
EXPECT_EQ( *(++ci), 9.436 );
EXPECT_EQ( *(++ci), 7.315 );
}
} // end namespace
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View file

@ -1,251 +0,0 @@
#include "test_header.h"
namespace
{
class OpTest_Sub : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
OpTest_Sub()
{
swapFactory<SRF>(rfbptr, {'x', 'l'} );
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() );
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> sr1ptr;
std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<SRange> sr3ptr;
vector<double> v1 = { 2.917, 9.436, 0.373, 0.353, 4.005, 1.070,
-14.364, -1.868, -25.703, 13.836, 23.563, 41.339 };
vector<double> v2 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 };
};
class MapTest : public ::testing::Test
{
protected:
typedef SingleRangeFactory<size_t,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
typedef typename SRange::IndexType SIndex;
std::shared_ptr<SRange> sr1ptr;
std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<SIndex> si1ptr;
std::shared_ptr<SIndex> si2ptr;
vector<double> v1 = { -31.71, -77.16, -18.81,
-67.06, 72.31, -54.48,
-50.91, -11.62, -59.57,
-42.53, 80.41, 6.35 };
typedef std::remove_reference<decltype(*mkMapR( mkMapOp(std::make_shared<plus<size_t>>(),getIndex(sr1ptr),getIndex(sr2ptr)) , sr1ptr, sr2ptr ))>::type MpRange;
std::shared_ptr<MpRange> mpr1ptr;
//typedef MpRange::ORType TRange;
typedef std::remove_reference<decltype(*mpr1ptr->outRange())>::type TRange;
MapTest()
{
SRF srf1( { 1, 3, 7, 10 } );
SRF srf2( { 2, 6, 8 } );
sr1ptr = std::dynamic_pointer_cast<SRange>( srf1.create() );
sr2ptr = std::dynamic_pointer_cast<SRange>( srf2.create() );
si1ptr = getIndex(sr1ptr);
si2ptr = getIndex(sr2ptr);
mpr1ptr = mkMapR( mkMapOp(std::make_shared<plus<size_t>>(),si1ptr,si2ptr) , sr1ptr, sr2ptr );
}
};
class MetaOp_Test : public ::testing::Test
{
protected:
typedef SingleRangeFactory<double,SpaceType::ANY> SRF;
typedef SRF::oType SR;
const size_t s1 = 10;
const size_t s2 = 17;
MetaOp_Test()
{
mv1 = { 2.476, 9.665, 1.289, 2.89, 77.04, -11.09, 100.4, 2.0, -26.5, -0.001 };
mv2 = { 44.56, 23.097, -117.3, -0.0765, 3.445, 0.02389, -4.0112, 10.567, 8.99, -177.2, 475.3,
11.111, 13.108, -35.6, 64.32, 2.44, -12.};
assert(mv1.size() == s1); // just to prevent typos...
assert(mv2.size() == s2);
swapFactory<SRF>(rfbptr, mv1);
sr1ptr = std::dynamic_pointer_cast<SR>(rfbptr->create());
swapFactory<SRF>(rfbptr, mv2);
sr2ptr = std::dynamic_pointer_cast<SR>(rfbptr->create());
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SR> sr1ptr;
std::shared_ptr<SR> sr2ptr;
vector<double> mv1;
vector<double> mv2;
double vcontract(size_t i)
{
double res = 0.;
for(auto& x: mv2){
res += pow(mv1[i],x);
}
return res;
}
};
TEST_F(MapTest, Exec1)
{
Array<double,SRange,SRange> ma1(sr1ptr,sr2ptr,v1);
auto ii1 = getIndex( rptr<0>( ma1 ) );
auto ii2 = getIndex( rptr<1>( ma1 ) );
auto mr = mkMapR( mkMapOp(std::make_shared<plus<size_t>>(),ii1,ii2) , sr1ptr, sr2ptr );
//auto mr = mkMapR(std::make_shared<plus<size_t>>(),sr1ptr,sr2ptr);
Array<double,MpRange> res(mr);
Array<double,MpRange> res2(mr);
auto jj = getIndex( mr );
(*jj)(ii1,ii2);
///auto jj = mkMapI( std::make_shared<plus<size_t> >(), ii1, ii1 );
res(jj) += ma1(ii1,ii2);
auto mult = mr->explMapMultiplicity();
res2(jj) += ma1(ii1,ii2) / staticcast<double>( mult(jj) );
Array<double,TRange> form = res.format(mpr1ptr->outRange());
Array<double,TRange> form2 = res2.format(mpr1ptr->outRange());
EXPECT_EQ( jj->range()->outRange()->size(), static_cast<size_t>( 10 ) );
EXPECT_EQ( jj->range()->mapMultiplicity().at(9), static_cast<size_t>( 3 ) );
EXPECT_EQ( jj->range()->mapMultiplicity().at(3), static_cast<size_t>( 1 ) );
EXPECT_EQ( form.at(3), -31.71 );
EXPECT_EQ( form.at(7), -77.16 );
EXPECT_EQ( form.at(9), -18.81 + 72.31 -50.91 );
EXPECT_EQ( form.at(5), -67.06 );
EXPECT_EQ( form.at(11), -54.48 );
EXPECT_EQ( form.at(13), -11.62 );
EXPECT_EQ( form.at(15), -59.57 );
EXPECT_EQ( form.at(12), -42.53 );
EXPECT_EQ( form.at(16), 80.41 );
EXPECT_EQ( form.at(18), 6.35 );
EXPECT_EQ( form2.at(3), -31.71 );
EXPECT_EQ( form2.at(7), -77.16 );
EXPECT_EQ( xround( form2.at(9) ), xround( (-18.81 + 72.31 -50.91) / 3. ) );
EXPECT_EQ( form2.at(5), -67.06 );
EXPECT_EQ( form2.at(11), -54.48 );
EXPECT_EQ( form2.at(13), -11.62 );
EXPECT_EQ( form2.at(15), -59.57 );
EXPECT_EQ( form2.at(12), -42.53 );
EXPECT_EQ( form2.at(16), 80.41 );
EXPECT_EQ( form2.at(18), 6.35 );
}
TEST_F(MetaOp_Test, SimpleCall)
{
FunctionalArray<double,Pow<double>,SR,SR> fma(sr1ptr, sr2ptr);
auto i = fma.begin();
EXPECT_EQ( xround( fma[ i.at( mkt(9.665, -0.0765) ) ] ), xround( pow(9.665, -0.0765) ) );
}
TEST_F(MetaOp_Test, Operation)
{
FunctionalArray<double,Pow<double>,SR,SR> fma(sr1ptr, sr2ptr);
Array<double,SR> res( sr1ptr );
auto i1 = MAT::getIndex(sr1ptr);
auto i2 = MAT::getIndex(sr2ptr);
res(i1) += fma(i1,i2).c(i2);
auto i = res.begin();
EXPECT_EQ( xround( res[ i.at( 2.476 ) ] ), xround( vcontract(0) ) );
EXPECT_EQ( xround( res[ i.at( 9.665 ) ] ), xround( vcontract(1) ) );
EXPECT_EQ( xround( res[ i.at( 1.289 ) ] ), xround( vcontract(2) ) );
EXPECT_EQ( xround( res[ i.at( 2.89 ) ] ), xround( vcontract(3) ) );
EXPECT_EQ( xround( res[ i.at( 77.04 ) ] ), xround( vcontract(4) ) );
EXPECT_EQ( xround( res[ i.at( -11.09 ) ] ), xround( vcontract(5) ) );
EXPECT_EQ( xround( res[ i.at( 100.4 ) ] ), xround( vcontract(6) ) );
EXPECT_EQ( xround( res[ i.at( 2.0 ) ] ), xround( vcontract(7) ) );
EXPECT_EQ( xround( res[ i.at( -26.5 ) ] ), xround( vcontract(8) ) );
EXPECT_EQ( xround( res[ i.at( -0.001 ) ] ), xround( vcontract(9) ) );
}
TEST_F(OpTest_Sub, Exec)
{
Array<double,SRange,SRange,SRange> ma1(sr1ptr, sr2ptr, sr3ptr, v1);
Array<double,SRange,SRange> ma2(sr3ptr, sr2ptr, v2);
SubRangeFactory<SRange> subf(sr2ptr, vector<size_t>({0,2}));
auto subptr = MAT::createExplicit(subf);
Array<double,SRange,SRange> res(sr3ptr,sr1ptr,0.);
Array<double,SRange,SubRange<SRange>,SRange> res2(sr3ptr,subptr,sr1ptr,0.);
auto i1 = MAT::getIndex( sr1ptr );
auto i2 = MAT::getIndex( sr2ptr );
auto i3 = MAT::getIndex( sr3ptr );
auto si = MAT::getIndex( subptr );
(*si)(i2);
res(i3,i1) += (ma2(i3,i2) - ma1(i1,i2,i3)).c(si);
res2(i3,si,i1) = ma2(i3,i2) - ma1(i1,i2,i3);
EXPECT_EQ( res2.size(), static_cast<size_t>(8) );
EXPECT_EQ( res2.vdata().size(), static_cast<size_t>(8) );
EXPECT_EQ( MAT::rptr<1>( res2 )->size(), static_cast<size_t>(2) );
EXPECT_EQ( MAT::rptr<1>( res2 )->isMeta('1'), true );
EXPECT_EQ( MAT::rptr<1>( res2 )->isMeta('3'), true );
EXPECT_EQ( xround( res.at(mkt('a','x')) ), xround((ma2.at(mkt('a','1')) - ma1.at(mkt('x','1','a'))) + (ma2.at(mkt('a','3')) - ma1.at(mkt('x','3','a')) ) ));
EXPECT_EQ( xround( res.at(mkt('a','l')) ), xround((ma2.at(mkt('a','1')) - ma1.at(mkt('l','1','a'))) + (ma2.at(mkt('a','3')) - ma1.at(mkt('l','3','a')) ) ));
EXPECT_EQ( xround( res.at(mkt('b','x')) ), xround((ma2.at(mkt('b','1')) - ma1.at(mkt('x','1','b'))) + (ma2.at(mkt('b','3')) - ma1.at(mkt('x','3','b')) ) ) );
EXPECT_EQ( xround( res.at(mkt('b','l')) ), xround((ma2.at(mkt('b','1')) - ma1.at(mkt('l','1','b'))) + (ma2.at(mkt('b','3')) - ma1.at(mkt('l','3','b')) ) ) );
EXPECT_EQ( xround( res2.at(mkt('a','1','x')) ), xround(ma2.at(mkt('a','1')) - ma1.at(mkt('x','1','a'))) );
EXPECT_EQ( xround( res2.at(mkt('a','1','l')) ), xround(ma2.at(mkt('a','1')) - ma1.at(mkt('l','1','a'))) );
EXPECT_EQ( xround( res2.at(mkt('b','1','x')) ), xround(ma2.at(mkt('b','1')) - ma1.at(mkt('x','1','b'))) );
EXPECT_EQ( xround( res2.at(mkt('b','1','l')) ), xround(ma2.at(mkt('b','1')) - ma1.at(mkt('l','1','b'))) );
EXPECT_EQ( xround( res2.at(mkt('a','3','x')) ), xround(ma2.at(mkt('a','3')) - ma1.at(mkt('x','3','a'))) );
EXPECT_EQ( xround( res2.at(mkt('a','3','l')) ), xround(ma2.at(mkt('a','3')) - ma1.at(mkt('l','3','a'))) );
EXPECT_EQ( xround( res2.at(mkt('b','3','x')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('x','3','b'))) );
EXPECT_EQ( xround( res2.at(mkt('b','3','l')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('l','3','b'))) );
}
}

View file

@ -1,119 +0,0 @@
#include "test_header.h"
namespace
{
class OpTest_Spin : public ::testing::Test
{
protected:
typedef SpinRF SRF;
typedef SpinRange SR;
typedef MultiRangeFactory<SR,SR,SR,SR,SR,SR,SR,SR> SR8F;
typedef SR8F::oType SR8;
static const size_t s = 65536;
OpTest_Spin()
{
data.resize(s);
for(size_t i = 0; i != s; ++i){
const double arg = static_cast<double>( s - i ) - 0.1;
data[i] = sin(arg)*10;
}
SRF f;
sr = std::dynamic_pointer_cast<SR>(f.create());
}
vector<double> data;
std::shared_ptr<SR> sr;
};
TEST_F(OpTest_Spin, Contract)
{
Array<double,SR,SR,SR,SR,SR,SR,SR,SR> ma(sr, sr, sr, sr, sr, sr, sr, sr, data);
Array<double,SR,SR> res1( sr, sr );
Array<double,SR,SR> res2( sr, sr );
auto alpha = MAT::getIndex<SR>();
auto beta = MAT::getIndex<SR>();
auto gamma = MAT::getIndex<SR>();
auto delta = MAT::getIndex<SR>();
auto deltap = MAT::getIndex<SR>();
auto mix = MAT::mkMIndex( alpha, beta, gamma );
std::clock_t begin = std::clock();
res1(delta, deltap) += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix);
//res1(delta, deltap) += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap);
std::clock_t end = std::clock();
std::cout << "Array time: " << static_cast<double>( end - begin ) / CLOCKS_PER_SEC
<< std::endl;
res2(delta, deltap).par() += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(alpha).c(beta).c(gamma);
vector<double> vres(4*4);
std::clock_t begin2 = std::clock();
for(size_t d = 0; d != 4; ++d){
for(size_t p = 0; p != 4; ++p){
const size_t tidx = d*4 + p;
vres[tidx] = 0.;
for(size_t a = 0; a != 4; ++a){
for(size_t b = 0; b != 4; ++b){
for(size_t c = 0; c != 4; ++c){
const size_t sidx = d*4*4*4*4*4*4*4 + a*5*4*4*4*4*4 + b*5*4*4*4 + c*5*4 + p;
vres[tidx] += data[sidx];
}
}
}
}
}
std::clock_t end2 = std::clock();
EXPECT_EQ( xround(res1.at(mkts(0,0))), xround(vres[0]) );
EXPECT_EQ( xround(res1.at(mkts(0,1))), xround(vres[1]) );
EXPECT_EQ( xround(res1.at(mkts(0,2))), xround(vres[2]) );
EXPECT_EQ( xround(res1.at(mkts(0,3))), xround(vres[3]) );
EXPECT_EQ( xround(res1.at(mkts(1,0))), xround(vres[4]) );
EXPECT_EQ( xround(res1.at(mkts(1,1))), xround(vres[5]) );
EXPECT_EQ( xround(res1.at(mkts(1,2))), xround(vres[6]) );
EXPECT_EQ( xround(res1.at(mkts(1,3))), xround(vres[7]) );
EXPECT_EQ( xround(res1.at(mkts(2,0))), xround(vres[8]) );
EXPECT_EQ( xround(res1.at(mkts(2,1))), xround(vres[9]) );
EXPECT_EQ( xround(res1.at(mkts(2,2))), xround(vres[10]) );
EXPECT_EQ( xround(res1.at(mkts(2,3))), xround(vres[11]) );
EXPECT_EQ( xround(res1.at(mkts(3,0))), xround(vres[12]) );
EXPECT_EQ( xround(res1.at(mkts(3,1))), xround(vres[13]) );
EXPECT_EQ( xround(res1.at(mkts(3,2))), xround(vres[14]) );
EXPECT_EQ( xround(res1.at(mkts(3,3))), xround(vres[15]) );
EXPECT_EQ( xround(res2.at(mkts(0,0))), xround(vres[0]) );
EXPECT_EQ( xround(res2.at(mkts(0,1))), xround(vres[1]) );
EXPECT_EQ( xround(res2.at(mkts(0,2))), xround(vres[2]) );
EXPECT_EQ( xround(res2.at(mkts(0,3))), xround(vres[3]) );
EXPECT_EQ( xround(res2.at(mkts(1,0))), xround(vres[4]) );
EXPECT_EQ( xround(res2.at(mkts(1,1))), xround(vres[5]) );
EXPECT_EQ( xround(res2.at(mkts(1,2))), xround(vres[6]) );
EXPECT_EQ( xround(res2.at(mkts(1,3))), xround(vres[7]) );
EXPECT_EQ( xround(res2.at(mkts(2,0))), xround(vres[8]) );
EXPECT_EQ( xround(res2.at(mkts(2,1))), xround(vres[9]) );
EXPECT_EQ( xround(res2.at(mkts(2,2))), xround(vres[10]) );
EXPECT_EQ( xround(res2.at(mkts(2,3))), xround(vres[11]) );
EXPECT_EQ( xround(res2.at(mkts(3,0))), xround(vres[12]) );
EXPECT_EQ( xround(res2.at(mkts(3,1))), xround(vres[13]) );
EXPECT_EQ( xround(res2.at(mkts(3,2))), xround(vres[14]) );
EXPECT_EQ( xround(res2.at(mkts(3,3))), xround(vres[15]) );
std::cout << "vector - for loop time: " << static_cast<double>( end2 - begin2 ) / CLOCKS_PER_SEC
<< std::endl;
std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl;
}
}

View file

@ -1,351 +0,0 @@
#include "test_header.h"
#include "hl_cnorxz.h"
#include <ctime>
namespace
{
template <class MA>
void setMARandom(MA& ma, int seed)
{
std::srand(seed);
double n = 0;
double d = 0;
for(auto& x: ma.vdata()){
double nx = 0;
double dx = 0;
while(nx == x or dx == d or nx == dx or dx == 0){
nx = static_cast<double>(std::rand() % 1000);
dx = static_cast<double>(std::rand() % 1000);
}
n = nx;
d = dx;
assert(n != d);
x = n/d;
}
}
template <class Op>
DynamicO<double> mkDynOp(const Op& op)
{
return DynamicO<double>(op);
}
template <class Op1, class Op2>
DynamicO<double> mkDynMul(const Op1& op1, const Op2& op2)
{
auto op = op1 * op2;
return DynamicO<double>(std::make_shared<DynamicOperation<double,decltype(op)>>(op));
}
class OpTest_Dyn : public ::testing::Test
{
protected:
Array<double,CR,DR> ma1;
Array<double,CR,DR> ma2;
Array<double,DR> ma3;
Array<double,DR> ma5;
Array<double,CR,DR> res1;
Array<double,CR,DR> res2;
std::map<std::string,std::shared_ptr<IndexW>> imap;
std::shared_ptr<DR> dr1;
//std::shared_ptr<DR> dr1a;
std::shared_ptr<DR> dr2;
std::shared_ptr<DR> dr3;
std::shared_ptr<DR> dr4;
std::shared_ptr<DR> dr4a;
std::shared_ptr<DR> dr5;
std::shared_ptr<DR> dr6;
std::shared_ptr<DR> dr6a;
std::shared_ptr<CR> cr1;
std::shared_ptr<CR::IndexType> ci4_1;
std::shared_ptr<CR::IndexType> ci4_2;
typedef CR::IndexType CI;
OpTest_Dyn()
{
cr1 = createRangeE<CR>(5);
auto cr2 = createRangeE<CR>(7);
//auto cr2 = createRangeE<CR>(2);
auto cr3 = createRangeE<CR>(11);
auto cr4 = createRangeE<CR>(3);
auto cr5 = createRangeE<CR>(13);
//auto cr5 = createRangeE<CR>(1);
dr1 = createRangeE<DR>(cr2,cr2,cr3,cr4);
//dr1a = createRangeE<DR>(cr2,cr2,cr3);
dr2 = createRangeE<DR>(cr3,cr3,cr4);
dr3 = createRangeE<DR>(cr2,cr5);
dr5 = createRangeE<DR>(cr5);
dr6 = createRangeE<DR>(cr3,cr4);
dr6a = createRangeE<DR>(cr3,cr2,cr5);
dr4 = createRangeE<DR>(cr2,cr3,cr4,cr4);
dr4a = createRangeE<DR>(cr2,cr3);
ma1 = mkArray<double>(cr1,dr1);
ma2 = mkArray<double>(cr1,dr2);
ma3 = mkArray<double>(dr3);
ma5 = mkArray<double>(dr5);
res1 = mkArray<double>(cr1,dr4);
res2 = mkArray<double>(cr1,dr6);
setMARandom(ma1, 25);
setMARandom(ma2, 31);
setMARandom(ma3, 47);
setMARandom(ma5, 59);
imap["i2_1"] = mkIndexW(getIndex(cr2));
imap["i2_2"] = mkIndexW(getIndex(cr2));
imap["i3_1"] = mkIndexW(getIndex(cr3));
imap["i3_2"] = mkIndexW(getIndex(cr3));
ci4_1 = getIndex(cr4);
ci4_2 = getIndex(cr4);
imap["i4_1"] = mkIndexW(ci4_1);
imap["i4_2"] = mkIndexW(ci4_2);
imap["i5_1"] = mkIndexW(getIndex(cr5));
imap["i5_2"] = mkIndexW(getIndex(cr5));
}
};
TEST_F(OpTest_Dyn, Multiply)
{
auto i1 = getIndex(cr1);
auto di1 = getIndex(dr1);
//auto di1a = getIndex(dr1a);
auto di2 = getIndex(dr2);
auto di4 = getIndex(dr4);
auto di4a = getIndex(dr4a);
(*di1)({imap["i2_1"],imap["i2_2"],imap["i3_1"],imap["i4_1"]});
//(*di1a)({imap["i2_1"],imap["i2_2"],imap["i3_1"]});
(*di2)({imap["i3_1"],imap["i3_1"],imap["i4_2"]});
(*di4)({imap["i2_1"],imap["i3_1"],imap["i4_1"],imap["i4_2"]});
(*di4a)({imap["i2_1"],imap["i3_1"]});
auto mi = mkMIndex(i1,di4a);
auto resx1 = res1;
auto resx2 = res1;
auto resx3 = res1;
auto resx4 = res1;
auto xx = std::make_shared<decltype(resx4)>(resx4);
res1(i1,di4) = ma1(i1,di1) * ma2(i1,di2);
resx1(i1,di4) = mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2));
resx2(i1,di4) = mkDynOp(ma1(i1,di1) * ma2(i1,di2));
resx3(i1,di4) = mkDynOp(mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2)));
auto op1x = mkDynOutOp((ma1(i1,di1) * ma2(i1,di2)), ci4_1, ci4_2);
auto opr = resx4(i1,di4);
auto loop = mkPILoop
( [&op1x,&opr,&xx,this](){
auto op1 = op1x;
return mkGetExpr(op1,mkILoop(std::make_tuple(opr,op1,*op1.data()->mOp), std::make_tuple(ci4_1, ci4_2),
std::make_tuple(xx),
std::make_tuple(opr.assign( *op1.data()->mOp, mkMIndex(ci4_1, ci4_2) )),
std::array<size_t,1>({1}), std::array<size_t,1>({0}))); } );
//loop.dummy();
mi->pifor(1,loop)();
auto i2_1 = imap.at("i2_1");
auto i2_2 = imap.at("i2_2");
auto i3_1 = imap.at("i3_1");
auto i4_1 = imap.at("i4_1");
auto i4_2 = imap.at("i4_2");
for(size_t ii1 = 0; ii1 != i1->max(); ++ii1){
for(size_t ii2_1 = 0; ii2_1 != i2_1->max(); ++ii2_1){
size_t ii2_2 = 0;
for(size_t ii3_1 = 0; ii3_1 != i3_1->max(); ++ii3_1){
for(size_t ii4_1 = 0; ii4_1 != i4_1->max(); ++ii4_1){
for(size_t ii4_2 = 0; ii4_2 != i4_2->max(); ++ii4_2){
const size_t jr = (((ii1*i2_1->max() + ii2_1)*i3_1->max() + ii3_1)*i4_1->max() + ii4_1)*i4_2->max() + ii4_2;
const size_t j1 = (((ii1*i2_1->max() + ii2_1)*i2_2->max() + ii2_2)*i3_1->max() + ii3_1)*i4_1->max() + ii4_1;
const size_t j2 = ((ii1*i3_1->max() + ii3_1)*i3_1->max() + ii3_1)*i4_2->max() + ii4_2;
auto resv = xround(res1.vdata()[jr]);
auto resx1v = xround(resx1.vdata()[jr]);
auto resx2v = xround(resx2.vdata()[jr]);
auto resx3v = xround(resx3.vdata()[jr]);
auto resx4v = xround(resx4.vdata()[jr]);
auto x12 = xround(ma1.vdata()[j1]*ma2.vdata()[j2]);
EXPECT_EQ( resv, x12 );
EXPECT_EQ( resx1v, x12 );
EXPECT_EQ( resx2v, x12 );
EXPECT_EQ( resx3v, x12 );
EXPECT_EQ( resx4v, x12 );
}
}
}
}
//std::cout << std::endl;
}
}
TEST_F(OpTest_Dyn, Contract)
{
auto i1 = getIndex(cr1);
auto di1 = getIndex(dr1);
auto di3 = getIndex(dr3);
auto di5 = getIndex(dr5);
auto di6 = getIndex(dr6);
auto di6a = getIndex(dr6a);
(*di1)({imap["i2_1"],imap["i2_1"],imap["i3_1"],imap["i4_1"]});
(*di3)({imap["i2_1"],imap["i5_1"]});
(*di5)({imap["i5_1"]});
(*di6)({imap["i3_1"],imap["i4_1"]});
(*di6a)({imap["i3_1"],imap["i2_1"],imap["i5_1"]});
auto resx1 = res2;
auto resx2 = res2;
auto resx3 = res2;
auto resx4 = res2;
res2(i1,di6) += (ma1(i1,di1) * ma5(di5)).c(di3);
resx1(i1,di6) += (mkDynOp(ma1(i1,di1)) * mkDynOp(ma5(di5))).c(di3);
resx2(i1,di6) += mkDynOp((ma1(i1,di1) * ma5(di5)).c(di3));
resx3(i1,di6) += mkDynOp((mkDynOp(ma1(i1,di1)) * mkDynOp(ma5(di5))).c(di3));
auto xx = std::make_shared<decltype(resx4)>(resx4);
auto mi = mkMIndex(i1,di6a);
auto op1 = ma1(i1,di1);
auto op2 = ma5(di5);
auto opr = resx4(i1,di6);
auto loop = mkPILoop
( [&opr,&op1,&op2,&xx,&di3,this](){
auto dop1 = mkDynOutOp(op1 * op2, ci4_1);
return mkGetExpr
(dop1,mkILoop
(std::make_tuple(opr,*dop1.data()->mOp), std::make_tuple(ci4_1),
std::make_tuple(xx),
std::make_tuple(opr.plus( *dop1.data()->mOp, mkMIndex(ci4_1) )),
std::array<size_t,1>({1}), std::array<size_t,1>({0}))); } );
mi->pifor(1,loop)();
auto i2_1 = imap.at("i2_1");
auto i3_1 = imap.at("i3_1");
auto i4_1 = imap.at("i4_1");
auto i5_1 = imap.at("i5_1");
for(size_t ii1 = 0; ii1 != i1->max(); ++ii1){
for(size_t ii3_1 = 0; ii3_1 != i3_1->max(); ++ii3_1){
for(size_t ii4_1 = 0; ii4_1 != i4_1->max(); ++ii4_1){
double vv = 0;
const size_t jr = (ii1*i3_1->max() + ii3_1)*i4_1->max() + ii4_1;
for(size_t ii2_1 = 0; ii2_1 != i2_1->max(); ++ii2_1){
const size_t j1 = (((ii1*i2_1->max() + ii2_1)*i2_1->max() + ii2_1)*i3_1->max() + ii3_1)*i4_1->max() + ii4_1;
for(size_t ii5_1 = 0; ii5_1 != i5_1->max(); ++ii5_1){
const size_t j2 = ii5_1;
vv += ma1.vdata()[j1] * ma5.vdata()[j2];
}
}
auto resv = xround(res2.vdata()[jr]);
auto resx1v = xround(resx1.vdata()[jr]);
auto resx2v = xround(resx2.vdata()[jr]);
auto resx3v = xround(resx3.vdata()[jr]);
auto resx4v = xround(resx4.vdata()[jr]);
auto x12 = xround(vv);
EXPECT_EQ( resv, x12 );
EXPECT_EQ( resx1v, x12 );
EXPECT_EQ( resx2v, x12 );
EXPECT_EQ( resx3v, x12 );
EXPECT_EQ( resx4v, x12 );
}
}
//std::cout << std::endl;
}
}
typedef vector<std::string> svec;
TEST_F(OpTest_Dyn, Functional)
{
auto i1 = getIndex(cr1);
auto di1 = getIndex(dr1);
auto di2 = getIndex(dr2);
auto di4 = getIndex(dr4);
auto di4a = getIndex(dr4a);
(*di1)({"ia_1","ia_2","ib_1","ic_1"});
(*di2)({"ib_1","ib_1","ic_2"});
(*di4)({"ia_1","ib_1","ic_1","ic_2"});
(*di4a)(svec({"ia_1","ib_1"}));
auto ic_1 = DynamicIndex::getIndexFromMap<CI>("ic_1");
auto ic_2 = DynamicIndex::getIndexFromMap<CI>("ic_2");
//VCHECK(reinterpret_cast<std::intptr_t>(ic_1.get()));
//VCHECK(reinterpret_cast<std::intptr_t>(ic_2.get()));
auto resx1 = res1;
auto resx2 = res1;
auto resx3 = res1;
auto resx4 = res1;
res1(i1,di4) = ma1(i1,di1) * exp(ma2(i1,di2));
resx1(i1,di4) = mkDynOp(ma1(i1,di1)) * exp(mkDynOp(ma2(i1,di2)));
resx2(i1,di4) = mkDynOp(ma1(i1,di1) * exp(ma2(i1,di2)));
resx3(i1,di4) = mkDynOp(mkDynOp(ma1(i1,di1)) * mkDynOp(exp(mkDynOp(ma2(i1,di2)))));
auto xx = mkArrayPtr<double>(nullr());
auto mi = mkMIndex(i1,di4a);
auto hop1 = mkHLO(ma2(i1,di2));
auto hop3 = mkHLO(ma1(i1,di1));
auto hop2 = hl_exp(hop1);
auto hop4 = hop3 * hop2;
auto hopr = mkHLO(resx4(i1,di4));
auto hop5 = mkHLOV<OpCD>(1.);
auto hop6 = hop4 - hop5;
//hopr.assign( hop4, mi, ic_1, ic_2 );
hopr.xassign( hop6, di4, i1 );
auto i2_1 = imap.at("i2_1");
auto i2_2 = imap.at("i2_2");
auto i3_1 = imap.at("i3_1");
auto i4_1 = imap.at("i4_1");
auto i4_2 = imap.at("i4_2");
for(size_t ii1 = 0; ii1 != i1->max(); ++ii1){
for(size_t ii2_1 = 0; ii2_1 != i2_1->max(); ++ii2_1){
size_t ii2_2 = 0;
for(size_t ii3_1 = 0; ii3_1 != i3_1->max(); ++ii3_1){
for(size_t ii4_1 = 0; ii4_1 != i4_1->max(); ++ii4_1){
for(size_t ii4_2 = 0; ii4_2 != i4_2->max(); ++ii4_2){
const size_t jr = (((ii1*i2_1->max() + ii2_1)*i3_1->max() + ii3_1)*i4_1->max() + ii4_1)*i4_2->max() + ii4_2;
const size_t j1 = (((ii1*i2_1->max() + ii2_1)*i2_2->max() + ii2_2)*i3_1->max() + ii3_1)*i4_1->max() + ii4_1;
const size_t j2 = ((ii1*i3_1->max() + ii3_1)*i3_1->max() + ii3_1)*i4_2->max() + ii4_2;
auto resv = xround(res1.vdata()[jr]);
auto resx1v = xround(resx1.vdata()[jr]);
auto resx2v = xround(resx2.vdata()[jr]);
auto resx3v = xround(resx3.vdata()[jr]);
auto resx4v = xround(resx4.vdata()[jr]);
auto x12 = xround(ma1.vdata()[j1]*exp(ma2.vdata()[j2]));
auto x121 = xround(ma1.vdata()[j1]*exp(ma2.vdata()[j2])-1.);
EXPECT_EQ( resv, x12 );
EXPECT_EQ( resx1v, x12 );
EXPECT_EQ( resx2v, x12 );
EXPECT_EQ( resx3v, x12 );
EXPECT_EQ( resx4v, x121 );
}
}
}
}
//std::cout << std::endl;
}
}
}

View file

@ -1,343 +0,0 @@
// -*- C++ -*-
#include "test_header.h"
namespace
{
class OpTest_1Dim : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
OpTest_1Dim()
{
swapFactory<SRF>(rfbptr, {'a', 'l', 'f', 'g'} );
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> srptr;
vector<double> v1 = { 2.917, 9.436, 0.373, 7.192 };
vector<double> v2 = { 8.870, 4.790, 8.215, 5.063 };
};
class OpTest_MDim : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange> MRF;
typedef MRF::oType MRange;
typedef AnonymousRange ANO;
typedef Array<double,ANO> AMA;
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;
vector<double> v1 = { 2.917, 9.436, 0.373 };
vector<double> v2 = { 8.870, 4.790 };
vector<double> v3 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 };
vector<double> v4 = { 1.470, 2.210 };
vector<double> v5 = { 30.932, -33.693, -26.205, -15.504, 21.227, 17.829,
-14.364, -1.868, -25.703, 13.836, 23.563, 41.339 };
};
TEST_F(OpTest_1Dim, ExecOp)
{
Array<double,SRange> ma1(srptr, v1);
Array<double,SRange> ma2(srptr, v2);
Array<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);
EXPECT_EQ( fabs( res.at('l') - (9.436+4.790) ) < 0.0001, true );
EXPECT_EQ( fabs( res.at('f') - (0.373+8.215) ) < 0.0001, true );
EXPECT_EQ( fabs( res.at('g') - (7.192+5.063) ) < 0.0001, true );
}
TEST_F(OpTest_MDim, ExecOp1)
{
Array<double,SRange,SRange> res(sr2ptr,sr4ptr);
Array<double,SRange,SRange> res2(sr2ptr,sr4ptr);
const Array<double,SRange> ma1(sr2ptr, v1);
const Array<double,SRange> ma2(sr4ptr, v2);
auto i1 = MAT::getIndex( sr2ptr );
auto i2 = MAT::getIndex( sr4ptr );
res(i1,i2) = ma1(i1) * ma2(i2);
EXPECT_EQ( xround( res.at(mkt('1','A')) ), xround(2.917 * 8.870) );
EXPECT_EQ( xround( res.at(mkt('1','B')) ), xround(2.917 * 4.790) );
EXPECT_EQ( xround( res.at(mkt('2','A')) ), xround(9.436 * 8.870) );
EXPECT_EQ( xround( res.at(mkt('2','B')) ), xround(9.436 * 4.790) );
EXPECT_EQ( xround( res.at(mkt('3','A')) ), xround(0.373 * 8.870) );
EXPECT_EQ( xround( res.at(mkt('3','B')) ), xround(0.373 * 4.790) );
res2(i1,i2) = (ma1(i1) + 3.14 ) * ma2(i2);
EXPECT_EQ( xround( res2.at(mkt('1','A')) ), xround( (2.917 + 3.14) * 8.870) );
EXPECT_EQ( xround( res2.at(mkt('1','B')) ), xround( (2.917 + 3.14) * 4.790) );
EXPECT_EQ( xround( res2.at(mkt('2','A')) ), xround( (9.436 + 3.14) * 8.870) );
EXPECT_EQ( xround( res2.at(mkt('2','B')) ), xround( (9.436 + 3.14) * 4.790) );
EXPECT_EQ( xround( res2.at(mkt('3','A')) ), xround( (0.373 + 3.14) * 8.870) );
EXPECT_EQ( xround( res2.at(mkt('3','B')) ), xround( (0.373 + 3.14) * 4.790) );
}
TEST_F(OpTest_MDim, ExecContract)
{
Array<double,SRange> res(sr2ptr);
const Array<double,SRange> ma1(sr2ptr, v1);
const Array<double,SRange> ma2(sr4ptr, v2);
auto i1 = MAT::getIndex( sr2ptr );
auto i2 = MAT::getIndex( sr4ptr );
res(i1) += (ma1(i1) * ma2(i2)).c(i2);
EXPECT_EQ( xround( res.at('1') ), xround(2.917 * 8.870 + 2.917 * 4.790) );
EXPECT_EQ( xround( res.at('2') ), xround(9.436 * 8.870 + 9.436 * 4.790) );
EXPECT_EQ( xround( res.at('3') ), xround(0.373 * 8.870 + 0.373 * 4.790) );
}
TEST_F(OpTest_MDim, ExecOp2)
{
Array<double,MRange,SRange> res(mr1ptr,sr4ptr);
Array<double,MRange> ma1(mr1ptr, v3);
Array<double,SRange> ma2(sr4ptr, v2);
Array<double,SRange> ma3(sr4ptr, v4);
auto i1 = MAT::getIndex( mr1ptr );
auto i2 = MAT::getIndex( sr4ptr );
res(i1,i2) = ( ma1(i1) + ma2(i2) ).p(i1,i2) - ma3(i2);
EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'A')) ), xround(0.353 + 8.870 - 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'B')) ), xround(0.353 + 4.790 - 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','b'),'A')) ), xround(4.005 + 8.870 - 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','b'),'B')) ), xround(4.005 + 4.790 - 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','a'),'A')) ), xround(1.070 + 8.870 - 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','a'),'B')) ), xround(1.070 + 4.790 - 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','b'),'A')) ), xround(2.310 + 8.870 - 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','b'),'B')) ), xround(2.310 + 4.790 - 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','a'),'A')) ), xround(9.243 + 8.870 - 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','a'),'B')) ), xround(9.243 + 4.790 - 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','b'),'A')) ), xround(2.911 + 8.870 - 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','b'),'B')) ), xround(2.911 + 4.790 - 2.210) );
}
TEST_F(OpTest_MDim, ExecOpAnon)
{
Array<double,MRange> ma1(mr1ptr, v3);
Array<double,AnonymousRange> maa
= *std::dynamic_pointer_cast<Array<double,AnonymousRange>>( ma1.anonymous() );
Array<double,AnonymousRange> maa2( maa.template getRangePtr<0>() );
auto ar = maa.template getRangePtr<0>();
auto i1 = MAT::getIndex( ar );
maa2(i1) = maa(i1) * maa(i1);
EXPECT_EQ( xround( maa2.at(0) ), xround( v3[0]*v3[0] ) );
for((*i1) = 0; i1->pos() != i1->max(); ++(*i1) ){
EXPECT_EQ( xround( maa2.at(i1->meta()) ), xround( maa.at(i1->meta()) * maa.at(i1->meta()) ) );
}
}
TEST_F(OpTest_MDim, ExecFOp)
{
Array<double,MRange,SRange> res(mr1ptr,sr4ptr);
Array<double,MRange> ma1(mr1ptr, v3);
Array<double,SRange> ma2(sr4ptr, v2);
Array<double,SRange> ma3(sr4ptr, v4);
auto i1 = MAT::getIndex( mr1ptr );
auto i2 = MAT::getIndex( sr4ptr );
res(i1,i2) = Monopole<double>::mk( ma1(i1) , ma2(i2) , ma3(i2) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'A')) ), xround(0.353 / ( 1 + 8.870 / 1.470) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'B')) ), xround(0.353 / ( 1 + 4.790 / 2.210) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','b'),'A')) ), xround(4.005 / ( 1 + 8.870 / 1.470) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','b'),'B')) ), xround(4.005 / ( 1 + 4.790 / 2.210) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','a'),'A')) ), xround(1.070 / ( 1 + 8.870 / 1.470) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','a'),'B')) ), xround(1.070 / ( 1 + 4.790 / 2.210) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','b'),'A')) ), xround(2.310 / ( 1 + 8.870 / 1.470) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','b'),'B')) ), xround(2.310 / ( 1 + 4.790 / 2.210) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','a'),'A')) ), xround(9.243 / ( 1 + 8.870 / 1.470) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','a'),'B')) ), xround(9.243 / ( 1 + 4.790 / 2.210) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','b'),'A')) ), xround(2.911 / ( 1 + 8.870 / 1.470) ) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','b'),'B')) ), xround(2.911 / ( 1 + 4.790 / 2.210) ) );
}
TEST_F(OpTest_MDim, ExecDOp)
{
//typedef Array<double,AnonymousRange> AMA;
typedef Array<double,DynamicRange> DMA;
Array<double,MRange,SRange> ma1(mr1ptr,sr4ptr,v5);
Array<double,SRange> ma2(sr2ptr,v1);
Array<double,SRange,MRange> res(sr4ptr,mr1ptr);
Array<double,MRange,SRange> res2(mr1ptr,sr4ptr);
DMA dma1 = *std::dynamic_pointer_cast<DMA>( dynamic( ma1 ) );
DMA dma2 = *std::dynamic_pointer_cast<DMA>( dynamic( ma2 ) );
DMA dres = *std::dynamic_pointer_cast<DMA>( dynamic( res ) );
DMA dres2 = *std::dynamic_pointer_cast<DMA>( dynamic( res2 ) );
auto si2 = MAT::getIndex( sr2ptr );
auto si3 = MAT::getIndex( sr3ptr );
auto si4 = MAT::getIndex( sr4ptr );
auto mi = MAT::getIndex( mr1ptr );
(*mi)(si2,si3);
auto di1 = MAT::getIndex( MAT::rptr<0>( dma1 ) );
auto di2 = MAT::getIndex( MAT::rptr<0>( dma2 ) );
auto dir = MAT::getIndex( MAT::rptr<0>( dres ) );
//auto dirx = MAT::getIndex( MAT::rptr<0>( dres ) );
auto dir2 = MAT::getIndex( MAT::rptr<0>( dres2 ) );
(*di1)(mi,si4);
(*di2)(si2);
(*dir)(si4,mi);
(*dir2)(mi,si4);
dres(dir) = dma1(di1) + dma2(di2);
res = dres.format(sr4ptr,mr1ptr);
EXPECT_EQ( xround( res.at( mkt('A',mkt('1','a')) ) ), xround( 30.932 + 2.917 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('1','b')) ) ), xround( -26.205 + 2.917 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('2','a')) ) ), xround( 21.227 + 9.436 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('2','b')) ) ), xround( -14.364 + 9.436 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('3','a')) ) ), xround( -25.703 + 0.373 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('3','b')) ) ), xround( 23.563 + 0.373 ) );
EXPECT_EQ( xround( res.at( mkt('B',mkt('1','a')) ) ), xround( -33.693 + 2.917 ) );
EXPECT_EQ( xround( res.at( mkt('B',mkt('1','b')) ) ), xround( -15.504 + 2.917 ) );
EXPECT_EQ( xround( res.at( mkt('B',mkt('2','a')) ) ), xround( 17.829 + 9.436 ) );
EXPECT_EQ( xround( res.at( mkt('B',mkt('2','b')) ) ), xround( -1.868 + 9.436 ) );
EXPECT_EQ( xround( res.at( mkt('B',mkt('3','a')) ) ), xround( 13.836 + 0.373 ) );
EXPECT_EQ( xround( res.at( mkt('B',mkt('3','b')) ) ), xround( 41.339 + 0.373 ) );
//dres = *std::dynamic_pointer_cast<DMA>( dynamic( res ) );
dres2(dir2) = dres(dir);
res2 = dres2.format(mr1ptr,sr4ptr);
EXPECT_EQ( xround( res2.at( mkt(mkt('1','a'),'A') ) ), xround( 30.932 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('1','b'),'A') ) ), xround( -26.205 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('2','a'),'A') ) ), xround( 21.227 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('2','b'),'A') ) ), xround( -14.364 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('3','a'),'A') ) ), xround( -25.703 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('3','b'),'A') ) ), xround( 23.563 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('1','a'),'B') ) ), xround( -33.693 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('1','b'),'B') ) ), xround( -15.504 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('2','a'),'B') ) ), xround( 17.829 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('2','b'),'B') ) ), xround( -1.868 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('3','a'),'B') ) ), xround( 13.836 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('3','b'),'B') ) ), xround( 41.339 + 0.373 ) );
}
TEST_F(OpTest_MDim, ExecOp3)
{
Array<double,MRange,SRange> res(mr1ptr,sr4ptr);
Array<double,MRange> ma1(mr1ptr, v3);
Array<double,SRange> ma2(sr2ptr, v1);
Array<double,SRange> ma3(sr4ptr, v4);
Array<double,SRange,SRange,SRange,SRange> ma4(sr1ptr,sr2ptr,sr3ptr,sr4ptr);
Array<double,SRange> ma5(sr1ptr, v3);
Array<double,SRange> ma6(sr3ptr, v2);
auto si0 = MAT::getIndex( sr1ptr ); // 'x'
auto si1 = MAT::getIndex( sr2ptr ); // '1'
auto si2 = MAT::getIndex( sr3ptr ); // 'a'
auto si3 = MAT::getIndex( sr4ptr ); // 'A'
auto mi = MAT::getIndex( mr1ptr );
mi->operator()(si1,si2);
res(mi,si3) = ma1(mi) + ma2(si1) + ma3(si3);
ma4(si0,si1,si2,si3) = ma5(si0)*ma2(si1)*ma6(si2)*ma3(si3);
EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'A')) ), xround(0.353 + 2.917 + 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'B')) ), xround(0.353 + 2.917 + 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','b'),'A')) ), xround(4.005 + 2.917 + 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('1','b'),'B')) ), xround(4.005 + 2.917 + 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','a'),'A')) ), xround(1.070 + 9.436 + 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','a'),'B')) ), xround(1.070 + 9.436 + 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','b'),'A')) ), xround(2.310 + 9.436 + 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('2','b'),'B')) ), xround(2.310 + 9.436 + 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','a'),'A')) ), xround(9.243 + 0.373 + 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','a'),'B')) ), xround(9.243 + 0.373 + 2.210) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','b'),'A')) ), xround(2.911 + 0.373 + 1.470) );
EXPECT_EQ( xround( res.at(mkt(mkt('3','b'),'B')) ), xround(2.911 + 0.373 + 2.210) );
si1->at('1');
si0->at('x');
(*si2) = 0;
(*si3) = 0;
Slice<double,SRange,SRange> sl(sr4ptr,sr3ptr);
sl.define(si3,si2) = ma4(si0,si1,si2,si3);
ArrayBase<double,SRange,SRange>& slb = sl;
Array<double,SRange,SRange> ma8(sr3ptr,sr4ptr);
//ma8(si2,si3) = ma4(si0,si1,si2,si3);
ma8(si2,si3) = slb(si3,si2);
EXPECT_EQ( xround( ma8.at(mkt('a','A')) ), xround( sl.at(mkt('A','a')) ) );
EXPECT_EQ( xround( ma8.at(mkt('b','A')) ), xround( sl.at(mkt('A','b')) ) );
}
} // anonymous namspace
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View file

@ -1,255 +0,0 @@
// -*- C++ -*-
#include <cstdlib>
#include "gtest/gtest.h"
#include <iostream>
#include "ranges/rheader.h"
#include "cnorxz.h"
//#include "ranges/ranges_header.cc.h"
namespace MAT = CNORXZ;
namespace {
using namespace MAT;
//typedef Expressions1 EC1;
template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{
vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr;
}
template <class Factory, class... Rs>
void swapMFactory(std::shared_ptr<RangeFactoryBase>& fptr, const Rs&... rs)
{
auto nptr = std::make_shared<Factory>( rs... );
fptr = nptr;
}
template <typename... Ts>
auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...))
{
return std::make_tuple(ts...);
}
class AnonymousTest : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange,SRange> M3RF;
typedef M3RF::oType M3Range;
typedef MultiRangeFactory<SRange,M3Range,SRange> MasterRF;
typedef MasterRF::oType MasterRange;
typedef ContainerRangeFactory<M3Range,SRange> CRF;
typedef CRF::oType CRange;
typedef ConstContainerIndex<double,M3Range::IndexType,SRange::IndexType> CIndex;
AnonymousTest()
{
swapFactory<SRF>(rfbptr, { 'e', 'b', 'n' } );
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, { 'x', 'y', 'l', 'f' } );
sr2ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, { 'a', 'b' } );
std::shared_ptr<SRange> temp1 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, { '1' } );
std::shared_ptr<SRange> temp2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, { '0', '7' } );
std::shared_ptr<SRange> temp3 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapMFactory<M3RF>(rfbptr, temp1, temp2, temp3 );
m3rptr = std::dynamic_pointer_cast<M3Range>( rfbptr->create() );
swapMFactory<MasterRF>(rfbptr, sr1ptr, m3rptr, sr2ptr);
mstrptr = std::dynamic_pointer_cast<MasterRange>( rfbptr->create() );
swapMFactory<CRF>(rfbptr, m3rptr, sr2ptr);
cr1ptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
swapMFactory<CRF>(rfbptr, m3rptr, sr1ptr);
cr2ptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> sr1ptr;
std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<M3Range> m3rptr;
std::shared_ptr<MasterRange> mstrptr;
std::shared_ptr<CRange> cr1ptr;
std::shared_ptr<CRange> cr2ptr;
};
TEST_F(AnonymousTest, Cast1)
{
AnonymousRangeFactory arf1(sr1ptr,m3rptr);
auto ar1a = std::dynamic_pointer_cast<AnonymousRange>( arf1.create() );
arf1.append(sr2ptr);
auto ar1b = std::dynamic_pointer_cast<AnonymousRange>( arf1.create() );
AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
auto ar2 = std::dynamic_pointer_cast<AnonymousRange>( arf2.create() );
EXPECT_EQ(ar1b.get(), ar2.get());
EXPECT_EQ(ar1a->size(), sr1ptr->size() * m3rptr->size());
EXPECT_EQ(ar2->size(), sr1ptr->size() * m3rptr->size() * sr2ptr->size());
EXPECT_EQ(ar1a->sub(0)->size(), sr1ptr->size());
EXPECT_EQ(ar1a->sub(1)->size(), m3rptr->size());
EXPECT_EQ(ar2->sub(0)->size(), sr1ptr->size());
EXPECT_EQ(ar2->sub(1)->size(), m3rptr->size());
EXPECT_EQ(ar2->sub(2)->size(), sr2ptr->size());
}
TEST_F(AnonymousTest, Cast2)
{
AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
auto ar = std::dynamic_pointer_cast<AnonymousRange>( arf2.create() );
auto mr = ar->template scast<SRange,AnonymousRange>(1,2);
EXPECT_EQ(mr->template getPtr<0>()->size(), sr1ptr->size());
EXPECT_EQ(mr->template getPtr<1>()->size(), m3rptr->size() * sr2ptr->size());
}
TEST_F(AnonymousTest, DCast1)
{
DynamicRangeFactory arf1(sr1ptr,m3rptr);
auto ar1a = std::dynamic_pointer_cast<DynamicRange>( arf1.create() );
arf1.append(sr2ptr);
auto ar1b = std::dynamic_pointer_cast<DynamicRange>( arf1.create() );
DynamicRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
auto ar2 = std::dynamic_pointer_cast<DynamicRange>( arf2.create() );
EXPECT_EQ(ar1b.get(), ar2.get());
EXPECT_EQ(ar1a->size(), sr1ptr->size() * m3rptr->size());
EXPECT_EQ(ar2->size(), sr1ptr->size() * m3rptr->size() * sr2ptr->size());
EXPECT_EQ(ar1a->sub(0)->size(), sr1ptr->size());
EXPECT_EQ(ar1a->sub(1)->size(), m3rptr->size());
EXPECT_EQ(ar2->sub(0)->size(), sr1ptr->size());
EXPECT_EQ(ar2->sub(1)->size(), m3rptr->size());
EXPECT_EQ(ar2->sub(2)->size(), sr2ptr->size());
}
TEST_F(AnonymousTest, DCast2)
{
DynamicRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
auto ar = std::dynamic_pointer_cast<DynamicRange>( arf2.create() );
auto mr = ar->template scast<SRange,DynamicRange>(1,2);
EXPECT_EQ(mr->template getPtr<0>()->size(), sr1ptr->size());
EXPECT_EQ(mr->template getPtr<1>()->size(), m3rptr->size() * sr2ptr->size());
}
TEST_F(AnonymousTest, ToString1)
{
vector<char> vv = sr1ptr->data();
const char* dp = vv.data();
auto ff = createRangeFactory(&dp);
auto ss = std::dynamic_pointer_cast<SRange>( ff->create() );
EXPECT_EQ(sr1ptr->size(), ss->size());
EXPECT_EQ(sr1ptr->get(0), ss->get(0));
EXPECT_EQ(sr1ptr->get(1), ss->get(1));
EXPECT_EQ(sr1ptr->get(2), ss->get(2));
}
TEST_F(AnonymousTest, ToString2)
{
typedef SingleRangeFactory<std::string,SpaceType::ANY> NameRF;
typedef SingleRange<std::string,SpaceType::ANY> NameRange;
ClassicRF crf(5);
SpinRF srf;
NameRF nrf({"ab", "cdef", "gh", "ijklmno"});
auto cr = std::dynamic_pointer_cast<ClassicRange>( crf.create() );
auto sr = std::dynamic_pointer_cast<SpinRange>( srf.create() );
auto nr = std::dynamic_pointer_cast<NameRange>( nrf.create() );
vector<char> cv = cr->data();
vector<char> sv = sr->data();
vector<char> nv = nr->data();
const char* cp = cv.data();
const char* sp = sv.data();
const char* np = nv.data();
auto crf2 = createRangeFactory(&cp);
auto cr2 = std::dynamic_pointer_cast<ClassicRange>( crf2->create() );
auto srf2 = createRangeFactory(&sp);
auto sr2 = std::dynamic_pointer_cast<SpinRange>( srf2->create() );
auto nrf2 = createRangeFactory(&np);
auto nr2 = std::dynamic_pointer_cast<NameRange>( nrf2->create() );
EXPECT_EQ(cr2->size(), cr->size());
EXPECT_EQ(sr2->size(), sr->size());
EXPECT_EQ(nr2->size(), nr->size());
EXPECT_EQ(nr2->get(0), nr->get(0));
EXPECT_EQ(nr2->get(1), nr->get(1));
EXPECT_EQ(nr2->get(2), nr->get(2));
EXPECT_EQ(nr2->get(3), nr->get(3));
}
TEST_F(AnonymousTest, ToStringMulti)
{
vector<char> vv = m3rptr->data();
const char* dp = vv.data();
auto ff2 = std::dynamic_pointer_cast<M3RF>( createRangeFactory(&dp) );
auto mr2 = std::dynamic_pointer_cast<M3Range>( ff2->create() );
EXPECT_EQ(mr2->size(), m3rptr->size());
EXPECT_EQ(mr2->template getPtr<0>()->size(),
m3rptr->template getPtr<0>()->size());
EXPECT_EQ(mr2->template getPtr<1>()->size(),
m3rptr->template getPtr<1>()->size());
EXPECT_EQ(mr2->template getPtr<2>()->size(),
m3rptr->template getPtr<2>()->size());
auto jj = m3rptr->begin();
for(auto ii = mr2->begin(); ii.pos() != ii.max(); ++ii, jj = ii.pos()){
EXPECT_EQ(ii.meta(), jj.meta());
}
}
TEST_F(AnonymousTest, ToStringAnonymous)
{
AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
auto ar = std::dynamic_pointer_cast<AnonymousRange>( arf2.create() );
vector<char> vv = ar->data();
const char* dp = vv.data();
auto ff2 = std::dynamic_pointer_cast<AnonymousRangeFactory>( createRangeFactory(&dp) );
auto ar2 = std::dynamic_pointer_cast<AnonymousRange>( ff2->create() );
EXPECT_EQ(ar2->size(), ar->size());
EXPECT_EQ(ar2->anonymousDim(), ar->anonymousDim());
}
} // end namespace
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View file

@ -1,326 +0,0 @@
// -*- C++ -*-
#include <cstdlib>
#include "gtest/gtest.h"
#include <iostream>
#include "cnorxz.h"
namespace MAT = CNORXZ;
namespace {
using namespace MAT;
template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{
vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr;
}
template <class Factory, class... Rs>
void swapMFactory(std::shared_ptr<RangeFactoryBase>& fptr, const Rs&... rs)
{
auto nptr = std::make_shared<Factory>( rs... );
fptr = nptr;
}
template <typename... Ts>
auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...))
{
return std::make_tuple(ts...);
}
class DynIndexTest : public ::testing::Test
{
protected:
typedef DynamicRangeFactory DRF;
typedef DRF::oType DR;
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange,SRange> M3RF;
typedef M3RF::oType M3Range;
DynIndexTest()
{
SRF srf({'e', 'b', 'n'});
sr = std::dynamic_pointer_cast<SRange>( srf.create() );
SRF srf1({'a', 'b'});
SRF srf2({'1'});
SRF srf3({'0', '7'});
auto sr1 = std::dynamic_pointer_cast<SRange>( srf1.create() );
auto sr2 = std::dynamic_pointer_cast<SRange>( srf2.create() );
auto sr3 = std::dynamic_pointer_cast<SRange>( srf3.create() );
M3RF mrf(sr1,sr2,sr3);
mr = std::dynamic_pointer_cast<M3Range>( mrf.create() );
vector<std::shared_ptr<RangeBase>> rv(2);
rv[0] = sr;
rv[1] = mr;
DRF drf(rv);
dr = std::dynamic_pointer_cast<DR>( drf.create() );
}
std::shared_ptr<DR> dr;
std::shared_ptr<SRange> sr;
std::shared_ptr<M3Range> mr;
};
class IndexTest : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange,SRange> M3RF;
typedef M3RF::oType M3Range;
typedef MultiRangeFactory<SRange,M3Range,SRange> MasterRF;
typedef MasterRF::oType MasterRange;
typedef ContainerRangeFactory<M3Range,SRange> CRF;
typedef CRF::oType CRange;
typedef ConstContainerIndex<double,M3Range::IndexType,SRange::IndexType> CIndex;
IndexTest()
{
swapFactory<SRF>(rfbptr, { 'e', 'b', 'n' } );
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, { 'x', 'y', 'l', 'f' } );
sr2ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, { 'a', 'b' } );
std::shared_ptr<SRange> temp1 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, { '1' } );
std::shared_ptr<SRange> temp2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, { '0', '7' } );
std::shared_ptr<SRange> temp3 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapMFactory<M3RF>(rfbptr, temp1, temp2, temp3 );
m3rptr = std::dynamic_pointer_cast<M3Range>( rfbptr->create() );
swapMFactory<MasterRF>(rfbptr, sr1ptr, m3rptr, sr2ptr);
mstrptr = std::dynamic_pointer_cast<MasterRange>( rfbptr->create() );
swapMFactory<CRF>(rfbptr, m3rptr, sr2ptr);
cr1ptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
swapMFactory<CRF>(rfbptr, m3rptr, sr1ptr);
cr2ptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> sr1ptr;
std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<M3Range> m3rptr;
std::shared_ptr<MasterRange> mstrptr;
std::shared_ptr<CRange> cr1ptr;
std::shared_ptr<CRange> cr2ptr;
};
TEST_F(IndexTest, SingleIndex_SimpleCall)
{
auto si = sr1ptr->begin();
EXPECT_EQ(si.max(), 3u);
EXPECT_EQ(si.pos(), 0u);
EXPECT_EQ(si.first(), true);
EXPECT_EQ(si.last(), false);
EXPECT_EQ(si.meta(), 'e');
si.at('n');
EXPECT_EQ(si.pos(), si.max()-1);
EXPECT_EQ(si.first(), false);
EXPECT_EQ(si.last(), true);
si = 1;
EXPECT_EQ(si.meta(), 'b');
++si;
EXPECT_EQ(si.meta(), 'n');
auto si2 = sr1ptr->end();
--si2;
EXPECT_EQ(si == si2, true);
EXPECT_EQ(si != si2, false);
auto si3 = sr2ptr->end();
--si3;
EXPECT_EQ(si == si3, false);
EXPECT_EQ(si != si3, true);
}
TEST_F(IndexTest, MultiIndex_SimpleCall)
{
auto mi = m3rptr->begin();
EXPECT_EQ(mi.max(), 4u);
EXPECT_EQ(mi.pos(), 0u);
EXPECT_EQ(mi.first(), true);
EXPECT_EQ(mi.last(), false);
EXPECT_EQ(mi.meta() == mkt('a','1','0'), true);
mi.at( mkt('b','1','7') );
EXPECT_EQ(mi.pos(), mi.max()-1);
EXPECT_EQ(mi.first(), false);
EXPECT_EQ(mi.last(), true);
mi = 1;
EXPECT_EQ(mi.meta() == mkt('a','1','7'), true);
++mi;
EXPECT_EQ(mi.meta() == mkt('b','1','0'), true);
++mi;
auto mi2 = m3rptr->end();
--mi2;
EXPECT_EQ(mi == mi2, true);
EXPECT_EQ(mi != mi2, false);
--mi2;
EXPECT_EQ(mi == mi2, false);
EXPECT_EQ(mi != mi2, true);
auto si = sr1ptr->begin();
EXPECT_EQ(si == mi, false);
EXPECT_EQ(si != mi, true);
}
TEST_F(IndexTest, MasterRange_Check)
{
EXPECT_EQ(mstrptr->size(), 48u);
EXPECT_EQ(mstrptr->template get<0>().size(), 3u);
EXPECT_EQ(mstrptr->template get<1>().size(), 4u);
EXPECT_EQ(mstrptr->template get<2>().size(), 4u);
EXPECT_EQ(mstrptr->dim(), 3u);
EXPECT_EQ(mstrptr->template get<0>().dim(), 1u);
EXPECT_EQ(mstrptr->template get<1>().dim(), 3u);
auto mi = mstrptr->begin();
EXPECT_EQ(mi.meta() == mkt( 'e' , mkt('a', '1', '0') , 'x' ), true);
mi = mi.max()-1;
EXPECT_EQ(mi.meta() == mkt( 'n' , mkt('b', '1', '7') , 'f' ), true);
mi.template down<1>();
EXPECT_EQ(mi.meta() == mkt( 'n' , mkt('b', '1', '0') , 'f' ), true);
mi.template down<0>();
EXPECT_EQ(mi.meta() == mkt( 'b' , mkt('b', '1', '0') , 'f' ), true);
mi.template down<2>();
EXPECT_EQ(mi.meta() == mkt( 'b' , mkt('b', '1', '0') , 'l' ), true);
mi.template up<1>();
EXPECT_EQ(mi.meta() == mkt( 'b' , mkt('b', '1', '7') , 'l' ), true);
auto& subI = mi.template get<0>();
EXPECT_EQ(subI.meta(), 'b');
mi.template up<0>();
EXPECT_EQ(subI.meta(), 'n');
auto& subI2 = mi.template get<1>();
EXPECT_EQ(subI2.meta() == mkt('b', '1', '7'), true);
mi.template down<1>();
EXPECT_EQ(subI2.meta() == mkt('b', '1', '0'), true);
}
TEST_F(IndexTest, ContainerRange_Check)
{
EXPECT_EQ(cr1ptr->size(), 16u);
EXPECT_EQ(cr2ptr->size(), 12u);
auto mi = mstrptr->begin();
//auto ci1 = cr1ptr->begin();
CIndex ci1(cr1ptr, 0);
ci1 = 0;
//auto ci2 = cr2ptr->begin();
CIndex ci2(cr2ptr, 0);
ci2 = 0;
EXPECT_EQ(ci1.max(), 16u);
EXPECT_EQ(ci2.max(), 12u);
ci1(mi.template getPtr<1>(), mi.template getPtr<2>());
ci2(mi.template getPtr<1>(), mi.template getPtr<0>());
EXPECT_EQ(ci1.pos(), 0u);
EXPECT_EQ(ci2.pos(), 0u);
++mi;
EXPECT_EQ(ci1().pos(), 1u);
EXPECT_EQ(ci2().pos(), 0u);
mi.template up<1>();
EXPECT_EQ(ci1().pos(), 5u);
EXPECT_EQ(ci2().pos(), 3u);
mi.template up<0>();
EXPECT_EQ(ci1().pos(), 5u);
EXPECT_EQ(ci2().pos(), 4u);
mi = mi.max()-1;
EXPECT_EQ(ci1().pos(), ci1.max()-1);
EXPECT_EQ(ci2().pos(), ci2.max()-1);
}
const char& resolve0(const vector<char>& cv)
{
return cv[0];
}
const std::tuple<char,char,char>& resolve1(const vector<char>& cv)
{
return *reinterpret_cast<const std::tuple<char,char,char>*>(cv.data()+1);
}
TEST_F(DynIndexTest, Iterate)
{
for(auto i = dr->begin(); i.pos() != i.max(); ++i){
EXPECT_EQ(i.meta().size(), 4*sizeof(char));
}
auto j = dr->begin();
//std::cout << j.stringMeta() << std::endl;
EXPECT_EQ(j.stringMeta(), "[e, [a,1,0]]");
EXPECT_EQ(resolve0(j.meta()), 'e');
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','0'));
EXPECT_EQ((++j).stringMeta(), "[e, [a,1,7]]");
EXPECT_EQ(resolve0(j.meta()), 'e');
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','7'));
EXPECT_EQ((++j).stringMeta(), "[e, [b,1,0]]");
EXPECT_EQ(resolve0(j.meta()), 'e');
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','0'));
EXPECT_EQ((++j).stringMeta(), "[e, [b,1,7]]");
EXPECT_EQ(resolve0(j.meta()), 'e');
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','7'));
EXPECT_EQ((++j).stringMeta(), "[b, [a,1,0]]");
EXPECT_EQ(resolve0(j.meta()), 'b');
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','0'));
EXPECT_EQ((++j).stringMeta(), "[b, [a,1,7]]");
EXPECT_EQ(resolve0(j.meta()), 'b');
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','7'));
EXPECT_EQ((++j).stringMeta(), "[b, [b,1,0]]");
EXPECT_EQ(resolve0(j.meta()), 'b');
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','0'));
EXPECT_EQ((++j).stringMeta(), "[b, [b,1,7]]");
EXPECT_EQ(resolve0(j.meta()), 'b');
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','7'));
EXPECT_EQ((++j).stringMeta(), "[n, [a,1,0]]");
EXPECT_EQ(resolve0(j.meta()), 'n');
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','0'));
EXPECT_EQ((++j).stringMeta(), "[n, [a,1,7]]");
EXPECT_EQ(resolve0(j.meta()), 'n');
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','7'));
EXPECT_EQ((++j).stringMeta(), "[n, [b,1,0]]");
EXPECT_EQ(resolve0(j.meta()), 'n');
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','0'));
EXPECT_EQ((++j).stringMeta(), "[n, [b,1,7]]");
EXPECT_EQ(resolve0(j.meta()), 'n');
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','7'));
}
} // end namespace
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}