Skip to content

Commit 6bbc63b

Browse files
committed
[AutoDiff upstream] Add the _Differentiable protocol.
The `_Differentiable` protocol generalizes all types that work with differentiation. It is a core piece of the differentiable programming project. Other parts depending on the `_Differentiable` protocol (e.g. attribute type-checking) will be upstreamed later.
1 parent dbddb0d commit 6bbc63b

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ set(SWIFTLIB_SOURCES
204204
Availability.swift
205205
CollectionDifference.swift
206206
CollectionOfOne.swift
207+
Differentiable.swift
207208
Diffing.swift
208209
Mirror.swift
209210
PlaygroundDisplay.swift
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===--- Differentiable.swift ---------------------------------*- swift -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines the _Differentiable protocol, used by the experimental
14+
// differentiable programming project. This API is not stable and subject to
15+
// change.
16+
//
17+
// Please see forum discussion for more information about the differentiable
18+
// programming project:
19+
// https://forums.swift.org/t/differentiable-programming-mega-proposal/28547
20+
//
21+
//===----------------------------------------------------------------------===//
22+
23+
/// A type that mathematically represents a differentiable manifold whose
24+
/// tangent spaces are finite-dimensional.
25+
public protocol _Differentiable {
26+
/// A type representing a differentiable value's derivatives.
27+
///
28+
/// Mathematically, this is equivalent to the tangent bundle of the
29+
/// differentiable manifold represented by the differentiable type.
30+
associatedtype TangentVector: _Differentiable & AdditiveArithmetic
31+
where TangentVector.TangentVector == TangentVector
32+
33+
/// Moves `self` along the given direction. In Riemannian geometry, this is
34+
/// equivalent to exponential map, which moves `self` on the geodesic surface
35+
/// along the given tangent vector.
36+
mutating func move(along direction: TangentVector)
37+
}
38+
39+
public extension _Differentiable where TangentVector == Self {
40+
@_alwaysEmitIntoClient
41+
mutating func move(along direction: TangentVector) {
42+
self += direction
43+
}
44+
}

stdlib/public/core/GroupInfo.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,8 @@
227227
],
228228
"Result": [
229229
"Result.swift"
230+
],
231+
"DifferentiableProgramming": [
232+
"Differentiable.swift"
230233
]
231234
}

0 commit comments

Comments
 (0)