Derive ElementaryFunctions conformances for structs.#25500
Derive ElementaryFunctions conformances for structs.#25500dan-zheng merged 3 commits intoswiftlang:tensorflowfrom
ElementaryFunctions conformances for structs.#25500Conversation
`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`.
| None)) | ||
| inherited.push_back(kpIterableType); | ||
| } | ||
| // If all members conform to `ElementaryFunctions`, make the associated struct |
There was a problem hiding this comment.
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.
| // 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.
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. |
ElementaryFunctionsderived 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.