37 for (
int i = 0; i < outer_size; ++i)
39 float squared_l2_norm = 0;
40 for (
int c = 0; c < depth; ++c)
42 const float val = input_data[c];
43 squared_l2_norm += val * val;
45 float l2_norm = std::sqrt(squared_l2_norm);
46 l2_norm = std::max(l2_norm, epsilon);
47 for (
int c = 0; c < depth; ++c)
49 *output_data = *input_data / l2_norm;
64 for (
int i = 0; i < outer_size; ++i)
66 int32_t square_l2_norm = 0;
67 for (
int c = 0; c < depth; c++)
70 int32_t diff = input_data[c] - input_zero_point;
71 square_l2_norm += diff * diff;
73 int32_t inv_l2norm_multiplier;
76 for (
int c = 0; c < depth; c++)
78 int32_t diff = *input_data - input_zero_point;
80 128 * diff, inv_l2norm_multiplier, inv_l2norm_shift);
81 int32_t unclamped_output_val = 128 + rescaled_diff;
82 int32_t output_val = std::min(
static_cast<int32_t
>(255),
83 std::max(
static_cast<int32_t
>(0), unclamped_output_val));
84 *output_data =
static_cast<uint8_t
>(output_val);