c9ac571f9b3235f05dfaac9822806e8677ea9c32
[platform/core/ml/nnfw.git] / compiler / souschef / include / souschef / Data / Gaussian.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __SOUSCHEF_DATA_GAUSSIAN_H__
18 #define __SOUSCHEF_DATA_GAUSSIAN_H__
19
20 #include "souschef/DataChef.h"
21
22 namespace souschef
23 {
24
25 /**
26  * @brief Generate a sequence of random values according to the gaussian(=normal) distribution
27  */
28 class GaussianFloat32DataChef final : public DataChef
29 {
30 public:
31   GaussianFloat32DataChef(float mean, float stddev) : _mean{mean}, _stddev{stddev}
32   {
33     // DO NOTHING
34   }
35
36 public:
37   std::vector<uint8_t> generate(int32_t count) const override;
38
39 private:
40   float _mean;
41   float _stddev;
42 };
43
44 class GaussianFloat16DataChef final : public DataChef
45 {
46 public:
47   GaussianFloat16DataChef(float mean, float stddev) : _mean{mean}, _stddev{stddev}
48   {
49     // DO NOTHING
50   }
51
52 public:
53   std::vector<uint8_t> generate(int32_t count) const override;
54
55 private:
56   float _mean;
57   float _stddev;
58 };
59
60 class GaussianInt32DataChef final : public DataChef
61 {
62 public:
63   GaussianInt32DataChef(float mean, float stddev) : _mean{mean}, _stddev{stddev}
64   {
65     // DO NOTHING
66   }
67
68 public:
69   std::vector<uint8_t> generate(int32_t count) const override;
70
71 private:
72   float _mean;
73   float _stddev;
74 };
75
76 class GaussianInt16DataChef final : public DataChef
77 {
78 public:
79   GaussianInt16DataChef(float mean, float stddev) : _mean{mean}, _stddev{stddev}
80   {
81     // DO NOTHING
82   }
83
84 public:
85   std::vector<uint8_t> generate(int32_t count) const override;
86
87 private:
88   float _mean;
89   float _stddev;
90 };
91
92 class GaussianUint8DataChef final : public DataChef
93 {
94 public:
95   GaussianUint8DataChef(float mean, float stddev) : _mean{mean}, _stddev{stddev}
96   {
97     // DO NOTHING
98   }
99
100 public:
101   std::vector<uint8_t> generate(int32_t count) const override;
102
103 private:
104   float _mean;
105   float _stddev;
106 };
107
108 struct GaussianFloat32DataChefFactory : public DataChefFactory
109 {
110   std::unique_ptr<DataChef> create(const Arguments &args) const;
111 };
112
113 struct GaussianInt32DataChefFactory : public DataChefFactory
114 {
115   std::unique_ptr<DataChef> create(const Arguments &args) const;
116 };
117
118 struct GaussianInt16DataChefFactory : public DataChefFactory
119 {
120   std::unique_ptr<DataChef> create(const Arguments &args) const;
121 };
122
123 struct GaussianUint8DataChefFactory : public DataChefFactory
124 {
125   std::unique_ptr<DataChef> create(const Arguments &args) const;
126 };
127
128 struct GaussianFloat16DataChefFactory : public DataChefFactory
129 {
130   std::unique_ptr<DataChef> create(const Arguments &args) const;
131 };
132
133 } // namespace souschef
134
135 #endif // __SOUSCHEF_DATA_GAUSSIAN_H__