Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define inverse functions with InverseFunctions.jl #29

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name = "LogExpFunctions"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
authors = ["StatsFun.jl contributors, Tamas K. Papp <tkpapp@gmail.com>"]
version = "0.3.3"
version = "0.3.4"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[compat]
ChainRulesCore = "1"
DocStringExtensions = "0.8"
InverseFunctions = "0.1"
IrrationalConstants = "0.1"
julia = "1"

Expand Down
2 changes: 2 additions & 0 deletions src/LogExpFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using DocStringExtensions: SIGNATURES
using Base: Math.@horner

import ChainRulesCore
import InverseFunctions
import IrrationalConstants
import LinearAlgebra

Expand All @@ -14,5 +15,6 @@ export xlogx, xlogy, xlog1py, logistic, logit, log1psq, log1pexp, log1mexp, log2
include("basicfuns.jl")
include("logsumexp.jl")
include("chainrules.jl")
include("inverse.jl")

end # module
9 changes: 9 additions & 0 deletions src/inverse.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
InverseFunctions.inverse(::typeof(log1pexp)) = logexpm1
InverseFunctions.inverse(::typeof(logexpm1)) = log1pexp

InverseFunctions.inverse(::typeof(log1mexp)) = log1mexp

InverseFunctions.inverse(::typeof(log2mexp)) = log2mexp

InverseFunctions.inverse(::typeof(logit)) = logistic
InverseFunctions.inverse(::typeof(logistic)) = logit
11 changes: 11 additions & 0 deletions test/inverse.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@testset "inverse.jl" begin
InverseFunctions.test_inverse(log1pexp, randn())
InverseFunctions.test_inverse(logexpm1, randexp())

InverseFunctions.test_inverse(log1mexp, -randexp())

InverseFunctions.test_inverse(log2mexp, log(2) - randexp())

InverseFunctions.test_inverse(logistic, randn())
InverseFunctions.test_inverse(logit, rand())
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LogExpFunctions
using ChainRulesTestUtils
using InverseFunctions
using OffsetArrays

using Random
Expand All @@ -9,3 +10,4 @@ Random.seed!(1234)

include("basicfuns.jl")
include("chainrules.jl")
include("inverse.jl")