From 85792361a2699ffb71ece60abdc2927b47f17646 Mon Sep 17 00:00:00 2001 From: Chen-Yu Yang Date: Mon, 31 Aug 2026 09:59:13 -0400 Subject: [PATCH] more precise hardcoded const for erf and selu --- tinygrad/mixin/elementwise.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tinygrad/mixin/elementwise.py b/tinygrad/mixin/elementwise.py index bed5e5dabcae8..edbbedcda4235 100644 --- a/tinygrad/mixin/elementwise.py +++ b/tinygrad/mixin/elementwise.py @@ -985,7 +985,7 @@ def celu(self, alpha=1.0) -> Self: """ return alpha * (self / alpha).elu() - def selu(self, alpha=1.67326, gamma=1.0507) -> Self: + def selu(self, alpha=1.6732632423543772, gamma=1.0507009873554805) -> Self: """ Applies the Scaled Exponential Linear Unit (SELU) function element-wise. @@ -1065,9 +1065,9 @@ def erf(self) -> Self: print(Tensor([-1.5, -1.0, -0.5, 0., 0.5, 1.0, 1.5]).erf().numpy()) ``` """ - # https://personal.math.ubc.ca/~cbm/aands/page_299.htm 7.1.26 + # https://personal.math.ubc.ca/~cbm/aands/page_299.htm 7.1.26, with a1 rounded so the coefficients sum to 1 and erf(0) is exactly 0 t = 1.0 / (1.0 + 0.3275911 * (s:=(self >= 0).where(1.0, -1.0)) * self) - return s * (1.0 - t * polyN(t, [1.061405429, -1.453152027, 1.421413741, -0.284496736, 0.254829592]) * (-self.square()).exp()) + return s * (1.0 - t * polyN(t, [1.061405429, -1.453152027, 1.421413741, -0.284496736, 0.254829593]) * (-self.square()).exp()) def softsign(self) -> Self: """