Skip to content

Commit

Permalink
Fix tanh_fast for large Float64 (#408)
Browse files Browse the repository at this point in the history
* fix tanh_fast for large Float64

* bump version
  • Loading branch information
mcabbott authored May 6, 2022
1 parent 886b34c commit ff3ac6e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "NNlib"
uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
version = "0.8.4"
version = "0.8.5"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion src/activations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ end
# Instead, we switch to a polynomial, which is very accurate within its range:
x2 = x * x
ypoly = x * evalpoly(x2, (1.0, -0.33333333333324583, 0.13333333325511604, -0.05396823125794372, 0.02186660872609521, -0.008697141630499953))
ifelse(x2 > 900.0, sign(y), ifelse(x2 < 0.017, oftype(y, ypoly), y))
ifelse(x2 > 900.0, sign(x), ifelse(x2 < 0.017, ypoly, y))
end

# These approximations are very badly behaved for Float16; none are fast.
Expand Down
4 changes: 2 additions & 2 deletions test/activations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ end
@testset "tanh_fast & sigmoid_fast: Float64" begin

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

@testset "tanh" begin
mean_eps(tanh, tanh, x64) # 0.06582
Expand Down Expand Up @@ -263,7 +263,7 @@ end
@testset "tanh_fast & sigmoid_fast: Float32" begin

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

@testset "tanh" begin
mean_eps(tanh, tanh, x32) # 0.065
Expand Down

2 comments on commit ff3ac6e

@mcabbott
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/59773

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.5 -m "<description of version>" ff3ac6eb807e9b41f46f28f8b3287d19f4b722c7
git push origin v0.8.5

Please sign in to comment.