-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtensor_generate_lib.h
78 lines (59 loc) · 2.1 KB
/
tensor_generate_lib.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef _TENSOR_GENERATE_LIB_H_
#define _TENSOR_GENERATE_LIB_H_
// Namespace
namespace tensor_lib {
namespace internal {
template <typename T>
struct uniform_distribution_traits
{
using backend_t = typename std::conditional<(std::is_integral<T>::value || std::is_floating_point<T>::value), T, double>::type;
using uniform_distribution_t = typename std::conditional<std::is_integral<T>::value, std::uniform_int_distribution<T>,
std::uniform_real_distribution<backend_t> >::type;
};
template <typename T>
T uniform_rand(const T& lobound, const T&hibound)
{
using backend_t = typename uniform_distribution_traits<T>::backend_t;
using uniform_distribution_t = typename uniform_distribution_traits<T>::uniform_distribution_t;
static std::random_device rd;
static std::mt19937 gen(rd());
backend_t _lobound(lobound);
backend_t _hibound(hibound);
uniform_distribution_t distr(_lobound, _hibound);
return T(distr(gen));
}
}
// Randomizer
// INT randTensor
template <typename myType, unsigned bitwidth>
void randTensor(std::vector<myType> & foo);
template <typename myType, unsigned bitwidth>
void randTensor(std::vector<std::vector<myType> > & foo);
template <typename myType, unsigned bitwidth>
void randTensor(std::vector<std::vector<std::vector<myType> > >& foo);
template <typename myType, unsigned bitwidth>
void randTensor(std::vector<std::vector<std::vector<std::vector<myType> > > >& foo);
// FLOAT randTensor
template <typename myType>
void randTensor(
std::vector<myType> & foo,
const myType low_bound, const myType high_bound
);
template <typename myType>
void randTensor(
std::vector<std::vector<myType> > & foo,
const myType low_bound, const myType high_bound
);
template <typename myType>
void randTensor(
std::vector<std::vector<std::vector<myType> > >& foo,
const myType low_bound, const myType high_bound
);
template <typename myType>
void randTensor(
std::vector<std::vector<std::vector<std::vector<myType> > > >& foo,
const myType low_bound, const myType high_bound
);
}
#include "tpp/tensor_generate_lib.cpp"
#endif