Skip to content

Commit b5912e8

Browse files
committed
Add missing 'T == T.TangentVector' requirement.
1 parent 893dd36 commit b5912e8

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

docs/DifferentiableProgramming.md

+35-17
Original file line numberDiff line numberDiff line change
@@ -1548,22 +1548,26 @@ language, but the developers of the differentiable programming feature will
15481548
prototype and pitch this change through Swift Evolution._
15491549

15501550
```swift
1551-
func foo<T: Differentiable & AdditiveArithmetic>(_ x: T, _ y: T, _ z: T) -> T { ... }
1551+
func foo<T: Differentiable & AdditiveArithmetic>(_ x: T, _ y: T, _ z: T) -> T
1552+
where T == T.TangentVector { ... }
15521553

15531554
// Transpose with respect to all parameters, making `foo(_:_:_:)` linear with
15541555
// with respect to all parameters.
15551556
@transpose(of: foo)
1556-
func _<T: Differentiable & AdditiveArithmetic>(_ v: T) -> (x: T, y: T, z: T) { ... }
1557+
func _<T: Differentiable & AdditiveArithmetic>(_ v: T) -> (x: T, y: T, z: T)
1558+
where T == T.TangentVector { ... }
15571559

15581560
// Transpose with respect to original parameter `x`, making `foo(_:_:_:)`
15591561
// linear with respect to `x`.
15601562
@transpose(of: foo, wrt: 0)
1561-
func _<T: Differentiable & AdditiveArithmetic>(y: T, z: T, v: T) -> T { ... }
1563+
func _<T: Differentiable & AdditiveArithmetic>(y: T, z: T, v: T) -> T
1564+
where T == T.TangentVector { ... }
15621565

15631566
// Transpose with respect to original parameters `x` and `z`, making
15641567
// `foo(_:_:_:)` linear with respect to `x` and `z`.
15651568
@transpose(of: foo, wrt: (0, 2))
1566-
func _<T: Differentiable & AdditiveArithmetic>(y: T, v: T) -> (x: T, z: T) { ... }
1569+
func _<T: Differentiable & AdditiveArithmetic>(y: T, v: T) -> (x: T, z: T)
1570+
where T == T.TangentVector { ... }
15671571
```
15681572

15691573
###### Static methods
@@ -1575,24 +1579,28 @@ parameter cannot be a linearity parameter, because metatypes cannot conform to
15751579

15761580
```swift
15771581
extension MyType {
1578-
static func foo<T: Differentiable & AdditiveArithmetic>(_ x: T, _ y: T, _ z: T) -> T { ... }
1582+
static func foo<T: Differentiable & AdditiveArithmetic>(_ x: T, _ y: T, _ z: T) -> T
1583+
where T == T.TangentVector { ... }
15791584
}
15801585

15811586
extension MyType {
15821587
// Transpose with respect to all parameters, making `foo(_:_:_:)` linear with
15831588
// with respect to all parameters.
15841589
@transpose(of: foo)
1585-
static func _<T: Differentiable & AdditiveArithmetic>(_ v: T) -> (x: T, y: T, z: T) { ... }
1590+
static func _<T: Differentiable & AdditiveArithmetic>(_ v: T) -> (x: T, y: T, z: T)
1591+
where T == T.TangentVector { ... }
15861592

15871593
// Transpose with respect to original parameter `x`, making `foo(_:_:_:)`
15881594
// linear with respect to `x`.
15891595
@transpose(of: foo, wrt: 0)
1590-
static func _<T: Differentiable & AdditiveArithmetic>(y: T, z: T, v: T) -> T { ... }
1596+
static func _<T: Differentiable & AdditiveArithmetic>(y: T, z: T, v: T) -> T
1597+
where T == T.TangentVector { ... }
15911598

15921599
// Transpose with respect to original parameters `x` and `z`, making
15931600
// `foo(_:_:_:)` linear with respect to `x` and `z`.
15941601
@transpose(of: foo, wrt: (0, 2))
1595-
static func _<T: Differentiable & AdditiveArithmetic>(y: T, v: T) -> (x: T, z: T) { ... }
1602+
static func _<T: Differentiable & AdditiveArithmetic>(y: T, v: T) -> (x: T, z: T)
1603+
where T == T.TangentVector { ... }
15961604
}
15971605
```
15981606

@@ -1605,7 +1613,9 @@ respect to each parameter). Here's how they are made differentiable in the
16051613
standard library.
16061614

16071615
```swift
1608-
extension FloatingPoint where Self: Differentiable & AdditiveArithmetic {
1616+
extension FloatingPoint
1617+
where Self: Differentiable & AdditiveArithmetic, Self == TangentVector
1618+
{
16091619
@transpose(of: +)
16101620
static func _(_ v: Self) -> (Self, Self) { (v, v) }
16111621

@@ -1657,34 +1667,40 @@ A transpose of a static method is exactly like top-level functions except:
16571667

16581668
```swift
16591669
extension MyType {
1660-
func foo<T: Differentiable & AdditiveArithmetic>(_ x: T, _ y: T, _ z: T) -> T { ... }
1670+
func foo<T: Differentiable & AdditiveArithmetic>(_ x: T, _ y: T, _ z: T) -> T
1671+
where T == T.TangentVector { ... }
16611672
}
16621673

16631674
extension MyType {
16641675
// Transpose with respect to all parameters, making `foo(_:_:_:)` linear with
16651676
// with respect to all parameters.
16661677
@transpose(of: foo)
1667-
func _<T: Differentiable & AdditiveArithmetic>(_ v: T) -> (x: T, y: T, z: T) { ... }
1678+
func _<T: Differentiable & AdditiveArithmetic>(_ v: T) -> (x: T, y: T, z: T)
1679+
where T == T.TangentVector { ... }
16681680

16691681
// Transpose with respect to original parameter `x`, making `foo(_:_:_:)`
16701682
// linear with respect to `x`.
16711683
@transpose(of: foo, wrt: 0)
1672-
func _<T: Differentiable & AdditiveArithmetic>(y: T, z: T, v: T) -> T { ... }
1684+
func _<T: Differentiable & AdditiveArithmetic>(y: T, z: T, v: T) -> T
1685+
where T == T.TangentVector { ... }
16731686

16741687
// Transpose with respect to original parameters `x` and `z`, making
16751688
// `foo(_:_:_:)` linear with respect to `x` and `z`.
16761689
@transpose(of: foo, wrt: (0, 2))
1677-
func _<T: Differentiable & AdditiveArithmetic>(y: T, v: T) -> (x: T, z: T) { ... }
1690+
func _<T: Differentiable & AdditiveArithmetic>(y: T, v: T) -> (x: T, z: T)
1691+
where T == T.TangentVector { ... }
16781692

16791693
// Transpose with respect to original parameters `self`, making `foo(_:_:_:)`
16801694
// linear with respect to `self`.
16811695
@transpose(of: foo, wrt: self)
1682-
static func _<T: Differentiable & AdditiveArithmetic>(x: T, y: T, z: T, v: T) -> MyType { ... }
1696+
static func _<T: Differentiable & AdditiveArithmetic>(x: T, y: T, z: T, v: T) -> MyType
1697+
where T == T.TangentVector { ... }
16831698

16841699
// Transpose with respect to original parameters `self`, `x` and `z`, making
16851700
// `foo(_:_:_:)` linear with respect to `self`, `x` and `z`.
16861701
@transpose(of: foo, wrt: (self, 0, 2))
1687-
static func _<T: Differentiable & AdditiveArithmetic>(y: T, v: T) -> (self: MyType, x: T, z: T) { ... }
1702+
static func _<T: Differentiable & AdditiveArithmetic>(y: T, v: T) -> (self: MyType, x: T, z: T)
1703+
where T == T.TangentVector { ... }
16881704
}
16891705
```
16901706

@@ -1702,13 +1718,15 @@ in `@differentiable` attributes.
17021718
func foo<T, U, V>(_ x: T, _ y: U, _ z: V) -> W { ... }
17031719

17041720
// Transpose with respect to `x` and `z`, requiring that `T` and `V` to conform
1705-
// to `Differentiable & AdditiveArithmetic`.
1721+
// to `Differentiable & AdditiveArithmetic` and equal their corresponding
1722+
`TangentVector` types.
17061723
@transpose(of: foo, wrt: (x, z))
17071724
func _<
17081725
T: Differentiable & AdditiveArithmetic,
17091726
U,
17101727
V: Differentiable & AdditiveArithmetic
17111728
>(_ y: U, _ v: W) -> (x: T, z: V)
1729+
where T.TangentVector == T, V.TangentVector == V { ... }
17121730
```
17131731

17141732
##### Examples
@@ -1717,7 +1735,7 @@ Many floating-point operations are linear. Addition and subtraction are linear.
17171735
Multiplication is bilinear (linear with respect to each argument).
17181736

17191737
```swift
1720-
extension FloatingPoint {
1738+
extension FloatingPoint where Self: Differentiable, Self == TangentVector {
17211739
@inlinable
17221740
@transpose(of: +)
17231741
func _(_ v: Self) -> (Self, Self) {

0 commit comments

Comments
 (0)