Skip to content

Commit

Permalink
docs and test
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Sep 14, 2024
1 parent a113b43 commit 0a03aba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ logcosh
logabssinh
log1psq
log1pexp
softplus
invsoftplus
log1mexp
log2mexp
logexpm1
Expand Down
2 changes: 2 additions & 0 deletions src/basicfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ See:
"""
softplus(x::Real) = log1pexp(x)
softplus(x::Real, a::Real) = log1pexp(a * x) / a
softplus(x::Real; a::Real=1) = softplus(x, a)

"""
$(SIGNATURES)
Expand All @@ -280,6 +281,7 @@ The inverse generalized `softplus` function (Wiemann et al., 2024). See [`softpl
"""
invsoftplus(y::Real) = logexpm1(y)
invsoftplus(y::Real, a::Real) = logexpm1(a * y) / a
invsoftplus(y::Real; a::Real=1) = invsoftplus(y, a)


"""
Expand Down
10 changes: 10 additions & 0 deletions test/basicfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ end
end
end

@testset "softplus" begin
@test softplus(2) log1pexp(2)
@test softplus(2, 1) log1pexp(2)
@test softplus(2, a=1) log1pexp(2)
@test softplus(2, 10) < log1pexp(2)
@test invsoftplus(softplus(2), 1) 2
@test invsoftplus(softplus(2, 10), a=10) 2
end


@testset "log1mexp" begin
for T in (Float64, Float32, Float16)
@test @inferred(log1mexp(-T(1))) isa T
Expand Down

0 comments on commit 0a03aba

Please sign in to comment.