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#include "backend/Storage.hpp"
14
15namespace cytnx {
20 namespace random {
21 // Actual definition is in uniform_.cpp
22 extern std::random_device __static_random_device;
23
24 // [Storage]
25 // =============================================================================================================
26 // =============================================================================================================
27 // normal_:
28 //--------------------------------------------------
37 void normal_(cytnx::Storage &Sin, const double &mean, const double &std,
38 const unsigned int &seed = __static_random_device());
39
40 // uniform_:
41 //--------------------------------------------------
53 void uniform_(cytnx::Storage &Sin, const double &low = 0, const double &high = 1,
54 const unsigned int &seed = __static_random_device());
55
56 // [Tensor]
57 // =============================================================================================================
58 // =============================================================================================================
59 // normal_:
60 //-------------------------------------------------
69 void normal_(cytnx::Tensor &Tin, const double &mean, const double &std,
70 const unsigned int &seed = __static_random_device());
71
72 // uniform_:
73 //--------------------------------------------------
86 void uniform_(cytnx::Tensor &Tin, const double &low = 0, const double &high = 1,
87 const unsigned int &seed = __static_random_device());
88
89 // [UniTensor]
90 // =============================================================================================================
91 // =============================================================================================================
92 // normal_:
93 //-------------------------------------------------
102 void normal_(cytnx::UniTensor &Tin, const double &mean, const double &std,
103 const unsigned int &seed = __static_random_device());
104
105 // uniform_:
106 //--------------------------------------------------
118 void uniform_(cytnx::UniTensor &Tin, const double &low = 0, const double &high = 1,
119 const unsigned int &seed = __static_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,
138 const unsigned int &seed = __static_random_device(),
139 const unsigned int &dtype = Type.Double);
140
153 Tensor normal(const std::vector<cytnx_uint64> &Nelem, const double &mean, const double &std,
154 const int &device = Device.cpu,
155 const unsigned int &seed = __static_random_device(),
156 const unsigned int &dtype = Type.Double);
158
159 // uniform:
161
173 Tensor uniform(const cytnx_uint64 &Nelem, const double &low, const double &high,
174 const int &device = Device.cpu,
175 const unsigned int &seed = __static_random_device(),
176 const unsigned int &dtype = Type.Double);
177
191 Tensor uniform(const std::vector<cytnx_uint64> &Nelem, const double &low, const double &high,
192 const int &device = Device.cpu,
193 const unsigned int &seed = __static_random_device(),
194 const unsigned int &dtype = Type.Double);
196
209 Tensor random_tensor(const std::vector<cytnx_uint64> &shape, const double &low = -10.0,
210 const double &high = 10.0, const int &device = Device.cpu,
211 const unsigned int &seed = __static_random_device(),
212 const unsigned int &dtype = Type.Double);
213
215 // this is going to deprecated:
216 template <class T>
217 [[deprecated("Use random::normal_ instead")]] void Make_normal(
218 T &In, const double &mean, const double &std,
219 const unsigned int &seed = __static_random_device()) {
220 normal_(In, mean, std, seed);
221 }
222 template <class T>
223 [[deprecated("Use random::uniform_ instead")]] void Make_uniform(
224 T &In, const double &low, const double &high,
225 const unsigned int &seed = __static_random_device()) {
226 uniform_(In, low, high, seed);
227 }
228
230
231 } // namespace random
232} // namespace cytnx
233
234#endif // CYTNX_RANDOM_H_
constexpr Type_class Type
data type
Definition Type.hpp:553
an tensor (multi-dimensional array)
Definition Tensor.hpp:33
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:2773
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:27
Tensor random_tensor(const std::vector< cytnx_uint64 > &shape, const double &low=-10.0, const double &high=10.0, const int &device=Device.cpu, const unsigned int &seed=__static_random_device(), const unsigned int &dtype=Type.Double)
create a Tensor with random values for any data type
Definition Accessor.hpp:12
Device_class Device
data on which devices.