Skip to content

Commit b7114f9

Browse files
authored
Some improvements (#1)
* Update docstring according to Julia style guide * Clean InverseFunctions.jl * Simplify CI * Update src/inverse.jl
1 parent 4200a48 commit b7114f9

File tree

7 files changed

+74
-54
lines changed

7 files changed

+74
-54
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ on:
44
push:
55
branches:
66
- master
7-
- dev
8-
- 'releases/**'
97
tags: '*'
108
pull_request:
11-
release:
9+
10+
concurrency:
11+
# Skip intermediate builds: always.
12+
# Cancel intermediate builds: only if it is a pull request build.
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
1215

1316
jobs:
1417
test:
@@ -24,19 +27,18 @@ jobs:
2427
- 'nightly'
2528
os:
2629
- ubuntu-latest
27-
- macOS-latest
28-
- windows-latest
2930
arch:
3031
- x64
31-
- x86
32-
exclude:
33-
# 32-bit Julia binaries are not available on macOS
34-
- os: macOS-latest
35-
arch: x86
36-
- os: windows-latest
37-
arch: x86
38-
- version: nightly
32+
include:
33+
- version: 1
34+
os: ubuntu-latest
3935
arch: x86
36+
- version: 1
37+
os: macOS-latest
38+
arch: x64
39+
- version: 1
40+
os: windows-latest
41+
arch: x64
4042
steps:
4143
- uses: actions/checkout@v2
4244
- uses: julia-actions/setup-julia@latest
@@ -55,11 +57,13 @@ jobs:
5557
${{ runner.os }}-test-
5658
${{ runner.os }}-
5759
- uses: julia-actions/julia-buildpkg@latest
58-
env:
59-
PYTHON: 'Conda'
6060
- uses: julia-actions/julia-runtest@latest
61+
with:
62+
coverage: ${{ matrix.version == '1' && matrix.os == 'ubuntu-latest' && matrix.arch == 'x64' }}
6163
- uses: julia-actions/julia-processcoverage@v1
64+
if: matrix.version == '1' && matrix.os == 'ubuntu-latest' && matrix.arch == 'x64'
6265
- uses: codecov/codecov-action@v1
66+
if: matrix.version == '1' && matrix.os == 'ubuntu-latest' && matrix.arch == 'x64'
6367
with:
6468
file: lcov.info
6569
docs:
@@ -82,8 +86,6 @@ jobs:
8286
${{ runner.os }}-test-
8387
${{ runner.os }}-
8488
- uses: julia-actions/julia-buildpkg@latest
85-
env:
86-
PYTHON: 'Conda'
8789
- uses: julia-actions/julia-docdeploy@latest
8890
env:
8991
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ version = "0.1.0"
88
julia = "1"
99

1010
[extras]
11+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1112
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1213

1314
[targets]
14-
test = ["Test"]
15+
test = ["Documenter", "Test"]

docs/make.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
using Documenter
88
using InverseFunctions
99

10+
# Doctest setup
11+
DocMeta.setdocmeta!(
12+
InverseFunctions,
13+
:DocTestSetup,
14+
:(using InverseFunctions);
15+
recursive=true,
16+
)
17+
1018
makedocs(
1119
sitename = "InverseFunctions",
1220
modules = [InverseFunctions],

src/InverseFunctions.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# This file is a part of InverseFunctions.jl, licensed under the MIT License (MIT).
2-
3-
__precompile__(true)
4-
52
"""
63
InverseFunctions
74

src/inverse.jl

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,54 @@
11
# This file is a part of InverseFunctions.jl, licensed under the MIT License (MIT).
22

3-
43
"""
54
inverse(f)
65
7-
Returns the inverse of a function `f`.
6+
Return the inverse of function `f`.
7+
8+
`inverse` supports mapped and broadcasted functions (via `Base.Fix1`) and
9+
function composition (requires Julia >= 1.6).
10+
11+
# Examples
12+
13+
```jldoctest
14+
julia> foo(x) = inv(exp(-x) + 1);
15+
16+
julia> inv_foo(y) = log(y / (1 - y));
817
9-
The following conditions must be satisfied:
18+
julia> InverseFunctions.inverse(::typeof(foo)) = inv_foo;
1019
11-
* `inverse(f) ∘ f` must be equivalent to `identity`.
12-
* `inverse(f)(f(x)) ≈ x`
13-
* `inverse(inverse(f))` must be equivalent (ideally identical) to `f`.
20+
julia> InverseFunctions.inverse(::typeof(inv_foo)) = foo;
1421
15-
`inverse` supports mapped/broadcasted functions (via `Base.Fix1`) and (on
16-
Julia >=v1.6) function composition.
22+
julia> x = 4.2;
1723
24+
julia> inverse(foo)(foo(x)) ≈ x
25+
true
1826
19-
Example:
27+
julia> inverse(inverse(foo)) === foo
28+
true
2029
21-
```julia
22-
foo(x) = inv(exp(-x) + 1)
23-
inv_foo(y) = log(y / (1 - y))
30+
julia> broadcast_foo = Base.Fix1(broadcast, foo);
2431
25-
InverseFunctions.inverse(::typeof(foo)) = inv_foo
26-
InverseFunctions.inverse(::typeof(inv_foo)) = foo
32+
julia> X = rand(10);
2733
28-
x = 4.2
29-
@assert inverse(foo)(foo(x)) ≈ x
30-
@assert inverse(inverse(foo)) == foo
34+
julia> inverse(broadcast_foo)(broadcast_foo(X)) ≈ X
35+
true
3136
32-
X = rand(10)
33-
broadcasted_foo = Base.Fix1(broadcast, foo)
34-
Y = broadcasted_foo(X)
35-
@assert inverse(broadcasted_foo)(Y) ≈ X
37+
julia> bar = log ∘ foo;
3638
37-
# Requires Julia >= v1.6:
38-
bar = log ∘ foo
39-
@assert inverse(bar)(bar(x)) ≈ x
39+
julia> VERSION < v"1.6" || inverse(bar)(bar(x)) ≈ x
40+
true
4041
```
42+
43+
# Implementation
44+
45+
Implementations of `inverse(::typeof(f))` have to satisfy
46+
* `inverse(f)(f(x)) ≈ x` for all `x` in the domain of `f`, and
47+
* `inverse(inverse(f)) === f`.
4148
"""
42-
function inverse end
49+
inverse(f)
4350
export inverse
4451

45-
4652
inverse(::typeof(inverse)) = inverse
4753

4854
@static if VERSION >= v"1.6"
@@ -56,7 +62,6 @@ inverse(::typeof(inv)) = inv
5662
inverse(::typeof(adjoint)) = adjoint
5763
inverse(::typeof(transpose)) = transpose
5864

59-
6065
inverse(::typeof(exp)) = log
6166
inverse(::typeof(log)) = exp
6267

test/runtests.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# This file is a part of InverseFunctions.jl, licensed under the MIT License (MIT).
22

3-
import Test
3+
using InverseFunctions
4+
using Documenter
5+
using Test
46

5-
Test.@testset "Package InverseFunctions" begin
7+
@testset "Package InverseFunctions" begin
68
include("test_inverse.jl")
9+
10+
# doctests
11+
DocMeta.setdocmeta!(
12+
InverseFunctions,
13+
:DocTestSetup,
14+
:(using InverseFunctions);
15+
recursive=true,
16+
)
17+
doctest(InverseFunctions)
718
end # testset

test/test_inverse.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# This file is a part of InverseFunctions.jl, licensed under the MIT License (MIT).
22

3-
using InverseFunctions
4-
using Test
5-
6-
73
foo(x) = inv(exp(-x) + 1)
84
inv_foo(y) = log(y / (1 - y))
95

0 commit comments

Comments
 (0)