ONE - On-device Neural Engine
Loading...
Searching...
No Matches
souschef::GaussianFloat16DataChef Class Referencefinal

#include <Gaussian.h>

Collaboration diagram for souschef::GaussianFloat16DataChef:

Public Member Functions

 GaussianFloat16DataChef (float mean, float stddev)
 
std::vector< uint8_t > generate (int32_t count) const override
 Generate a sequence of 'count' elements as a byte sequence.
 
- Public Member Functions inherited from souschef::DataChef
virtual ~DataChef ()=default
 

Detailed Description

Definition at line 44 of file Gaussian.h.

Constructor & Destructor Documentation

◆ GaussianFloat16DataChef()

souschef::GaussianFloat16DataChef::GaussianFloat16DataChef ( float  mean,
float  stddev 
)
inline

Definition at line 47 of file Gaussian.h.

47 : _mean{mean}, _stddev{stddev}
48 {
49 // DO NOTHING
50 }

Member Function Documentation

◆ generate()

std::vector< uint8_t > souschef::GaussianFloat16DataChef::generate ( int32_t  count) const
overridevirtual

Generate a sequence of 'count' elements as a byte sequence.

Let D be the return value of generate(N). Then, D.size() == N * sizeof(T) where T is the element type.

Implements souschef::DataChef.

Definition at line 75 of file Gaussian.cpp.

76{
77 auto time_stamp = std::chrono::system_clock::now().time_since_epoch().count();
78 auto seed = static_cast<std::minstd_rand::result_type>(time_stamp);
79
80 std::minstd_rand rand{static_cast<std::minstd_rand::result_type>(seed)};
81 std::normal_distribution<float> dist{_mean, _stddev};
82
83 std::vector<uint8_t> res;
84
85 constexpr float max_cap = 1e9;
86 constexpr float min_cap = -1e9;
87 for (uint32_t n = 0; n < count; ++n)
88 {
89 float raw_value = dist(rand);
90 const float capped_value = std::max(min_cap, std::min(max_cap, raw_value));
91 const uint16_t value = fp16_ieee_from_fp32_value(capped_value);
92 auto const arr = reinterpret_cast<const uint8_t *>(&value);
93
94 for (uint32_t b = 0; b < sizeof(uint16_t); ++b)
95 {
96 res.emplace_back(arr[b]);
97 }
98 }
99
100 return res;
101}
arr
Definition infer.py:92

The documentation for this class was generated from the following files: