Skip to content

Commit 9ff7485

Browse files
authored
Merge pull request #28454 from apple/rename-differentiating-transposing
2 parents f555d6e + 7a9be4f commit 9ff7485

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

docs/DifferentiableProgramming.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Backticks were added manually.
4242
* [The `Differentiable` protocol](#the-differentiable-protocol)
4343
* [The `@differentiable` declaration attribute](#the-differentiable-declaration-attribute)
4444
* [`@differentiable` function types](#differentiable-function-types)
45-
* [`@differentiating` and `@transposing` attributes](#differentiating-and-transposing-attributes)
45+
* [`@derivative` and `@transpose` attributes](#derivative-and-transpose-attributes)
4646
* [Differential operators](#differential-operators)
4747
* [Detailed design](#detailed-design)
4848
* [Differentiable data structures](#differentiable-data-structures)
@@ -57,8 +57,8 @@ Backticks were added manually.
5757
* [Conformance and subclassing](#conformance-and-subclassing)
5858
* [Protocol dispatch](#protocol-dispatch)
5959
* [Class dispatch](#class-dispatch)
60-
* [Make a function differentiable using `@differentiating` or
61-
`@transposing`](#make-a-function-differentiable-using-differentiating-or-transposing)
60+
* [Make a function differentiable using `@derivative` or
61+
`@transpose`](#make-a-function-differentiable-using-derivative-or-transpose)
6262
* [Linear maps](#linear-maps)
6363
* [Examples](#examples)
6464
* [Derivative functions](#derivative-functions)
@@ -109,7 +109,7 @@ First-class differentiable programming includes five core additions:
109109
- `@differentiable` function types.
110110
- The `@differentiable` declaration attribute for defining differentiable
111111
functions.
112-
- The `@differentiating` and `@transposing` attributes for defining custom
112+
- The `@derivative` and `@transpose` attributes for defining custom
113113
derivatives.
114114
- Differential operators (e.g. `derivative(of:)`) in the standard library.
115115

@@ -893,15 +893,15 @@ let _: @differentiable (Float) -> Float = addOne
893893
let _: @differentiable(linear) (Float) -> Float = addOne
894894
```
895895

896-
### `@differentiating` and `@transposing` attributes
896+
### `@derivative` and `@transpose` attributes
897897

898-
`@differentiating` and `@transposing` attributes are used for declaring custom
898+
`@derivative` and `@transpose` attributes are used for declaring custom
899899
derivative functions for some other function declaration.
900900

901901
```swift
902902
import Glibc
903903

904-
@differentiating(expf)
904+
@derivative(of: expf)
905905
func _(_ x: Float) -> (value: Float,
906906
differential: @differentiable(linear) (Float) -> Float) {
907907
let y = expf(x)
@@ -1439,13 +1439,13 @@ class Subclass: Superclass {
14391439
}
14401440
```
14411441

1442-
### Make a function differentiable using `@differentiating` or `@transposing`
1442+
### Make a function differentiable using `@derivative` or `@transpose`
14431443

14441444
Any function that has `Differentiable`-conforming parameters and result can be
14451445
made differentiable by extending the function to have either an associated
1446-
derivative function or a linear transpose. The `@differentiating` attribute is
1446+
derivative function or a linear transpose. The `@derivative` attribute is
14471447
used for marking a function as producing a custom derivative for another
1448-
function, hence making the other function differentiable. The `@transposing`
1448+
function, hence making the other function differentiable. The `@transpose`
14491449
attribute is used for marking a function as transposing another function, hence
14501450
making the other function linear.
14511451

@@ -1473,9 +1473,9 @@ provided with a transpose (e.g. scalar multiplication, matrix transposition, and
14731473
matrix multiplication), because gradients can only be computed when the
14741474
differential can be transposed.
14751475

1476-
To make a function a linear map, use a `@transposing` attribute on the transpose
1476+
To make a function a linear map, use a `@transpose` attribute on the transpose
14771477
function. If the function is only linear with respect to certain parameters, use
1478-
a wrt: clause to indicate parameter positions, e.g. `@transposing(..., wrt:
1478+
a wrt: clause to indicate parameter positions, e.g. `@transpose(of: ..., wrt:
14791479
(self, 0))`.
14801480

14811481
The numeric addition operator
@@ -1494,11 +1494,11 @@ prototype and pitch this change through Swift Evolution._
14941494

14951495
```swift
14961496
extension FloatingPoint where Self: Differentiable & AdditiveArithmetic {
1497-
@transposing(+)
1497+
@transpose(of: +)
14981498
static func _(_ v: Self) -> (Self, Self) { (v, v) }
14991499

1500-
@transposing(*, wrt: 0)
1501-
@transposing(*, wrt: 1)
1500+
@transpose(of: *, wrt: 0)
1501+
@transpose(of: *, wrt: 1)
15021502
static func _(lhs: Self, rhs: Self) -> Self { lhs * rhs }
15031503
}
15041504
```
@@ -1518,18 +1518,18 @@ matrix multiplication function.
15181518

15191519
```swift
15201520
extension Tensor where Scalar: FloatingPoint & Differentiable {
1521-
@transposing(transposed, wrt: self)
1521+
@transpose(of: transposed, wrt: self)
15221522
func _() -> Tensor {
15231523
self.transposed()
15241524
}
15251525
}
15261526

1527-
@transposing(matmul(_:_:), wrt: 0)
1527+
@transpose(of: matmul(_:_:), wrt: 0)
15281528
func _<T: FloatingPoint & Differentiable>(y: Tensor<T>, v: Tensor<T>) -> Tensor<T> {
15291529
matmul(v, y.transposed())
15301530
}
15311531

1532-
@transposing(matmul(_:_:), wrt: 1)
1532+
@transpose(of: matmul(_:_:), wrt: 1)
15331533
func _<T: FloatingPoint & Differentiable>(x: Tensor<T>, v: Tensor<T>) -> Tensor<T> {
15341534
matmul(x.transposed(), v)
15351535
}
@@ -1543,20 +1543,20 @@ Multiplication is bilinear (linear with respect to each argument).
15431543
```swift
15441544
extension FloatingPoint {
15451545
@inlinable
1546-
@transposing(+)
1546+
@transpose(of: +)
15471547
func _(_ v: Self) -> (Self, Self) {
15481548
(v, v)
15491549
}
15501550

15511551
@inlinable
1552-
@transposing(-)
1552+
@transpose(of: -)
15531553
func _(_ v: Self) -> (Self, Self) {
15541554
(v, -v)
15551555
}
15561556

15571557
@inlinable
1558-
@transposing(*, wrt: 0)
1559-
@transposing(*, wrt: 1)
1558+
@transpose(of: *, wrt: 0)
1559+
@transpose(of: *, wrt: 1)
15601560
func _(_ x: Self, _ v: Self) -> Self {
15611561
return x * v
15621562
}
@@ -1610,8 +1610,8 @@ on `SIMD`.
16101610

16111611
```swift
16121612
extension SIMD where Self: Differentiable, TangentVector: SIMD, Scalar: BinaryFloatingPoint, Self == Self.TangentVector {
1613-
@transposing(*, wrt: 0)
1614-
@transposing(*, wrt: 1)
1613+
@transpose(of: *, wrt: 0)
1614+
@transpose(of: *, wrt: 1)
16151615
static func _(v: Self, x: Self) -> Self {
16161616
v * x
16171617
}
@@ -1633,7 +1633,7 @@ where Scalar: Differentiable & BinaryFloatingPoint,
16331633

16341634
// `subscript` is defined on `SIMD`-conforming types, so the transpose is as well.
16351635
extension SIMDScalar where Self: Differentiable & BinaryFloatingPoint {
1636-
@transposing(subscript)
1636+
@transpose(of: subscript)
16371637
func _(index: Int) -> SIMD${n}<Self> {
16381638
var result = SIMD${n}<Self>.zero
16391639
result[index] = self
@@ -1652,13 +1652,13 @@ on the `tensorflow` branch.
16521652

16531653
In the following example, the 32-bit floating point exponential function
16541654
[`expf(_:)`](https://en.cppreference.com/w/c/numeric/math/exp) is imported from
1655-
the C standard library. The derivative function marked with `@differentiating`
1655+
the C standard library. The derivative function marked with `@derivative`
16561656
makes `expf(_:)` a differentiable function.
16571657

16581658
```swift
16591659
import Glibc
16601660

1661-
@differentiating(expf)
1661+
@derivative(of: expf)
16621662
func _(_ x: Float) -> (value: Float,
16631663
differential: @differentiable(linear) (Float) -> Float) {
16641664
let y = expf(x)
@@ -1679,7 +1679,7 @@ flexibility and performance.
16791679
The `ElementaryFunctions` protocol introduced in
16801680
[SE-0246](https://github.com/apple/swift-evolution/blob/master/proposals/0246-mathable.md)
16811681
defines generic elementary functions, which are non-linear. By defining
1682-
derivatives using the `@differentiating` attribute for these protocol
1682+
derivatives using the `@derivative` attribute for these protocol
16831683
requirements in an extension, all conforming types now have differentiable
16841684
elementary functions.
16851685

@@ -1697,45 +1697,45 @@ public protocol ElementaryFunctions {
16971697

16981698
public extension ElementaryFunctions where Self: Differentiable, Self == Self.TangentVector {
16991699
@inlinable
1700-
@differentiating(sqrt)
1700+
@derivative(of: sqrt)
17011701
func _(_ x: Self) -> (value: Self, differential: @differential(linear) (Self) -> Self) {
17021702
(sqrt(x), { dx in (1 / 2) * (1 / sqrt(x)) * dx })
17031703
}
17041704

17051705
@inlinable
1706-
@differentiating(cos)
1706+
@derivative(of: cos)
17071707
func _(_ x: Self) -> (value: Self, differential: @differential(linear) (Self) -> Self) {
17081708
(cos(x), { dx in -sin(x) * dx })
17091709
}
17101710

17111711
@inlinable
1712-
@differentiating(asinh)
1712+
@derivative(of: asinh)
17131713
func _(_ x: Self) -> (value: Self, differential: @differential(linear) (Self) -> Self) {
17141714
(asinh(x), { dx in 1 / (1 + x * x) * dx })
17151715
}
17161716

17171717
@inlinable
1718-
@differentiating(exp)
1718+
@derivative(of: exp)
17191719
func _(_ x: Self) -> (value: Self, differential: @differential(linear) (Self) -> Self) {
17201720
let ret = exp(x)
17211721
return (ret, { dx in ret * dx })
17221722
}
17231723

17241724
@inlinable
1725-
@differentiating(exp10)
1725+
@derivative(of: exp10)
17261726
func _(_ x: Self) -> (value: Self, differential: @differential(linear) (Self) -> Self) {
17271727
let ret = exp10(x)
17281728
return (ret, { dx in exp(10) * ret * dx })
17291729
}
17301730

17311731
@inlinable
1732-
@differentiating(log)
1732+
@derivative(of: log)
17331733
func _(_ x: Self) -> (value: Self, differential: @differential(linear) (Self) -> Self) { dx in
17341734
(log(x), { 1 / x * dx })
17351735
}
17361736

17371737
@inlinable
1738-
@differentiating(pow)
1738+
@derivative(of: pow)
17391739
func _(_ x: Self, _ y: Self) -> (value: Self, differential: @differential(linear) (Self, Self) -> Self) {
17401740
(pow(x, y), { (dx, dy) in
17411741
let l = y * pow(x, y-1) * dx

0 commit comments

Comments
 (0)