File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
``` @docs
6
6
inverse
7
+ NoInverse
7
8
```
8
9
9
10
## Test utility
Original file line number Diff line number Diff line change @@ -52,6 +52,27 @@ You can check your implementation with [`InverseFunctions.test_inverse`](@ref).
52
52
inverse (f)
53
53
export inverse
54
54
55
+
56
+
57
+ """
58
+ struct NoInverse{F}
59
+
60
+ An instance `NoInverse(f)` signifies that that `inverse(f)` is not
61
+ defined.
62
+ """
63
+ struct NoInverse{F}
64
+ f:: F
65
+ end
66
+ export NoInverse
67
+
68
+ (f:: NoInverse )(x) = error (" inverse of " , f. f, " is not defined" )
69
+
70
+ inverse (f) = NoInverse (f)
71
+
72
+ inverse (f:: NoInverse ) = f. f
73
+
74
+
75
+
55
76
inverse (:: typeof (inverse)) = inverse
56
77
57
78
@static if VERSION >= v " 1.6"
Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ InverseFunctions.inverse(f::Bar) = Bar(inv(f.A))
20
20
21
21
22
22
@testset " inverse" begin
23
+ f_without_inverse (x) = x^ 2
24
+ @test inverse (f_without_inverse) isa NoInverse
25
+ @test_throws ErrorException inverse (f_without_inverse)(42 )
26
+ @test inverse (inverse (f_without_inverse)) === f_without_inverse
27
+
28
+
23
29
InverseFunctions. test_inverse (inverse, log, compare = === )
24
30
25
31
x = rand ()
You can’t perform that action at this time.
0 commit comments