mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
`Differentiable` conformance derivation now supports
`Differentiable.zeroTangentVectorInitializer`.
There are two potential cases:
1. Memberwise derivation: done when `TangentVector` can be initialized memberwise.
2. `{ TangentVector.zero }` derivation: done as a fallback.
`zeroTangentVectorInitializer` is a closure that produces a zero tangent vector,
capturing minimal necessary information from `self`.
It is an instance property, unlike the static property `AdditiveArithmetic.zero`,
and should be used by the differentiation transform for correctness.
Remove `Differentiable.zeroTangentVectorInitializer` dummy default implementation.
Update stdlib `Differentiable` conformances and tests.
Clean up DerivedConformanceDifferentiable.cpp cruft.
Resolves TF-1007.
Progress towards TF-1008: differentiation correctness for projection operations.
15 lines
425 B
Swift
15 lines
425 B
Swift
import _Differentiation
|
|
import a
|
|
|
|
extension Struct: Differentiable {
|
|
public struct TangentVector: Differentiable & AdditiveArithmetic {}
|
|
public mutating func move(along _: TangentVector) {}
|
|
public var zeroTangentVectorInitializer: () -> TangentVector { { .zero } }
|
|
|
|
@usableFromInline
|
|
@derivative(of: method, wrt: x)
|
|
func vjpMethod(_ x: Float) -> (value: Float, pullback: (Float) -> Float) {
|
|
(x, { $0 })
|
|
}
|
|
}
|