MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / PopulateLookupTable

Function PopulateLookupTable

tensorflow/lite/kernels/activations.cc:98–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96
97template <typename T>
98void PopulateLookupTable(struct OpData* data, const TfLiteTensor* input,
99 TfLiteTensor* output,
100 const std::function<float(float)>& transform) {
101 static_assert(sizeof(T) == 1, "Lookup table valid only for 8bit");
102 const float inverse_scale = 1 / output->params.scale;
103 int32_t maxval = std::numeric_limits<T>::max();
104 int32_t minval = std::numeric_limits<T>::min();
105 data->table_zero = &data->table[-minval];
106 for (int32_t val = minval; val <= maxval; ++val) {
107 const float dequantized =
108 input->params.scale * (val - input->params.zero_point);
109 const float transformed = transform(dequantized);
110 const float rescaled = std::round(transformed * inverse_scale);
111 const int32_t quantized =
112 static_cast<int32_t>(rescaled + output->params.zero_point);
113 data->table_zero[val] =
114 static_cast<uint8_t>(std::max(std::min(maxval, quantized), minval));
115 }
116}
117
118template <typename T>
119void EvalUsingLookupTable(struct OpData* data, const TfLiteTensor* input,

Callers

nothing calls this directly

Calls 4

maxFunction · 0.50
minFunction · 0.50
transformFunction · 0.50
roundFunction · 0.50

Tested by

no test coverage detected