-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Derive ElementaryFunctions
conformances for structs.
#25500
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
Derive ElementaryFunctions
conformances for structs.
#25500
Conversation
`ElementaryFunctions` derived conformances enable elementary math functions to work with product spaces formed from `ElementaryFunctions`-conforming types. Enables efficient, elegant mathematical optimizers.
…sible. Conform `Differentiable` synthesized associated types to `ElementaryFunctions` if possible. Similar to existing logic for `VectorProtocol`.
@@ -625,6 +634,10 @@ getOrSynthesizeSingleAssociatedStruct(DerivedConformance &derived, | |||
None)) | |||
inherited.push_back(kpIterableType); | |||
} | |||
// If all members conform to `ElementaryFunctions`, make the associated struct |
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.
This logic (conform synthesized Differentiable
associated types to ElementaryFunctions
if possible) is not super principled. Similar logic exists for conforming synthesized types to VectorProtocol
if possible.
We could remove this logic by constraining TangentVector
to VectorProtocol
and/or ElementaryFunctions
, but it's not clear to me whether that's desirable. Constraining TangentVector
to VectorProtocol
seems more reasonable.
@@ -203,6 +210,14 @@ ValueDecl *DerivedConformance::getDerivableRequirement(TypeChecker &tc, | |||
|
|||
// Retrieve the requirement. | |||
auto results = proto->lookupDirect(name); | |||
// SWIFT_ENABLE_TENSORFLOW | |||
// Filter requirements, if `filter` function is specified. |
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: adding a filter
function here is necessary because, for the first time, derived conformances must handle two protocol requirements with the same name: pow(_ x: Self, _ y: Self) -> Self
and pow(_ x: Self, _ n: Int) -> Self
.
Verifying whether tests pass. |
2735b55
to
fd11642
Compare
@swift-ci Please test tensorflow |
https://ci-external.swift.org is down, locally verified that tests pass. |
ElementaryFunctions
derived conformances enable elementary math functions to work with product spaces formed fromElementaryFunctions
-conforming types.Enables efficient, elegant mathematical optimizers.
Example:
Resolves TF-578.
Enables revamping optimizers in tensorflow/swift-apis#218.