Skip to content

Commit 823b216

Browse files
authored
Merge pull request #28309 from apple/autodiff-doc-update
2 parents 7431c4e + 01b53db commit 823b216

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

docs/DifferentiableProgramming.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,15 +1827,12 @@ The `@differentiable` attribute requires the function type it is attached to
18271827
have differentiable parameters and results. Each parameter and result must
18281828
conform to the `Differentiable` protocol (or `Differentiable &
18291829
AdditiveArithmetic` when the attribute is `@differentiable(linear)`) unless it
1830-
is marked with `@nondiff`.
1830+
is marked with `@noDerivative`.
18311831

18321832
<p align="center">
18331833
<img src="assets/DifferentiableProgramming/differentiable-function-subtyping.png">
18341834
</p>
18351835

1836-
_Note: `@nondiff` stands for "not being differentiated", and will likely be
1837-
unified with `@noDerivative`._
1838-
18391836
#### Type conversion
18401837

18411838
The subtyping relation among `@differentiable(linear)`, `@differentiable`, and
@@ -1899,13 +1896,13 @@ let f2: (Float) -> Float = f1
18991896
```
19001897

19011898
A `@differentiable` function can also be converted to a function which is
1902-
identical except that more of its parameters are marked with `@nondiff`.
1899+
identical except that more of its parameters are marked with `@noDerivative`.
19031900

19041901
```swift
19051902
func addOne(_ x: Float) -> Float { x + 1 }
19061903
let f0: @differentiable (Float, Float, Float) -> Float = addOne
1907-
let f1: @differentiable (@nondiff Float, Float, Float) -> Float = f0
1908-
let f2: @differentiable (@nondiff Float, Float, @nondiff Float) -> Float = f1
1904+
let f1: @differentiable (@noDerivative Float, Float, Float) -> Float = f0
1905+
let f2: @differentiable (@noDerivative Float, Float, @noDerivative Float) -> Float = f1
19091906
```
19101907

19111908
#### Implied generic constraints
@@ -1975,33 +1972,33 @@ Neural network trainer objects that store loss functions, e.g.
19751972
Like function declarations with a `@differentiable` attribute, differentiable
19761973
function values can also be differentiable with respect to a subset of
19771974
parameters. This is expressed as part of type information, in `@differentiable`
1978-
and `@differentiable(linear)` function types, using a `@nondiff` attribute at
1975+
and `@differentiable(linear)` function types, using a `@noDerivative` attribute at
19791976
each parameter that is not being differentiated with respect to.
19801977

19811978
By default, all parameters are being differentiated with respect to. When a
1982-
`@nondiff` attribute is specified for a parameter in a `@differentiable`
1979+
`@noDerivative` attribute is specified for a parameter in a `@differentiable`
19831980
function type, values of this function type are not differentiable (or linear)
19841981
with respect to the parameter.
19851982

19861983
```swift
19871984
let f0: @differentiable (Float, Float) -> Float = { $0 * $1 }
19881985
let f1: @differentiable(linear) (Float, Float) -> Float = { $0 + $1 }
1989-
let f2: @differentiable(linear) (Float, @nondiff Float) -> Float = { $0 * $1 }
1990-
let f3: @differentiable (@nondiff Int, Float, @nondiff Int) -> Float = {
1986+
let f2: @differentiable(linear) (Float, @noDerivative Float) -> Float = { $0 * $1 }
1987+
let f3: @differentiable (@noDerivative Int, Float, @noDerivative Int) -> Float = {
19911988
$0 ? Float($1) + $2 : 0
19921989
}
19931990
```
19941991

19951992
Differentiability of parameters in a function type is important for type
19961993
conversions and is part of the subtyping rule: Any `@differentiable` or
19971994
`@differentiable(linear)` function type is a subtype of the same function type
1998-
with more `@nondiff` parameters than there originally are.
1995+
with more `@noDerivative` parameters than there originally are.
19991996

20001997
```swift
20011998
let f0: @differentiable (Float, Float) -> Float = { $0 * $1 }
2002-
_ = f0 as @differentiable (Float, @nondiff Float) -> Float
2003-
_ = f0 as @differentiable (@nondiff Float, Float) -> Float
2004-
_ = f0 as @differentiable (@nondiff Float, @nondiff Float) -> Float
1999+
_ = f0 as @differentiable (Float, @noDerivative Float) -> Float
2000+
_ = f0 as @differentiable (@noDerivative Float, Float) -> Float
2001+
_ = f0 as @differentiable (@noDerivative Float, @noDerivative Float) -> Float
20052002
```
20062003

20072004
### Differentiable operators

0 commit comments

Comments
 (0)