l2Normalize static method
Implementation
static Tensor l2Normalize(
Tensor input,
List<Tensor> tracker, {
double eps = 1e-12,
}) {
final xSq = input.pow(2.0);
final sumSq = xSq.sum();
final norm = sumSq.pow(0.5) + eps;
final result = input / norm;
// Track everything so backward() can see the math
tracker.addAll([xSq, sumSq, norm, result]);
return result;
}