@@ -264,22 +264,22 @@ func (e StdEng) softMaxBLastDimF64(inputGrad, output, grad Tensor, axis int, log
264
264
dx [i ] = gradArr [i ] - (math .Exp (outputArr [i ]) * sum )
265
265
}
266
266
} else {
267
- mul := make ([]float64 , dimSize )
268
-
267
+ // mul := make([]float64, dimSize)
268
+ var sum float64
269
269
for j := 0 ; j < dimSize ; j ++ {
270
270
i := ii * dimSize + j
271
271
272
- mul [j ] = outputArr [i ] * gradArr [i ]
272
+ // mul[j] = outputArr[i] * gradArr[i]
273
+ sum += outputArr [i ] * gradArr [i ]
273
274
}
274
275
275
- sum := mul [0 ]
276
- for j := 1 ; j < dimSize ; j ++ {
277
- sum += mul [j ]
278
- }
276
+ // sum := mul[0]
277
+ // for j := 1; j < dimSize; j++ {
278
+ // sum += mul[j]
279
+ // }
279
280
280
281
for j := 0 ; j < dimSize ; j ++ {
281
282
i := ii * dimSize + j
282
-
283
283
dx [i ] = (gradArr [i ] - sum ) * outputArr [i ]
284
284
}
285
285
}
@@ -481,18 +481,19 @@ func (e StdEng) softMaxBLastDimF32(inputGrad, output, grad Tensor, axis int, log
481
481
dx [i ] = gradArr [i ] - (math32 .Exp (outputArr [i ]) * sum )
482
482
}
483
483
} else {
484
- mul := make ([]float32 , dimSize )
485
-
484
+ // mul := make([]float32, dimSize)
485
+ var sum float32
486
486
for j := 0 ; j < dimSize ; j ++ {
487
487
i := ii * dimSize + j
488
488
489
- mul [j ] = outputArr [i ] * gradArr [i ]
489
+ //mul[j] = outputArr[i] * gradArr[i]
490
+ sum += outputArr [i ] * gradArr [i ]
490
491
}
491
492
492
- sum := mul [0 ]
493
- for j := 1 ; j < dimSize ; j ++ {
494
- sum += mul [j ]
495
- }
493
+ // sum := mul[0]
494
+ // for j := 1; j < dimSize; j++ {
495
+ // sum += mul[j]
496
+ // }
496
497
497
498
for j := 0 ; j < dimSize ; j ++ {
498
499
i := ii * dimSize + j
0 commit comments