20 "Required axis index greater than number of dimensions.");
22 "Required axis index lower than negative of the number of dimensions");
24 unsigned int uAxis = axis < 0 ?
26 :
static_cast<unsigned int>(axis);
30 const unsigned int axisSize = inputShape[uAxis];
35 for (
unsigned int outer = 0; outer < outerSize; ++outer)
37 unsigned int inputBeginIdx = outer * axisSize * innerSize;
38 unsigned int inputEndIdx = inputBeginIdx + axisSize * innerSize;
39 unsigned int outputBeginIdx = outer * axisSize * innerSize;
41 for (
unsigned int inner = 0; inner < innerSize; ++inner, ++inputBeginIdx, ++inputEndIdx, ++outputBeginIdx)
44 float maxValue = std::numeric_limits<float>::lowest();
45 for (
unsigned int iter = inputBeginIdx; iter < inputEndIdx; iter += innerSize)
48 maxValue = std::max(maxValue, in.
Get());
53 for (
unsigned int iter = inputBeginIdx; iter < inputEndIdx; iter += innerSize)
56 sum += std::exp((in.
Get() - maxValue) * beta);
60 unsigned int outputIter = outputBeginIdx;
62 for (
unsigned int iter = inputBeginIdx; iter < inputEndIdx; iter += innerSize, outputIter += innerSize)
66 out.
Set(std::exp((in.
Get() - maxValue) * beta) / sum);