-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[AutoDiff] Underscore the Differentiable protocol.
#27577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dan-zheng
merged 5 commits into
swiftlang:tensorflow
from
dan-zheng:underscore-differentiable
Oct 9, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a18e9af
Underscore `Differentiable` protocol.
dan-zheng 3041554
Code reordering to match upstream changes.
dan-zheng 144c676
Update tests.
dan-zheng d80ae53
Merge branch 'tensorflow' of github.com:apple/swift into underscore-d…
dan-zheng a3743b7
Update remaining tests.
dan-zheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| //===--- Differentiable.swift ---------------------------------*- swift -*-===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See https://swift.org/LICENSE.txt for license information | ||
| // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the Differentiable protocol, used by the experimental | ||
| // differentiable programming project. Please see forum discussion for more | ||
| // information: | ||
| // https://forums.swift.org/t/differentiable-programming-mega-proposal/28547 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| /// A type that mathematically represents a differentiable manifold whose | ||
| /// tangent spaces are finite-dimensional. | ||
| public protocol _Differentiable { | ||
| /// A type representing a differentiable value's derivatives. | ||
| /// | ||
| /// Mathematically, this is equivalent to the tangent bundle of the | ||
| /// differentiable manifold represented by the differentiable type. | ||
| associatedtype TangentVector: _Differentiable & AdditiveArithmetic | ||
| where TangentVector.TangentVector == TangentVector | ||
|
|
||
| /// Moves `self` along the given direction. In Riemannian geometry, this is | ||
| /// equivalent to exponential map, which moves `self` on the geodesic surface | ||
| /// along the given tangent vector. | ||
| mutating func move(along direction: TangentVector) | ||
|
|
||
| // SWIFT_ENABLE_TENSORFLOW | ||
| /// A tangent vector such that `move(along: zeroTangentVector)` will not | ||
| /// modify `self`. | ||
| /// - Note: `zeroTangentVector` can be `TangentVector.zero` in most cases, | ||
| /// but types whose tangent vectors depend on instance properties of `self` | ||
| /// need to provide a different implementation. For example, the tangent | ||
| /// vector of an `Array` depends on the array's `count`. | ||
| @available(*, deprecated, message: """ | ||
| `zeroTangentVector` derivation has not been implemented; do not use \ | ||
| this property | ||
| """) | ||
| var zeroTangentVector: TangentVector { get } | ||
| } | ||
|
|
||
| public extension _Differentiable where TangentVector == Self { | ||
| mutating func move(along direction: TangentVector) { | ||
| self += direction | ||
| } | ||
| } | ||
|
|
||
| public extension _Differentiable { | ||
| // This is a temporary solution that allows us to add `zeroTangentVector` | ||
| // without implementing derived conformances. This property is marked | ||
| // unavailable because it will produce incorrect results when tangent vectors | ||
| // depend on instance properties of `self`. | ||
| // FIXME: Implement derived conformance and remove this default | ||
| // implementation. | ||
| var zeroTangentVector: TangentVector { .zero } | ||
| } | ||
|
|
||
| // SWIFT_ENABLE_TENSORFLOW | ||
| public typealias Differentiable = _Differentiable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.