@@ -42,7 +42,7 @@ Backticks were added manually.
42
42
* [ The ` Differentiable ` protocol] ( #the-differentiable-protocol )
43
43
* [ The ` @differentiable ` declaration attribute] ( #the-differentiable-declaration-attribute )
44
44
* [ ` @differentiable ` function types] ( #differentiable-function-types )
45
- * [ ` @differentiating ` and ` @transposing ` attributes] ( #differentiating -and-transposing -attributes )
45
+ * [ ` @derivative ` and ` @transpose ` attributes] ( #derivative -and-transpose -attributes )
46
46
* [ Differential operators] ( #differential-operators )
47
47
* [ Detailed design] ( #detailed-design )
48
48
* [ Differentiable data structures] ( #differentiable-data-structures )
@@ -57,8 +57,8 @@ Backticks were added manually.
57
57
* [ Conformance and subclassing] ( #conformance-and-subclassing )
58
58
* [ Protocol dispatch] ( #protocol-dispatch )
59
59
* [ 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 )
62
62
* [ Linear maps] ( #linear-maps )
63
63
* [ Examples] ( #examples )
64
64
* [ Derivative functions] ( #derivative-functions )
@@ -109,7 +109,7 @@ First-class differentiable programming includes five core additions:
109
109
- ` @differentiable ` function types.
110
110
- The ` @differentiable ` declaration attribute for defining differentiable
111
111
functions.
112
- - The ` @differentiating ` and ` @transposing ` attributes for defining custom
112
+ - The ` @derivative ` and ` @transpose ` attributes for defining custom
113
113
derivatives.
114
114
- Differential operators (e.g. ` derivative(of:) ` ) in the standard library.
115
115
@@ -893,15 +893,15 @@ let _: @differentiable (Float) -> Float = addOne
893
893
let _: @differentiable (linear) (Float ) -> Float = addOne
894
894
```
895
895
896
- ### ` @differentiating ` and ` @transposing ` attributes
896
+ ### ` @derivative ` and ` @transpose ` attributes
897
897
898
- ` @differentiating ` and ` @transposing ` attributes are used for declaring custom
898
+ ` @derivative ` and ` @transpose ` attributes are used for declaring custom
899
899
derivative functions for some other function declaration.
900
900
901
901
``` swift
902
902
import Glibc
903
903
904
- @differentiating ( expf)
904
+ @derivative (of : expf)
905
905
func _ (_ x : Float ) -> (value: Float ,
906
906
differential: @differentiable (linear) (Float ) -> Float ) {
907
907
let y = expf (x)
@@ -1439,13 +1439,13 @@ class Subclass: Superclass {
1439
1439
}
1440
1440
```
1441
1441
1442
- ### Make a function differentiable using ` @differentiating ` or ` @transposing `
1442
+ ### Make a function differentiable using ` @derivative ` or ` @transpose `
1443
1443
1444
1444
Any function that has ` Differentiable ` -conforming parameters and result can be
1445
1445
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
1447
1447
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 `
1449
1449
attribute is used for marking a function as transposing another function, hence
1450
1450
making the other function linear.
1451
1451
@@ -1473,9 +1473,9 @@ provided with a transpose (e.g. scalar multiplication, matrix transposition, and
1473
1473
matrix multiplication), because gradients can only be computed when the
1474
1474
differential can be transposed.
1475
1475
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
1477
1477
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:
1479
1479
(self, 0))`.
1480
1480
1481
1481
The numeric addition operator
@@ -1494,11 +1494,11 @@ prototype and pitch this change through Swift Evolution._
1494
1494
1495
1495
``` swift
1496
1496
extension FloatingPoint where Self : Differentiable & AdditiveArithmetic {
1497
- @transposing ( + )
1497
+ @transpose (of : + )
1498
1498
static func _ (_ v : Self ) -> (Self , Self ) { (v, v) }
1499
1499
1500
- @transposing ( * , wrt: 0 )
1501
- @transposing ( * , wrt: 1 )
1500
+ @transpose (of : * , wrt: 0 )
1501
+ @transpose (of : * , wrt: 1 )
1502
1502
static func _ (lhs : Self , rhs : Self ) -> Self { lhs * rhs }
1503
1503
}
1504
1504
```
@@ -1518,18 +1518,18 @@ matrix multiplication function.
1518
1518
1519
1519
``` swift
1520
1520
extension Tensor where Scalar: FloatingPoint & Differentiable {
1521
- @transposing ( transposed, wrt: self )
1521
+ @transpose (of : transposed, wrt: self )
1522
1522
func _ () -> Tensor {
1523
1523
self .transposed ()
1524
1524
}
1525
1525
}
1526
1526
1527
- @transposing ( matmul (_:_:), wrt: 0 )
1527
+ @transpose (of : matmul (_:_:), wrt: 0 )
1528
1528
func _ <T : FloatingPoint & Differentiable >(y : Tensor<T>, v : Tensor<T>) -> Tensor<T> {
1529
1529
matmul (v, y.transposed ())
1530
1530
}
1531
1531
1532
- @transposing ( matmul (_:_:), wrt: 1 )
1532
+ @transpose (of : matmul (_:_:), wrt: 1 )
1533
1533
func _ <T : FloatingPoint & Differentiable >(x : Tensor<T>, v : Tensor<T>) -> Tensor<T> {
1534
1534
matmul (x.transposed (), v)
1535
1535
}
@@ -1543,20 +1543,20 @@ Multiplication is bilinear (linear with respect to each argument).
1543
1543
``` swift
1544
1544
extension FloatingPoint {
1545
1545
@inlinable
1546
- @transposing ( + )
1546
+ @transpose (of : + )
1547
1547
func _ (_ v : Self ) -> (Self , Self ) {
1548
1548
(v, v)
1549
1549
}
1550
1550
1551
1551
@inlinable
1552
- @transposing ( - )
1552
+ @transpose (of : - )
1553
1553
func _ (_ v : Self ) -> (Self , Self ) {
1554
1554
(v, - v)
1555
1555
}
1556
1556
1557
1557
@inlinable
1558
- @transposing ( * , wrt: 0 )
1559
- @transposing ( * , wrt: 1 )
1558
+ @transpose (of : * , wrt: 0 )
1559
+ @transpose (of : * , wrt: 1 )
1560
1560
func _ (_ x : Self , _ v : Self ) -> Self {
1561
1561
return x * v
1562
1562
}
@@ -1610,8 +1610,8 @@ on `SIMD`.
1610
1610
1611
1611
``` swift
1612
1612
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 )
1615
1615
static func _ (v : Self , x : Self ) -> Self {
1616
1616
v * x
1617
1617
}
@@ -1633,7 +1633,7 @@ where Scalar: Differentiable & BinaryFloatingPoint,
1633
1633
1634
1634
// `subscript` is defined on `SIMD`-conforming types, so the transpose is as well.
1635
1635
extension SIMDScalar where Self : Differentiable & BinaryFloatingPoint {
1636
- @transposing ( subscript )
1636
+ @transpose (of : subscript )
1637
1637
func _ (index : Int ) -> SIMD${n}< Self > {
1638
1638
var result = SIMD${n}< Self > .zero
1639
1639
result[index] = self
@@ -1652,13 +1652,13 @@ on the `tensorflow` branch.
1652
1652
1653
1653
In the following example, the 32-bit floating point exponential function
1654
1654
[ ` 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 `
1656
1656
makes ` expf(_:) ` a differentiable function.
1657
1657
1658
1658
``` swift
1659
1659
import Glibc
1660
1660
1661
- @differentiating ( expf)
1661
+ @derivative (of : expf)
1662
1662
func _ (_ x : Float ) -> (value: Float ,
1663
1663
differential: @differentiable (linear) (Float ) -> Float ) {
1664
1664
let y = expf (x)
@@ -1679,7 +1679,7 @@ flexibility and performance.
1679
1679
The ` ElementaryFunctions ` protocol introduced in
1680
1680
[ SE-0246] ( https://github.com/apple/swift-evolution/blob/master/proposals/0246-mathable.md )
1681
1681
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
1683
1683
requirements in an extension, all conforming types now have differentiable
1684
1684
elementary functions.
1685
1685
@@ -1697,45 +1697,45 @@ public protocol ElementaryFunctions {
1697
1697
1698
1698
public extension ElementaryFunctions where Self : Differentiable , Self == Self .TangentVector {
1699
1699
@inlinable
1700
- @differentiating ( sqrt)
1700
+ @derivative (of : sqrt)
1701
1701
func _ (_ x : Self ) -> (value: Self , differential: @differential (linear) (Self ) -> Self ) {
1702
1702
(sqrt (x), { dx in (1 / 2 ) * (1 / sqrt (x)) * dx })
1703
1703
}
1704
1704
1705
1705
@inlinable
1706
- @differentiating ( cos)
1706
+ @derivative (of : cos)
1707
1707
func _ (_ x : Self ) -> (value: Self , differential: @differential (linear) (Self ) -> Self ) {
1708
1708
(cos (x), { dx in - sin (x) * dx })
1709
1709
}
1710
1710
1711
1711
@inlinable
1712
- @differentiating ( asinh)
1712
+ @derivative (of : asinh)
1713
1713
func _ (_ x : Self ) -> (value: Self , differential: @differential (linear) (Self ) -> Self ) {
1714
1714
(asinh (x), { dx in 1 / (1 + x * x) * dx })
1715
1715
}
1716
1716
1717
1717
@inlinable
1718
- @differentiating ( exp)
1718
+ @derivative (of : exp)
1719
1719
func _ (_ x : Self ) -> (value: Self , differential: @differential (linear) (Self ) -> Self ) {
1720
1720
let ret = exp (x)
1721
1721
return (ret, { dx in ret * dx })
1722
1722
}
1723
1723
1724
1724
@inlinable
1725
- @differentiating ( exp10)
1725
+ @derivative (of : exp10)
1726
1726
func _ (_ x : Self ) -> (value: Self , differential: @differential (linear) (Self ) -> Self ) {
1727
1727
let ret = exp10 (x)
1728
1728
return (ret, { dx in exp (10 ) * ret * dx })
1729
1729
}
1730
1730
1731
1731
@inlinable
1732
- @differentiating ( log)
1732
+ @derivative (of : log)
1733
1733
func _ (_ x : Self ) -> (value: Self , differential: @differential (linear) (Self ) -> Self ) { dx in
1734
1734
(log (x), { 1 / x * dx })
1735
1735
}
1736
1736
1737
1737
@inlinable
1738
- @differentiating ( pow)
1738
+ @derivative (of : pow)
1739
1739
func _ (_ x : Self , _ y : Self ) -> (value: Self , differential: @differential (linear) (Self , Self ) -> Self ) {
1740
1740
(pow (x, y), { (dx, dy) in
1741
1741
let l = y * pow (x, y- 1 ) * dx
0 commit comments