The .reduce() on the C-fragment gives global max across all rows, not per-row max. Compute row_max element-wise from S values before the exp2 pass. Also accumulate row_sum in the exp2 pass.
The .reduce() on the C-fragment gives global max across all rows, not per-row max. Compute row_max element-wise from S values before the exp2 pass. Also accumulate row_sum in the exp2 pass.