lundi 2 février 2015

C++ random values and Blitz++

The code below is compiling and running. The code should init a Blitz-matrix to random values but it fails as every element of the matrix got the same value.



#include <iostream>
#include <array>
#include <algorithm>
#include <functional>
#include <random>
#include <blitz/array.h>

int main()
{
// random
std::random_device __device;
std::array<int, std::mt19937::state_size> __seeds;
std::normal_distribution<double> __distribution(0.0, 1.0);
std::mt19937 __engine;
std::generate_n(__seeds.data(), __seeds.size(), std::ref(__device));
std::seed_seq __sequence(std::begin(__seeds), std::end(__seeds));
__engine.seed(__sequence);

// matrix
blitz::Array<float,2> a(4,5);
a=__distribution(__engine);

// io
std::cout << a << std::endl;
}


The output is not what I wanted



(0,3) x (0,4)
[ -1.10231 -1.10231 -1.10231 -1.10231 -1.10231
-1.10231 -1.10231 -1.10231 -1.10231 -1.10231
-1.10231 -1.10231 -1.10231 -1.10231 -1.10231
-1.10231 -1.10231 -1.10231 -1.10231 -1.10231 ]


What's the proper way to init a Blitz-Matrix to random values?





Aucun commentaire:

Enregistrer un commentaire