TFLite: reduced duplicated calculation of exp in softmax.h (float)
This commit is contained in:
parent
c979f5a424
commit
a8d859546f
@ -49,15 +49,15 @@ inline void Softmax(const SoftmaxParams& params,
|
|||||||
// Compute sum.
|
// Compute sum.
|
||||||
float sum = 0.f;
|
float sum = 0.f;
|
||||||
for (int c = 0; c < depth; ++c) {
|
for (int c = 0; c < depth; ++c) {
|
||||||
sum += std::exp((input_data[i * depth + c] - max) *
|
const float exp_c = std::exp((input_data[i * depth + c] - max) *
|
||||||
static_cast<float>(params.beta));
|
static_cast<float>(params.beta));
|
||||||
|
output_data[i * depth + c] = exp_c;
|
||||||
|
sum += exp_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute result.
|
// Compute result.
|
||||||
for (int c = 0; c < depth; ++c) {
|
for (int c = 0; c < depth; ++c) {
|
||||||
output_data[i * depth + c] = std::exp((input_data[i * depth + c] - max) *
|
output_data[i * depth + c] = output_data[i * depth + c] / sum;
|
||||||
static_cast<float>(params.beta)) /
|
|
||||||
sum;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user