diff --git a/stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb b/stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb index e4110340ad696..9eee9b6f22b8b 100644 --- a/stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb +++ b/stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb @@ -176,7 +176,7 @@ where ) { return (lhs * rhs, { ltan, rtan in - return lhs * ltan + rtan * rhs + return lhs * rtan + ltan * rhs }) } diff --git a/test/AutoDiff/validation-test/forward_mode.swift b/test/AutoDiff/validation-test/forward_mode.swift index b75cc1645d59e..c29b87f34c198 100644 --- a/test/AutoDiff/validation-test/forward_mode.swift +++ b/test/AutoDiff/validation-test/forward_mode.swift @@ -1537,15 +1537,17 @@ ForwardModeTests.test("Subtraction") { ForwardModeTests.test("Multiplication") { let a = SIMD4(1, 2, 3, 4) + let a2 = SIMD4(4, 3, 2, 1) let g = SIMD4(1, 1, 1, 1) + let g2 = SIMD4(0, 2, 1, 3) // SIMD * SIMD func foo1(x: SIMD4, y: SIMD4) -> SIMD4 { return x * y } - let (val1, df1) = valueWithDifferential(at: a, a, in: foo1) - expectEqual(a * a, val1) - expectEqual(a * g + g * a, df1(g, g)) + let (val1, df1) = valueWithDifferential(at: a, a2, in: foo1) + expectEqual(a * a2, val1) + expectEqual(a * g2 + g * a2, df1(g, g2)) // SIMD * Scalar func foo2(x: SIMD4, y: Float) -> SIMD4 {