Skip to content

Commit

Permalink
Add rectifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Feb 22, 2022
1 parent 3ff786a commit 15ab20f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SLEEFPirates"
uuid = "476501e8-09a2-5ece-8869-fb82de89a1fa"
authors = ["chriselrod <elrodc@gmail.com>"]
version = "0.6.29"
version = "0.6.30"

[deps]
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
Expand Down
5 changes: 4 additions & 1 deletion src/SLEEFPirates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ using VectorizationBase: vzero, AbstractSIMD, _Vec, fma_fast, data, VecUnroll, N

import IfElse: ifelse

export Vec, sigmoid_fast, tanh_fast#, loggamma
export Vec, sigmoid_fast, tanh_fast,
PReLu, gelu, softplus, silu, Elu
#, loggamma

const FloatType64 = Union{Float64,AbstractSIMD{<:Any,Float64}}
const FloatType32 = Union{Float32,AbstractSIMD{<:Any,Float32}}
Expand Down Expand Up @@ -118,6 +120,7 @@ include("log.jl") # logarithmic functions
include("trig.jl") # trigonometric and inverse trigonometric functions
include("hyp.jl") # hyperbolic and inverse hyperbolic functions
include("misc.jl") # miscallenous math functions including pow and cbrt
include("rectifier.jl")
# if Int === Int64
# if isfile(joinpath(@__DIR__, "svmlwrap.jl"))
# include("svmlwrap.jl")
Expand Down
13 changes: 13 additions & 0 deletions src/rectifier.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

struct PReLu{T}; a::T; end
@inline (p::PReLu)(x) = ifelse(x <= 0, x * p.a, x)

@inline Φ(x::T) where {T} = @fastmath T(0.5) * (one(T) + VectorizationBase.verf(x * T(0.7071067811865476)))
@inline gelu(x) = Base.FastMath.mul_fast(x, Φ(x))

@inline softplus(x) = log1p(exp(x))
@inline silu(x) = Base.FastMath.mul_fast(x, sigmoid_fast(x))

struct Elu{T}; a::T; end
@inline (e::Elu)(x) = ifelse(x <= 0, Base.FastMath.mul_fast(e.a, expm1_fast(x)), x)

2 comments on commit 15ab20f

@chriselrod
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/55244

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.6.30 -m "<description of version>" 15ab20fcfcc3452a3764bc8941c49456a67de1b1
git push origin v0.6.30

Please sign in to comment.