60inline void Logistic(
const int flat_size,
const int8_t *input_data,
float input_scale,
61 int input_zero_point, int8_t *output_data,
float output_scale,
62 int output_zero_point)
64 const float cutoff_upper = 16.619047164916992188f;
65 const float cutoff_lower = -9.f;
75 for (
int i = 0; i < flat_size; i++)
78 float val =
static_cast<float>((input_data[i] - input_zero_point) * input_scale);
80 if (val > cutoff_upper)
84 else if (val < cutoff_lower)
86 result = std::exp(val);
90 result = 1.f / (1.f + std::exp(-val));
93 int8_t output =
static_cast<int8_t
>(result / output_scale + output_zero_point);
94 output_data[i] = output;
98inline void Logistic(int32_t input_multiplier, int32_t input_left_shift, int32_t input_size,
99 const int16_t *ptr_input_data, int16_t *ptr_output_data)
108 if (input_multiplier == 0)
110 input_multiplier = 3 << input_left_shift;
111 input_left_shift = 0;
114 int32_t round = (input_left_shift > 0) ? 1 << (input_left_shift - 1) : 0;
116 for (
int i = 0; i < input_size; ++i, ptr_input_data++, ptr_output_data++)
118 int32_t input_data = ((*ptr_input_data) * input_multiplier + round) >> input_left_shift;
121 uint32_t abs_input_data = abs(input_data);
128 uint32_t uh = abs_input_data >> 9;
134 result = 0x7FFF << 10;
138 uint32_t ua = sigmoid_table_uint16[uh];
139 uint32_t ub = sigmoid_table_uint16[uh + 1];
140 uint32_t ut = abs_input_data & 0x1ff;
142 result = (ua << 9) + ut * (ub - ua);
145 result = (input_data >= 0) ? (result + (1 << 9)) : ((1 << (16 + 9)) - result + (1 << 9) - 1);
150 *ptr_output_data = result;