25inline void Softmax(
const SoftmaxParams ¶ms,
const float *input_data,
float *output_data)
27 const int outer_size = params.
num_rows;
29 const double beta = params.
beta;
31 for (
int i = 0; i < outer_size; ++i)
36 float max = std::numeric_limits<float>::lowest();
37 for (
int c = 0; c < depth; ++c)
39 max = std::max(max, input_data[i * depth + c]);
44 for (
int c = 0; c < depth; ++c)
46 const float exp_c = std::exp((input_data[i * depth + c] - max) *
static_cast<float>(beta));
47 output_data[i * depth + c] = exp_c;
52 for (
int c = 0; c < depth; ++c)
54 output_data[i * depth + c] = output_data[i * depth + c] / sum;