|
| 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 | +} |
0 commit comments