Skip to content

Commit ff3ac6e

Browse files
authored
Fix tanh_fast for large Float64 (#408)
* fix tanh_fast for large Float64 * bump version
1 parent 886b34c commit ff3ac6e

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "NNlib"
22
uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
3-
version = "0.8.4"
3+
version = "0.8.5"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/activations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ end
780780
# Instead, we switch to a polynomial, which is very accurate within its range:
781781
x2 = x * x
782782
ypoly = x * evalpoly(x2, (1.0, -0.33333333333324583, 0.13333333325511604, -0.05396823125794372, 0.02186660872609521, -0.008697141630499953))
783-
ifelse(x2 > 900.0, sign(y), ifelse(x2 < 0.017, oftype(y, ypoly), y))
783+
ifelse(x2 > 900.0, sign(x), ifelse(x2 < 0.017, ypoly, y))
784784
end
785785

786786
# These approximations are very badly behaved for Float16; none are fast.

test/activations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ end
227227
@testset "tanh_fast & sigmoid_fast: Float64" begin
228228

229229
x64 = 1e-6:1e-4:5
230-
xbig = 6:3:200.0
230+
xbig = vcat(6:3:200.0, 1000, 10^6, typemax(Float64))
231231

232232
@testset "tanh" begin
233233
mean_eps(tanh, tanh, x64) # 0.06582
@@ -263,7 +263,7 @@ end
263263
@testset "tanh_fast & sigmoid_fast: Float32" begin
264264

265265
x32 = 1f-6:1f-4:5
266-
xbig32 = 6:3:200f0
266+
xbig32 = vcat(6:3:200f0, 1000, typemax(Float32))
267267

268268
@testset "tanh" begin
269269
mean_eps(tanh, tanh, x32) # 0.065

0 commit comments

Comments
 (0)