-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] add some @derivative(of:) tests #28785
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
marcrasi
merged 2 commits into
swiftlang:tensorflow
from
marcrasi:retrodiff-followup-tests
Dec 18, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend %s -emit-module -parse-as-library -o %t | ||
// RUN: llvm-bcanalyzer %t/derivative_attr.swiftmodule | %FileCheck %s -check-prefix=BCANALYZER | ||
// RUN: %target-sil-opt -disable-sil-linking -enable-sil-verify-all %t/derivative_attr.swiftmodule -o - | %FileCheck %s | ||
|
||
// BCANALYZER-NOT: UnknownCode | ||
|
||
struct DerivativeOfSpecialMethods: Differentiable { | ||
var x: Float | ||
|
||
init(_ x: Float) { self.x = x } | ||
subscript(_ i: Int) -> Float { x } | ||
|
||
// CHECK: @derivative(of: init, wrt: x) | ||
// CHECK-NEXT: static func dInit(_ x: Float) | ||
@derivative(of: init(_:)) | ||
static func dInit(_ x: Float) -> (value: Self, pullback: (TangentVector) -> Float) { | ||
fatalError() | ||
} | ||
|
||
// CHECK: @derivative(of: subscript, wrt: self) | ||
// CHECK-NEXT: func dSubscript(_ i: Int) | ||
@derivative(of: subscript(_:)) | ||
func dSubscript(_ i: Int) -> (value: Float, pullback: (Float) -> TangentVector) { | ||
fatalError() | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: #28781 added a a file of the same name (
test/AutoDiff/Serialization/derivative_attr.swift
) tomaster
branch. It covers the functionality added in this test:@derivative
attribute serialization forinit
andsubscript
.So far,
AutoDiff
tests onmaster
branch andtensorflow
branch have been kept separate:master
branch tests are all categorized intest/AutoDiff/XXX
subdirectories, liketest/AutoDiff/Parse
.tensorflow
branch tests exist intest/AutoDiff
at the top-level. Some multi-file tests include files intest/AutoDiff/Inputs
and/or their own subdirectories, liketest/AutoDiff/silgen_thunking/main.swift
andswift/test/AutoDiff/Inputs/silgen_thunking_other_module.swift
.I think separation is nice because it makes it clear which tests have been upstreamed and prevents merge conflicts.
How about moving all non-upstreamed
tensorflow
branch tests to atest/AutoDiff/tensorflow
subdirectory? cc @rxwei @bgogulAs AutoDiff code is upstreamed, tests can be polished and moved to
test/AutoDiff/xxx
, so eventuallytest/AutoDiff/tensorflow
becomes empty. Ontensorflow
branch, tests should never be added totest/AutoDiff
outside oftest/AutoDiff/tensorflow
. Onmaster
branch,test/AutoDiff/tensorflow
does not exist and tests should be added totest/AutoDiff/XXX
.I'm happy to start this after this PR is merged!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A separate folder sounds good, but perhaps instead put upstreamed ones in
test/AutoDiff/upstreamed/
?