Skip to content

Commit

Permalink
Define inverse functions (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Oct 19, 2021
1 parent 584442d commit d0c80b7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
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")

2 comments on commit d0c80b7

@devmotion
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/47043

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.3.4 -m "<description of version>" d0c80b709c64025ccde96cf56b4d781262f5fd7e
git push origin v0.3.4

Please sign in to comment.