Cytnx v0.9.4
Loading...
Searching...
No Matches
random.hpp
Go to the documentation of this file.
1#ifndef _random_H_
2#define _random_H_
3#include "Type.hpp"
4#include "Device.hpp"
5#include "cytnx_error.hpp"
6#include <vector>
7#include <initializer_list>
8#include <random>
9#include "Tensor.hpp"
10#include "UniTensor.hpp"
11
12#ifdef BACKEND_TORCH
13#else
14
15 #include "backend/Storage.hpp"
16
17namespace cytnx {
22 namespace random {
23
24 // [Storage]
25 // =============================================================================================================
26 // =============================================================================================================
27 // normal_:
28 //--------------------------------------------------
37 void normal_(Storage &Sin, const double &mean, const double &std,
38 const unsigned int &seed = std::random_device()());
39
40 // uniform_:
41 //--------------------------------------------------
53 void uniform_(Storage &Sin, const double &low = 0, const double &high = 1,
54 const unsigned int &seed = std::random_device()());
55
56 // [Tensor]
57 // =============================================================================================================
58 // =============================================================================================================
59 // normal_:
60 //-------------------------------------------------
69 void normal_(Tensor &Tin, const double &mean, const double &std,
70 const unsigned int &seed = std::random_device()());
71
72 // uniform_:
73 //--------------------------------------------------
86 void uniform_(Tensor &Tin, const double &low = 0, const double &high = 1,
87 const unsigned int &seed = std::random_device()());
88
89 // [UniTensor]
90 // =============================================================================================================
91 // =============================================================================================================
92 // normal_:
93 //-------------------------------------------------
102 void normal_(UniTensor &Tin, const double &mean, const double &std,
103 const unsigned int &seed = std::random_device()());
104
105 // uniform_:
106 //--------------------------------------------------
118 void uniform_(UniTensor &Tin, const double &low = 0, const double &high = 1,
119 const unsigned int &seed = std::random_device()());
120
121 // normal:
123
136 Tensor normal(const cytnx_uint64 &Nelem, const double &mean, const double &std,
137 const int &device = Device.cpu, const unsigned int &seed = std::random_device()(),
138 const unsigned int &dtype = Type.Double);
139
152 Tensor normal(const std::vector<cytnx_uint64> &Nelem, const double &mean, const double &std,
153 const int &device = Device.cpu, const unsigned int &seed = std::random_device()(),
154 const unsigned int &dtype = Type.Double);
156
157 // uniform:
159
171 Tensor uniform(const cytnx_uint64 &Nelem, const double &low, const double &high,
172 const int &device = Device.cpu,
173 const unsigned int &seed = std::random_device()(),
174 const unsigned int &dtype = Type.Double);
175
189 Tensor uniform(const std::vector<cytnx_uint64> &Nelem, const double &low, const double &high,
190 const int &device = Device.cpu,
191 const unsigned int &seed = std::random_device()(),
192 const unsigned int &dtype = Type.Double);
194
196 // this is going to deprecated:
197 template <class T>
198 void Make_normal(T &In, const double &mean, const double &std,
199 const unsigned int &seed = std::random_device()()) {
200 normal_(In, mean, std, seed);
201 }
202 template <class T>
203 void Make_uniform(T &In, const double &low, const double &high,
204 const unsigned int &seed = std::random_device()()) {
205 uniform_(In, low, high, seed);
206 }
207
209
210 } // namespace random
211} // namespace cytnx
212
213#endif // BACKEND_TORCH
214
215#endif
an tensor (multi-dimensional array)
Definition Tensor.hpp:41
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1706
Tensor normal(const cytnx_uint64 &Nelem, const double &mean, const double &std, const int &device=Device.cpu, const unsigned int &seed=std::random_device()(), const unsigned int &dtype=Type.Double)
create an Tensor with all the elements are initialized with normal distribution
Tensor uniform(const cytnx_uint64 &Nelem, const double &low, const double &high, const int &device=Device.cpu, const unsigned int &seed=std::random_device()(), const unsigned int &dtype=Type.Double)
create an Tensor with all the elements are initialized with uniform distribution
void uniform_(Storage &Sin, const double &low=0, const double &high=1, const unsigned int &seed=std::random_device()())
Randomize the memory of a Storage with uniform distributon.
void normal_(Storage &Sin, const double &mean, const double &std, const unsigned int &seed=std::random_device()())
Randomize the memory of a Storage with normal distributon.
Helper function to print vector with ODT:
Definition Accessor.hpp:12
Device_class Device
data on which devices.
uint64_t cytnx_uint64
Definition Type.hpp:55
Type_class Type
data type