-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrandom.h
More file actions
62 lines (47 loc) · 1.34 KB
/
Copy pathrandom.h
File metadata and controls
62 lines (47 loc) · 1.34 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// random.h
// RNG for distributions
#ifndef TINYTENSOR_RANDOM_H_
#define TINYTENSOR_RANDOM_H_
#include <tt/export.h>
#include <tt/macros.h>
#include <cstdint>
#include <vector>
namespace tinytensor {
// RNG object for all distribution functions
//
class TINYTENSOR_EXPORT Generator {
public:
/**
* Create a Generator from a seed
* @param seed The seed
*/
TT_HOST_DEVICE Generator(uint64_t seed);
/**
* Factory to create a generator from a state
*/
TT_HOST_DEVICE static auto from_state(uint64_t state) -> Generator;
/**
* Generate a random set of 64 bits
*/
TT_HOST_DEVICE auto operator()() noexcept -> uint64_t;
/**
* Set the state of the generator object
*/
TT_HOST_DEVICE void set_state(uint64_t state);
private:
TT_HOST_DEVICE Generator(uint64_t s, bool is_state);
uint64_t state;
};
TINYTENSOR_EXPORT void shuffle(std::vector<int> &data, Generator &gen);
/**
* Set the default generator state using the passed seed
* @param seed The seed
*/
TINYTENSOR_EXPORT void set_default_generator_seed(uint64_t seed);
/**
* Get the default generator.
* For reproducibility, its recommended to not rely on this and create your own Generator
*/
TINYTENSOR_EXPORT auto get_default_generator() -> Generator &;
} // namespace tinytensor
#endif // TINYTENSOR_RANDOM_H_