Cytnx v0.9.7
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 // Actual definition is in uniform_.cpp
24 extern std::random_device __static_random_device;
25
26 // [Storage]
27 // =============================================================================================================
28 // =============================================================================================================
29 // normal_:
30 //--------------------------------------------------
39 void normal_(cytnx::Storage &Sin, const double &mean, const double &std,
40 const unsigned int &seed = __static_random_device());
41
42 // uniform_:
43 //--------------------------------------------------
55 void uniform_(cytnx::Storage &Sin, const double &low = 0, const double &high = 1,
56 const unsigned int &seed = __static_random_device());
57
58 // [Tensor]
59 // =============================================================================================================
60 // =============================================================================================================
61 // normal_:
62 //-------------------------------------------------
71 void normal_(cytnx::Tensor &Tin, const double &mean, const double &std,
72 const unsigned int &seed = __static_random_device());
73
74 // uniform_:
75 //--------------------------------------------------
88 void uniform_(cytnx::Tensor &Tin, const double &low = 0, const double &high = 1,
89 const unsigned int &seed = __static_random_device());
90
91 // [UniTensor]
92 // =============================================================================================================
93 // =============================================================================================================
94 // normal_:
95 //-------------------------------------------------
104 void normal_(cytnx::UniTensor &Tin, const double &mean, const double &std,
105 const unsigned int &seed = __static_random_device());
106
107 // uniform_:
108 //--------------------------------------------------
120 void uniform_(cytnx::UniTensor &Tin, const double &low = 0, const double &high = 1,
121 const unsigned int &seed = __static_random_device());
122
123 // normal:
125
138 Tensor normal(const cytnx_uint64 &Nelem, const double &mean, const double &std,
139 const int &device = Device.cpu,
140 const unsigned int &seed = __static_random_device(),
141 const unsigned int &dtype = Type.Double);
142
155 Tensor normal(const std::vector<cytnx_uint64> &Nelem, const double &mean, const double &std,
156 const int &device = Device.cpu,
157 const unsigned int &seed = __static_random_device(),
158 const unsigned int &dtype = Type.Double);
160
161 // uniform:
163
175 Tensor uniform(const cytnx_uint64 &Nelem, const double &low, const double &high,
176 const int &device = Device.cpu,
177 const unsigned int &seed = __static_random_device(),
178 const unsigned int &dtype = Type.Double);
179
193 Tensor uniform(const std::vector<cytnx_uint64> &Nelem, const double &low, const double &high,
194 const int &device = Device.cpu,
195 const unsigned int &seed = __static_random_device(),
196 const unsigned int &dtype = Type.Double);
198
200 // this is going to deprecated:
201 template <class T>
202 void Make_normal(T &In, const double &mean, const double &std,
203 const unsigned int &seed = __static_random_device()) {
204 normal_(In, mean, std, seed);
205 }
206 template <class T>
207 void Make_uniform(T &In, const double &low, const double &high,
208 const unsigned int &seed = __static_random_device()) {
209 uniform_(In, low, high, seed);
210 }
211
213
214 } // namespace random
215} // namespace cytnx
216
217#endif // BACKEND_TORCH
218
219#endif
an tensor (multi-dimensional array)
Definition Tensor.hpp:41
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1783
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
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