swift
swift copied to clipboard
Map isn't differentiable but compiler diagnosis is gone
I though Dan had talked about .map
becoming differentiable recently in an open design meeting, but there is still an issue as of the 9/16 Xcode snapshot. The compiler lets this through, but it produces an incorrect derivative:
func mappy(a: [Double]) -> Double{
let twice = a.map{$0 * 2} //compiles, but resulting gradient is incorrect (empty list)
// let twice = a.differentiableMap{$0 * 2} //works, gradient is [2.0, 2.0, 2.0]
return twice.differentiableReduce(0, +)
}
print(valueWithGradient(at: [1,2,3], in: mappy))
Also reproducible with Xcode release v0.12-rc2