You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Converting from Double to Double? is essentially an identity operator. This probably generalizes to other differentiable types. Here is a minimal example.
import _Differentiation
/// should be differentiable without explicitly defining a derivative
func convertToOptional(_ a:Double)->Double?{return a
}
/// expected derivative
@derivative(of: convertToOptional)func convertToOptionalVJP(
_ a:Double)->(value:Double?, pullback:(Optional<Double>.TangentVector)->Double){func pullback(_ backwardValue:Optional<Double>.TangentVector)->Double{return backwardValue.value ??0.0}return(value: a, pullback: pullback)}
An application of this is creating a closure around a function that accepts a Double? as input, as follows:
/// differentiable
func f(x:Double?)->Double{if x ==nil{return0.0}else{return2.0* x!
}}
/// differentiable
letfClosureOptionalInput:@differentiable(reverse)(Double?)->Double={
y inf(x: y)}
// should be differentiable
letfClosure:@differentiable(reverse)(Double)->Double={
// y is of type Double
// x is expecting a Double? value
// so the compiler currently complains that this is not differentiable
y inf(x: y)}
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: bb0718bed6418e286a744ca920d5ef3a
Issue Description:
Converting from Double to Double? is essentially an identity operator. This probably generalizes to other differentiable types. Here is a minimal example.
An application of this is creating a closure around a function that accepts a Double? as input, as follows:
The text was updated successfully, but these errors were encountered: