35 const int outer_size = params.
num_rows;
37 const double beta = params.
beta;
42 const int input_zp = params.
input_zp;
45 for (
int i = 0; i < outer_size; ++i)
50 float max = std::numeric_limits<float>::lowest();
51 for (
int c = 0; c < depth; ++c)
53 auto t = input_data[i * depth + c] - input_zp;
54 auto t_f =
static_cast<float>(input_data[i * depth + c] - input_zp);
55 float cur_val =
static_cast<float>(input_data[i * depth + c] - input_zp) * input_scale;
56 max = std::max(max, cur_val);
59 static constexpr int32_t min_val = std::numeric_limits<U>::min();
60 static constexpr int32_t max_val = std::numeric_limits<U>::max();
63 for (
int c = 0; c < depth; ++c)
65 float cur_val =
static_cast<float>(input_data[i * depth + c] - input_zp) * input_scale;
66 const auto exp_c =
static_cast<float>(std::exp((cur_val - max) * beta));
71 for (
int c = 0; c < depth; ++c)
73 float cur_val =
static_cast<float>(input_data[i * depth + c] - input_zp) * input_scale;
74 const auto exp_c =
static_cast<float>(std::exp((cur_val - max) * beta));
75 float softmax_val = exp_c / sum;
76 auto unclamped =
static_cast<int32_t
>(std::round(softmax_val / output_scale) +
77 static_cast<float>(output_zp));
78 int32_t clamped = std::min(std::max(unclamped, min_val), max_val);
79 output_data[i * depth + c] =
static_cast<U
>(clamped);
89 const int outer_size = params.
num_rows;
91 const double beta = params.
beta;
93 for (
int i = 0; i < outer_size; ++i)
98 float max = std::numeric_limits<float>::lowest();
99 for (
int c = 0; c < depth; ++c)
101 max = std::max(max, input_data[i * depth + c]);
106 for (
int c = 0; c < depth; ++c)
108 const float exp_c = std::exp((input_data[i * depth + c] - max) *
static_cast<float>(beta));
109 output_data[i * depth + c] = exp_c;
119 for (
int c = 0; c < depth; ++c)
121 output_data[i * depth + c] = output_data[i * depth + c] / sum;