swift icon indicating copy to clipboard operation
swift copied to clipboard

Map isn't differentiable but compiler diagnosis is gone

Open porterchild opened this issue 3 years ago • 1 comments

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))

porterchild avatar Nov 04 '20 00:11 porterchild

Also reproducible with Xcode release v0.12-rc2

porterchild avatar Nov 19 '20 01:11 porterchild