Skip to content

[stdlib] [Sema] Add broadcasting 'adding(_:)' and 'subtracting(_:)' to 'VectorProtocol'. #25525

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
merged 8 commits into from
Jun 18, 2019

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Jun 17, 2019

  • Add broadcasting 'adding(:)' and 'subtracting(:)' to 'VectorProtocol'. These are important for aggregate algorithms such as machine learning optimizers ([Optimizer] Simplify optimizers using generalized vector math. tensorflow/swift-apis#218).
  • Make their implementations compiler-derivable.
  • Add operators for adding(_:) and subtracting(_:) in a protocol extension.
  • Comment out all operators in protocol extensions for VectorProtocol because a source breakage has been found.

@rxwei rxwei added the tensorflow This is for "tensorflow" branch PRs. label Jun 17, 2019
@rxwei rxwei requested a review from dan-zheng June 17, 2019 21:20
@rxwei
Copy link
Contributor Author

rxwei commented Jun 17, 2019

Still WIP. Free to be picked up by anyone.

@rxwei rxwei force-pushed the vectorprotocol-additive branch from 976f841 to f962f20 Compare June 17, 2019 21:27
@rxwei rxwei requested a review from stephentyrone June 17, 2019 22:42

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…o 'VectorProtocol'.

Also make their implementations compiler-derivable.
@rxwei rxwei force-pushed the vectorprotocol-additive branch from f962f20 to 965e2fb Compare June 17, 2019 23:57
@rxwei rxwei marked this pull request as ready for review June 17, 2019 23:58
@rxwei
Copy link
Contributor Author

rxwei commented Jun 17, 2019

Ready for review.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link
Contributor

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I believe the existing test/Sema/struct_vector_protocol.swift is sufficient for testing.

@@ -268,18 +266,32 @@ static ValueDecl *deriveVectorProtocol_scaled(DerivedConformance &derived) {
auto scalarType = deriveVectorProtocol_VectorSpaceScalar(nominal, parentDC)
->mapTypeOutOfContext();

auto bodySynthesizer = [](AbstractFunctionDecl *funcDecl, void *ctx) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice utilization of BodySynthesizer's context!

rxwei added 2 commits June 17, 2019 17:13

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@rxwei
Copy link
Contributor Author

rxwei commented Jun 18, 2019

Default-implemented broadcasting operators such as +, - and * heavily impacted type checker performance and caused the TensorFlow library to fail to compile.

error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
    let loss = maxLogitsWithZero - logits * labels + log(1 + exp(-abs(logits)))
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

So I removed all operators in VectorProtocol extensions.

rxwei added 2 commits June 17, 2019 17:49

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@rxwei
Copy link
Contributor Author

rxwei commented Jun 18, 2019

@swift-ci please test tensorflow

1 similar comment
@rxwei
Copy link
Contributor Author

rxwei commented Jun 18, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Jun 18, 2019

@swift-ci please test tensorflow

1 similar comment
@rxwei
Copy link
Contributor Author

rxwei commented Jun 18, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Jun 18, 2019

@swift-ci please test tensorflow Linux

2 similar comments
@rxwei
Copy link
Contributor Author

rxwei commented Jun 18, 2019

@swift-ci please test tensorflow Linux

@rxwei
Copy link
Contributor Author

rxwei commented Jun 18, 2019

@swift-ci please test tensorflow Linux

@rxwei rxwei merged commit aa6d64c into swiftlang:tensorflow Jun 18, 2019
@rxwei rxwei deleted the vectorprotocol-additive branch June 18, 2019 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tensorflow This is for "tensorflow" branch PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants