IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 51351dcf authored by Antonio Augusto Alves Junior's avatar Antonio Augusto Alves Junior
Browse files

...

parent c1339ac0
Branches master
No related tags found
No related merge requests found
......@@ -3,13 +3,13 @@
PROJECT_NAME = RandomIterator
PROJECT_NUMBER =
STRIP_FROM_PATH = /home/augalves/Development/Release/RandomIterator/random_iterator
STRIP_FROM_PATH = /home/augalves/Development/random_iterator
INPUT = /home/augalves/Development/Release/RandomIterator/random_iterator/random_iterator /home/augalves/Development/Release/RandomIterator/random_iterator/examples
INPUT = /home/augalves/Development/random_iterator/random_iterator /home/augalves/Development/random_iterator/examples
USE_MDFILE_AS_MAINPAGE = /home/augalves/Development/Release/RandomIterator/random_iterator/README.md
OUTPUT_DIRECTORY = /home/augalves/Development/Release/RandomIterator/random_iterator_proj/documentation/reference
USE_MDFILE_AS_MAINPAGE = /home/augalves/Development/random_iterator/README.md
OUTPUT_DIRECTORY = /home/augalves/Development/random_iterator_proj/documentation/reference
VERBATIM_HEADERS = NO
GENERATE_LATEX = NO
RECURSIVE = YES
......
......@@ -147,7 +147,9 @@ public:
engine_(seed, stream),
seed_(seed),
stream_(stream)
{}
{
distribution_.reset();
}
/**
* Copy constructor
......@@ -159,7 +161,7 @@ public:
engine_(other.getEngine()),
seed_(other.getSeed()),
stream_(other.getStream())
{}
{ }
/**
* Returns an iterator to the first element of the stream.
......@@ -192,10 +194,11 @@ public:
* @return element at location n
*/
inline result_type operator[](advance_type n) const{
//counting_iterator first( 0);
//caller_type caller(distribution_, seed_, stream_ );
return begin()[n];//caller(n);
counting_iterator first( 0);
caller_type caller(distribution_, seed_, stream_ );
return caller(n);
}
/**
......@@ -304,7 +307,7 @@ private:
*/
template<typename DistibutionType, typename EngineType>
Stream<DistibutionType, EngineType>
make_stream( DistibutionType const& dist, EngineType eng, uint32_t stream ){
make_stream( DistibutionType const& dist, EngineType const& eng, uint32_t stream ){
return Stream<DistibutionType, EngineType>( dist, eng.getSeed(), stream);
}
......
......@@ -51,7 +51,9 @@ struct EngineCaller
distribution_(dist),
seed_(seed),
stream_(stream)
{}
{
distribution_.reset();
}
EngineCaller( EngineCaller<DistibutionType, EngineType> const& other ):
distribution_(other.distribution_),
......@@ -75,7 +77,6 @@ struct EngineCaller
EngineType eng(seed_, stream_ );
eng.discard(n);
return static_cast<distribution_type>(distribution_)(eng);
}
......
......@@ -62,15 +62,52 @@ SECTION( "[ random_iterator::squares3_128 ] Comparing function-like interface wi
for(size_t j=0; j<NCHECKS; ++j ) //loop sequence
{
auto dist_rng = stream() ;
INFO("#i" << " | stream() | stream[#] | *(it + i)");
INFO("#" << j << " | " << dist_rng << " | " << stream[2*j] << " | "<< *(it+2*j) );
INFO("#" << j << " | " << stream[j] << " | "<< *(it +j) );
CHECK( ((dist_rng == stream[2*j]) && (stream[2*j] == *(it+2*j) )));
CHECK( (stream[j] == *(it+j) ) );
}
}//SECTION( "[ random_iterator::squares3_128 ] Random test different streams produces different sequences." )
SECTION( "[ random_iterator::squares3_128 ] Comparing function-like interface with iterator access" )
{
INFO("Checking streams");
typedef random_iterator::squares3_128 engine_type;
//typedef std::uniform_real_distribution<double> distribution_type;
typedef std::normal_distribution<double> distribution_type;
engine_type RNG(default_seed);
distribution_type dist(0, 2);
auto stream = random_iterator::make_stream( dist, RNG , 0);
auto it = stream.begin();
double sum = 0;
double sum2 =0;
size_t N = NCHECKS*NCHECKS*NCHECKS;
for(size_t j=0; j< N; ++j ) //loop sequence
{
double x = *(it++);
sum += x ;
sum2 += x*x;
}
double mean = sum/N;
double variance = std::sqrt((sum2 - (sum*sum) / N) / N);
INFO("mean: " << mean);
INFO("variance: " <<variance );
CHECK( ( mean == 1.0 ) );
}//SECTION( "[ random_iterator::squares3_128 ] Random test different streams produces different sequences." )
}//TEST_CASE("Streams correctness")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment