31 const Shape &incoming_shape,
const float *incoming_data,
32 const Shape &grad_shape,
float *grad_data)
38 const int batches = incoming_shape.
Dims(0);
39 const int width = incoming_shape.
Dims(1);
41 for (
int b = 0; b < batches; ++b)
43 int b_offset = b * width;
44 for (
int w1 = 0; w1 < width; ++w1)
47 for (
int w2 = 0; w2 < width; ++w2)
52 val = output_data[b_offset + w2] * (1.f - output_data[b_offset + w2]);
56 val = -output_data[b_offset + w2] * output_data[b_offset + w1];
58 val *= incoming_data[b_offset + w2];
61 grad_data[b_offset + w1] = sum;
void SoftMaxGrad(const Shape &output_shape, const float *output_data, const Shape &incoming_shape, const float *incoming_data, const Shape &grad_shape, float *grad_data)