Compare commits

...

2 Commits

Author SHA1 Message Date
dante
cf6dcba5ae Update ops.rs 2025-03-17 13:03:11 +00:00
dante
fd81344b51 fix: recip denom epsilon can induce non opt res 2025-03-17 12:56:59 +00:00

View File

@@ -2346,7 +2346,11 @@ pub mod nonlinearities {
pub fn recip(a: &Tensor<IntegerRep>, input_scale: f64, out_scale: f64) -> Tensor<IntegerRep> {
a.par_enum_map(|_, a_i| {
let rescaled = (a_i as f64) / input_scale;
let denom = (1_f64) / (rescaled + f64::EPSILON);
let denom = if rescaled == 0_f64 {
(1_f64) / (rescaled + f64::EPSILON)
} else {
(1_f64) / (rescaled)
};
let d_inv_x = out_scale * denom;
Ok::<_, TensorError>(d_inv_x.round() as IntegerRep)
})