Cytnx v1.0.0
Loading...
Searching...
No Matches
random.hpp
Go to the documentation of this file.
1#ifndef CYTNX_RANDOM_H_
2#define CYTNX_RANDOM_H_
3
4#include "Type.hpp"
5#include "Device.hpp"
6#include "cytnx_error.hpp"
7#include <vector>
8#include <initializer_list>
9#include <random>
10#include "Tensor.hpp"
11#include "UniTensor.hpp"
12
13#ifdef BACKEND_TORCH
14#else
15
16 #include "backend/Storage.hpp"
17
18namespace cytnx {
23 namespace random {
24 // Actual definition is in uniform_.cpp
25 extern std::random_device __static_random_device;
26
27 // [Storage]
28 // =============================================================================================================
29 // =============================================================================================================
30 // normal_:
31 //--------------------------------------------------
40 void normal_(cytnx::Storage &Sin, const double &mean, const double &std,
41 const unsigned int &seed = __static_random_device());
42
43 // uniform_:
44 //--------------------------------------------------
56 void uniform_(cytnx::Storage &Sin, const double &low = 0, const double &high = 1,
57 const unsigned int &seed = __static_random_device());
58
59 // [Tensor]
60 // =============================================================================================================
61 // =============================================================================================================
62 // normal_:
63 //-------------------------------------------------
72 void normal_(cytnx::Tensor &Tin, const double &mean, const double &std,
73 const unsigned int &seed = __static_random_device());
74
75 // uniform_:
76 //--------------------------------------------------
89 void uniform_(cytnx::Tensor &Tin, const double &low = 0, const double &high = 1,
90 const unsigned int &seed = __static_random_device());
91
92 // [UniTensor]
93 // =============================================================================================================
94 // =============================================================================================================
95 // normal_:
96 //-------------------------------------------------
105 void normal_(cytnx::UniTensor &Tin, const double &mean, const double &std,
106 const unsigned int &seed = __static_random_device());
107
108 // uniform_:
109 //--------------------------------------------------
121 void uniform_(cytnx::UniTensor &Tin, const double &low = 0, const double &high = 1,
122 const unsigned int &seed = __static_random_device());
123
124 // normal:
126
139 Tensor normal(const cytnx_uint64 &Nelem, const double &mean, const double &std,
140 const int &device = Device.cpu,
141 const unsigned int &seed = __static_random_device(),
142 const unsigned int &dtype = Type.Double);
143
156 Tensor normal(const std::vector<cytnx_uint64> &Nelem, const double &mean, const double &std,
157 const int &device = Device.cpu,
158 const unsigned int &seed = __static_random_device(),
159 const unsigned int &dtype = Type.Double);
161
162 // uniform:
164
176 Tensor uniform(const cytnx_uint64 &Nelem, const double &low, const double &high,
177 const int &device = Device.cpu,
178 const unsigned int &seed = __static_random_device(),
179 const unsigned int &dtype = Type.Double);
180
194 Tensor uniform(const std::vector<cytnx_uint64> &Nelem, const double &low, const double &high,
195 const int &device = Device.cpu,
196 const unsigned int &seed = __static_random_device(),
197 const unsigned int &dtype = Type.Double);
199
201 // this is going to deprecated:
202 template <class T>
203 void Make_normal(T &In, const double &mean, const double &std,
204 const unsigned int &seed = __static_random_device()) {
205 normal_(In, mean, std, seed);
206 }
207 template <class T>
208 void Make_uniform(T &In, const double &low, const double &high,
209 const unsigned int &seed = __static_random_device()) {
210 uniform_(In, low, high, seed);
211 }
212
214
215 } // namespace random
216} // namespace cytnx
217
218#endif // BACKEND_TORCH
219
220#endif // CYTNX_RANDOM_H_
constexpr Type_class Type
data type
Definition Type.hpp:426
an tensor (multi-dimensional array)
Definition Tensor.hpp:41
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1794
Tensor normal(const cytnx_uint64 &Nelem, const double &mean, const double &std, const int &device=Device.cpu, const unsigned int &seed=__static_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=__static_random_device(), const unsigned int &dtype=Type.Double)
create an Tensor with all the elements are initialized with uniform distribution
void normal_(cytnx::Storage &Sin, const double &mean, const double &std, const unsigned int &seed=__static_random_device())
Randomize the memory of a Storage with normal distributon.
void uniform_(cytnx::Storage &Sin, const double &low=0, const double &high=1, const unsigned int &seed=__static_random_device())
Randomize the memory of a Storage with uniform distributon.
std::random_device __static_random_device
Definition UniTensor.hpp:29
Definition Accessor.hpp:12
Device_class Device
data on which devices.