-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRandomize.h
More file actions
43 lines (30 loc) · 1007 Bytes
/
Randomize.h
File metadata and controls
43 lines (30 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef __TTNS_RANDOMIZE_H
#define __TTNS_RANDOMIZE_H
#include <functional> // std::bind
#include <random> // std::mt19937, std::distribution
#include <btas/QSPARSE/QSDArray.h>
namespace ttns
{
// adding noise
template<size_t N, class Q>
void Randomize (const double& scale, btas::QSDArray<N, Q>& x)
{
if(scale < 1.0e-12) return;
std::mt19937 rgen;
std::uniform_real_distribution<double> dist(-1.0, 1.0);
btas::QSDArray<N, Q> noise(x.q(), x.qshape(), x.dshape(), std::bind(dist, rgen));
btas::Axpy(scale, noise, x);
btas::Normalize(x);
}
template<size_t N, class Q>
void Randomize (const double& scale, btas::QSDArray<N, Q>& x, const btas::TVector<btas::Dshapes, N>& dshape)
{
if(scale < 1.0e-12) return;
std::mt19937 rgen;
std::uniform_real_distribution<double> dist(-1.0, 1.0);
btas::QSDArray<N, Q> noise(x.q(), x.qshape(), dshape, std::bind(dist, rgen));
btas::Axpy(scale, noise, x);
btas::Normalize(x);
}
} // namespace ttns
#endif // __TTNS_RANDOMIZE_H