Skip to content

Commit 0a03aba

Browse files
docs and test
1 parent a113b43 commit 0a03aba

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

docs/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ logcosh
1818
logabssinh
1919
log1psq
2020
log1pexp
21+
softplus
22+
invsoftplus
2123
log1mexp
2224
log2mexp
2325
logexpm1

src/basicfuns.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ See:
272272
"""
273273
softplus(x::Real) = log1pexp(x)
274274
softplus(x::Real, a::Real) = log1pexp(a * x) / a
275+
softplus(x::Real; a::Real=1) = softplus(x, a)
275276

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

284286

285287
"""

test/basicfuns.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ end
161161
end
162162
end
163163

164+
@testset "softplus" begin
165+
@test softplus(2) log1pexp(2)
166+
@test softplus(2, 1) log1pexp(2)
167+
@test softplus(2, a=1) log1pexp(2)
168+
@test softplus(2, 10) < log1pexp(2)
169+
@test invsoftplus(softplus(2), 1) 2
170+
@test invsoftplus(softplus(2, 10), a=10) 2
171+
end
172+
173+
164174
@testset "log1mexp" begin
165175
for T in (Float64, Float32, Float16)
166176
@test @inferred(log1mexp(-T(1))) isa T

0 commit comments

Comments
 (0)