sisi4s
Loading...
Searching...
No Matches
RandomTensor.hpp
Go to the documentation of this file.
1#ifndef RANDOM_TENSOR_DEFINED
2#define RANDOM_TENSOR_DEFINED
3
4#include <math/Complex.hpp>
5#include <Sisi4s.hpp>
6#include <util/Tensor.hpp>
7#include <complex>
8#include <random>
9
10namespace sisi4s {
11template <typename Distribution, typename RandomEngine>
12inline void setRandom(double &value,
13 Distribution &distribution,
14 RandomEngine &randomEngine) {
15 // #ifdef INTEL_COMPILER
16 // value = distribution(randomEngine);
17 // value = -1.0 + 2.0*rand() / RAND_MAX; // distribution(randomEngine);
18 // #else
19 value = distribution(randomEngine);
20 // #endif
21}
22
23template <typename Distribution, typename RandomEngine>
24inline void setRandom(complex &value,
25 Distribution &distribution,
26 RandomEngine &randomEngine) {
27 // #ifdef INTEL_COMPILER
28 // value.real() = -1.0 + 2.0*rand() / RAND_MAX; //
29 // distribution(randomEngine); value.imag() = -1.0 + 2.0*rand() /
30 // RAND_MAX;
31 // // distribution(randomEngine);
32 // #else
33 value.real(distribution(randomEngine));
34 value.imag(distribution(randomEngine));
35 // #endif
36}
37
38class DefaultRandomEngine : public std::mt19937 {
39public:
41};
42
43/*
44 std::normal_distribution<double> normalDistribution(0.0, 1.0);
45*/
46template <typename F, typename Distribution, typename RandomEngine>
48 Distribution &distribution,
49 RandomEngine &randomEngine) {
50 int64_t indicesCount, *indices;
51 F *values;
52 t.read_local(&indicesCount, &indices, &values);
53 for (int64_t i(0); i < indicesCount; ++i) {
54 setRandom(values[i], distribution, randomEngine);
55 }
56 t.write(indicesCount, indices, values);
57 free(indices);
58 free(values);
59}
60} // namespace sisi4s
61
62#endif
Definition RandomTensor.hpp:38
DefaultRandomEngine()
Definition RandomTensor.hpp:40
static CTF::World * world
Definition Sisi4s.hpp:17
Definition Algorithm.hpp:10
CTF::Tensor< F > Tensor
Definition Tensor.hpp:9
void setRandom(double &value, Distribution &distribution, RandomEngine &randomEngine)
Definition RandomTensor.hpp:12
Complex< real > complex
Definition Complex.hpp:17
void setRandomTensor(Tensor< F > &t, Distribution &distribution, RandomEngine &randomEngine)
Definition RandomTensor.hpp:47