You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/index.md
+16-8Lines changed: 16 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ For information about ChainRules, including how to write rules, refer to the gen
12
12
## Canonical example
13
13
14
14
Let's suppose a custom transformation has been defined
15
-
```jldoctest ex; output = false
15
+
```jldoctest ex
16
16
function two2three(x1::Float64, x2::Float64)
17
17
return 1.0, 2.0*x1, 3.0*x2
18
18
end
@@ -21,7 +21,7 @@ end
21
21
two2three (generic function with 1 method)
22
22
```
23
23
along with the `frule`
24
-
```jldoctest ex; output = false
24
+
```jldoctest ex
25
25
using ChainRulesCore
26
26
27
27
function ChainRulesCore.frule((Δf, Δx1, Δx2), ::typeof(two2three), x1, x2)
@@ -33,7 +33,7 @@ end
33
33
34
34
```
35
35
and `rrule`
36
-
```jldoctest ex; output = false
36
+
```jldoctest ex
37
37
function ChainRulesCore.rrule(::typeof(two2three), x1, x2)
38
38
y = two2three(x1, x2)
39
39
function two2three_pullback(Ȳ)
@@ -55,10 +55,12 @@ They can be used for any type and number of inputs and outputs.
55
55
The call will test the `frule` for function `f` at the point `x` in the domain.
56
56
Keep this in mind when testing discontinuous rules for functions like [ReLU](https://en.wikipedia.org/wiki/Rectifier_(neural_networks)), which should ideally be tested at both `x` being above and below zero.
[`test_rrule`](@ref) takes in the function `f`, and primal inputsr `x`.
68
70
The call will test the `rrule` for function `f` at the point `x`, and similarly to `frule` some rules should be tested at multiple points in the domain.
69
71
70
-
```jldoctest ex; output = false
72
+
```jldoctest ex
71
73
julia> test_rrule(two2three, 3.33, -7.77);
74
+
Test Summary: | Pass Total
75
+
test_rrule: two2three on Float64,Float64 | 8 8
72
76
73
77
```
74
78
75
79
## Scalar example
76
80
77
81
For functions with a single argument and a single output, such as e.g. ReLU,
78
-
```jldoctest ex; output = false
82
+
```jldoctest ex
79
83
function relu(x::Real)
80
84
return max(0, x)
81
85
end
@@ -84,7 +88,7 @@ end
84
88
relu (generic function with 1 method)
85
89
```
86
90
with the `frule` and `rrule` defined with the help of `@scalar_rule` macro
87
-
```jldoctest ex; output = false
91
+
```jldoctest ex
88
92
@scalar_rule relu(x::Real) x <= 0 ? zero(x) : one(x)
89
93
90
94
# output
@@ -93,11 +97,15 @@ with the `frule` and `rrule` defined with the help of `@scalar_rule` macro
93
97
94
98
`test_scalar` function is provided to test both the `frule` and the `rrule` with a single
0 commit comments