Skip to content

Commit fd40488

Browse files
committed
Fix indents
1 parent 0597f61 commit fd40488

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

docs/src/design/changing_the_primal.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ x̄ = pullback_at(f, x, y, ȳ, intermediates)
148148
```
149149
```julia
150150
function augmented_primal(::typeof(sin), x)
151-
y, cx = sincos(x)
152-
return y, (; cx=cx) # use a NamedTuple for the intermediates
151+
y, cx = sincos(x)
152+
return y, (; cx=cx) # use a NamedTuple for the intermediates
153153
end
154154

155155
pullback_at(::typeof(sin), x, y, ȳ, intermediates) = ȳ * intermediates.cx
@@ -163,9 +163,9 @@ pullback_at(::typeof(sin), x, y, ȳ, intermediates) = ȳ * intermediates.cx
163163
```
164164
```julia
165165
function augmented_primal(::typeof(σ), x)
166-
ex = exp(x)
167-
y = ex / (1 + ex)
168-
return y, (; ex=ex) # use a NamedTuple for the intermediates
166+
ex = exp(x)
167+
y = ex / (1 + ex)
168+
return y, (; ex=ex) # use a NamedTuple for the intermediates
169169
end
170170

171171
pullback_at(::typeof(σ), x, y, ȳ, intermediates) = ȳ * y / (1 + intermediates.ex)
@@ -189,8 +189,8 @@ And storing all these things on the tape — inputs, outputs, sensitivities, int
189189
What if we generalized the idea of the `intermediate` named tuple, and had `augmented_primal` return a struct that just held anything we might want put on the tape.
190190
```julia
191191
struct PullbackMemory{P, S}
192-
primal_function::P
193-
state::S
192+
primal_function::P
193+
state::S
194194
end
195195
# convenience constructor:
196196
PullbackMemory(primal_function; state...) = PullbackMemory(primal_function, state)
@@ -211,8 +211,8 @@ which is much cleaner.
211211
```
212212
```julia
213213
function augmented_primal(::typeof(sin), x)
214-
y, cx = sincos(x)
215-
return y, PullbackMemory(sin; cx=cx)
214+
y, cx = sincos(x)
215+
return y, PullbackMemory(sin; cx=cx)
216216
end
217217

218218
pullback_at(pb::PullbackMemory{typeof(sin)}, ȳ) = ȳ * pb.cx
@@ -226,9 +226,9 @@ pullback_at(pb::PullbackMemory{typeof(sin)}, ȳ) = ȳ * pb.cx
226226
```
227227
```julia
228228
function augmented_primal(::typeof(σ), x)
229-
ex = exp(x)
230-
y = ex / (1 + ex)
231-
return y, PullbackMemory(σ; y=y, ex=ex)
229+
ex = exp(x)
230+
y = ex / (1 + ex)
231+
return y, PullbackMemory(σ; y=y, ex=ex)
232232
end
233233

234234
pullback_at(pb::PullbackMemory{typeof(σ)}, ȳ) = ȳ * pb.y / (1 + pb.ex)
@@ -256,8 +256,8 @@ x̄ = pb(ȳ)
256256
```
257257
```julia
258258
function augmented_primal(::typeof(sin), x)
259-
y, cx = sincos(x)
260-
return y, PullbackMemory(sin; cx=cx)
259+
y, cx = sincos(x)
260+
return y, PullbackMemory(sin; cx=cx)
261261
end
262262
(pb::PullbackMemory{typeof(sin)})(ȳ) = ȳ * pb.cx
263263
```
@@ -271,9 +271,9 @@ end
271271
```
272272
```julia
273273
function augmented_primal(::typeof(σ), x)
274-
ex = exp(x)
275-
y = ex / (1 + ex)
276-
return y, PullbackMemory(σ; y=y, ex=ex)
274+
ex = exp(x)
275+
y = ex / (1 + ex)
276+
return y, PullbackMemory(σ; y=y, ex=ex)
277277
end
278278

279279
(pb::PullbackMemory{typeof(σ)})(ȳ) = ȳ * pb.y / (1 + pb.ex)
@@ -295,16 +295,16 @@ Let's go back and think about the changes we would have make to go from our orig
295295
To rewrite that original formulation in the new pullback form we have:
296296
```julia
297297
function augmented_primal(::typeof(sin), x)
298-
y = sin(x)
299-
return y, PullbackMemory(sin; x=x)
298+
y = sin(x)
299+
return y, PullbackMemory(sin; x=x)
300300
end
301301
(pb::PullbackMemory)(ȳ) = ȳ * cos(pb.x)
302302
```
303303
To go from that to:
304304
```julia
305305
function augmented_primal(::typeof(sin), x)
306-
y, cx = sincos(x)
307-
return y, PullbackMemory(sin; cx=cx)
306+
y, cx = sincos(x)
307+
return y, PullbackMemory(sin; cx=cx)
308308
end
309309
(pb::PullbackMemory)(ȳ) = ȳ * pb.cx
310310
```
@@ -317,17 +317,17 @@ end
317317
```
318318
```julia
319319
function augmented_primal(::typeof(σ), x)
320-
y = σ(x)
321-
return y, PullbackMemory(σ; y=y, x=x)
320+
y = σ(x)
321+
return y, PullbackMemory(σ; y=y, x=x)
322322
end
323323
(pb::PullbackMemory{typeof(σ)})(ȳ) = ȳ * pb.y * σ(-pb.x)
324324
```
325325
to get to:
326326
```julia
327327
function augmented_primal(::typeof(σ), x)
328-
ex = exp(x)
329-
y = ex/(1 + ex)
330-
return y, PullbackMemory(σ; y=y, ex=ex)
328+
ex = exp(x)
329+
y = ex/(1 + ex)
330+
return y, PullbackMemory(σ; y=y, ex=ex)
331331
end
332332
(pb::PullbackMemory{typeof(σ)})(ȳ) = ȳ * pb.y/(1 + pb.ex)
333333
```
@@ -356,9 +356,9 @@ Replacing `PullbackMemory` with a closure that works the same way lets us avoid
356356
```
357357
```julia
358358
function augmented_primal(::typeof(sin), x)
359-
y, cx = sincos(x)
360-
pb = ȳ -> cx * ȳ # pullback closure. closes over `cx`
361-
return y, pb
359+
y, cx = sincos(x)
360+
pb = ȳ -> cx * ȳ # pullback closure. closes over `cx`
361+
return y, pb
362362
end
363363
```
364364
```@raw html
@@ -370,10 +370,10 @@ end
370370
```
371371
```julia
372372
function augmented_primal(::typeof(σ), x)
373-
ex = exp(x)
374-
y = ex / (1 + ex)
375-
pb = ȳ -> ȳ * y / (1 + ex) # pullback closure. closes over `y` and `ex`
376-
return y, pb
373+
ex = exp(x)
374+
y = ex / (1 + ex)
375+
pb = ȳ -> ȳ * y / (1 + ex) # pullback closure. closes over `y` and `ex`
376+
return y, pb
377377
end
378378
```
379379
```@raw html

src/rule_definition_tools.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ end
124124
_normalize_scalarrules_macro_input(call, maybe_setup, partials)
125125
126126
returns (in order) the correctly escaped:
127-
- `call` with out any type constraints
128-
- `setup_stmts`: the content of `@setup` or `[]` if that is not provided,
129-
- `inputs`: with all args having the constraints removed from call, or
130-
defaulting to `Number`
131-
- `partials`: which are all `Expr{:tuple,...}`
127+
- `call` with out any type constraints
128+
- `setup_stmts`: the content of `@setup` or `[]` if that is not provided,
129+
- `inputs`: with all args having the constraints removed from call, or
130+
defaulting to `Number`
131+
- `partials`: which are all `Expr{:tuple,...}`
132132
"""
133133
function _normalize_scalarrules_macro_input(call, maybe_setup, partials)
134134
# Setup: normalizing input form etc
@@ -286,7 +286,7 @@ Returns the expression for the propagation of
286286
the input gradient `Δs` though the partials `∂s`.
287287
Specify `_conj = true` to conjugate the partials.
288288
Projector `proj` is a function that will be applied at the end;
289-
for `rrules` it is usually a `ProjectTo(x)`, for `frules` it is `identity`
289+
for `rrules` it is usually a `ProjectTo(x)`, for `frules` it is `identity`
290290
"""
291291
function propagation_expr(Δs, ∂s, _conj=false, proj=identity)
292292
# This is basically Δs ⋅ ∂s

src/rules.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ note: when the text below says methods `==` it actually means:
169169
170170
To decide if should opt-out using this mechanism.
171171
- find the most specific method of `rrule` and `no_rule` e.g with `Base.which`
172-
- if the method of `no_rrule` `==` the method of `rrule`, then should opt-out
172+
- if the method of `no_rrule` `==` the method of `rrule`, then should opt-out
173173
174174
To just ignore the fact that rules can be opted-out from, and that some rules thus return
175175
`nothing`, then filter the list of methods of `rrule` to remove those that are `==` to ones

0 commit comments

Comments
 (0)