Skip to content

Commit c6d3914

Browse files
committed
Add inverse of sqrt
1 parent 3f803b7 commit c6d3914

File tree

8 files changed

+32
-2
lines changed

8 files changed

+32
-2
lines changed

docs/src/api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ inverse
1111
```@docs
1212
InverseFunctions.test_inverse
1313
```
14+
15+
## Additional functions
16+
17+
```@docs
18+
InverseFunctions.square
19+
```

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ This package defines the function [`inverse`](@ref). `inverse(f)` returns the in
88

99
`inverse` supports mapped/broadcasted functions (via `Base.Fix1`) and (on Julia >=v1.6) function composition.
1010

11-
Implementations of `inverse(f)` for `identity`, `inv`, `adjoint` and `transpose` as well as for `exp`, `log`, `exp2`, `log2`, `exp10`, `log10`, `expm1` and `log1p` are included.
11+
Implementations of `inverse(f)` for `identity`, `inv`, `adjoint` and `transpose` as well as for `exp`, `log`, `exp2`, `log2`, `exp10`, `log10`, `expm1`, `log1p` and `sqrt` are included.

src/InverseFunctions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module InverseFunctions
88

99
using Test
1010

11+
include("functions.jl")
1112
include("inverse.jl")
1213
include("test.jl")
1314

src/functions.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file is a part of InverseFunctions.jl, licensed under the MIT License (MIT).
2+
3+
"""
4+
square(x)
5+
6+
Inverse of `sqrt(x)`.
7+
"""
8+
square(x) = x^2

src/inverse.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ inverse(::typeof(log10)) = exp10
7676

7777
inverse(::typeof(expm1)) = log1p
7878
inverse(::typeof(log1p)) = expm1
79+
80+
inverse(::typeof(sqrt)) = square
81+
inverse(::typeof(square)) = sqrt

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import InverseFunctions
55
import Documenter
66

77
Test.@testset "Package InverseFunctions" begin
8+
include("test_functions.jl")
89
include("test_inverse.jl")
910

1011
# doctests

test/test_functions.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is a part of InverseFunctions.jl, licensed under the MIT License (MIT).
2+
3+
using Test
4+
using InverseFunctions
5+
6+
7+
@testset "square" begin
8+
for x in (-0.72, 0.73, randn(3, 3))
9+
@test InverseFunctions.square(x) x * x
10+
end
11+
end

test/test_inverse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ InverseFunctions.inverse(f) = Bar(inv(f.A))
2323
InverseFunctions.test_inverse(inverse, log, compare = ===)
2424

2525
x = rand()
26-
for f in (foo, inv_foo, exp, log, exp2, log2, exp10, log10, expm1, log1p)
26+
for f in (foo, inv_foo, exp, log, exp2, log2, exp10, log10, expm1, log1p, sqrt)
2727
InverseFunctions.test_inverse(f, x)
2828
end
2929

0 commit comments

Comments
 (0)