Skip to content

Commit d0c80b7

Browse files
authored
Define inverse functions (#29)
1 parent 584442d commit d0c80b7

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

Project.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
name = "LogExpFunctions"
22
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
33
authors = ["StatsFun.jl contributors, Tamas K. Papp <[email protected]>"]
4-
version = "0.3.3"
4+
version = "0.3.4"
55

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

1213
[compat]
1314
ChainRulesCore = "1"
1415
DocStringExtensions = "0.8"
16+
InverseFunctions = "0.1"
1517
IrrationalConstants = "0.1"
1618
julia = "1"
1719

src/LogExpFunctions.jl

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using DocStringExtensions: SIGNATURES
44
using Base: Math.@horner
55

66
import ChainRulesCore
7+
import InverseFunctions
78
import IrrationalConstants
89
import LinearAlgebra
910

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

1820
end # module

src/inverse.jl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
InverseFunctions.inverse(::typeof(log1pexp)) = logexpm1
2+
InverseFunctions.inverse(::typeof(logexpm1)) = log1pexp
3+
4+
InverseFunctions.inverse(::typeof(log1mexp)) = log1mexp
5+
6+
InverseFunctions.inverse(::typeof(log2mexp)) = log2mexp
7+
8+
InverseFunctions.inverse(::typeof(logit)) = logistic
9+
InverseFunctions.inverse(::typeof(logistic)) = logit

test/inverse.jl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@testset "inverse.jl" begin
2+
InverseFunctions.test_inverse(log1pexp, randn())
3+
InverseFunctions.test_inverse(logexpm1, randexp())
4+
5+
InverseFunctions.test_inverse(log1mexp, -randexp())
6+
7+
InverseFunctions.test_inverse(log2mexp, log(2) - randexp())
8+
9+
InverseFunctions.test_inverse(logistic, randn())
10+
InverseFunctions.test_inverse(logit, rand())
11+
end

test/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using LogExpFunctions
22
using ChainRulesTestUtils
3+
using InverseFunctions
34
using OffsetArrays
45

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

1011
include("basicfuns.jl")
1112
include("chainrules.jl")
13+
include("inverse.jl")

0 commit comments

Comments
 (0)