Skip to content

Commit 3e52062

Browse files
committed
Add end-to-end validation test involving array modify accessor differentiation
1 parent 0fd46d1 commit 3e52062

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/AutoDiff/validation-test/array.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,23 @@ ArrayAutoDiffTests.test("ArraySubscript") {
3636
return array[0] + array[1] + array[2]
3737
}
3838

39+
func modifyArray(_ array: [Float]) -> Float {
40+
var array = array
41+
var result: Float = 0
42+
for index in withoutDerivative(at: 0 ..< array.count) {
43+
let multiplier = 1.0 + Float(index)
44+
array[index] *= multiplier
45+
result += array[index]
46+
}
47+
48+
return result
49+
}
3950
expectEqual(
4051
FloatArrayTan([1, 1, 1, 0, 0, 0]),
4152
gradient(at: [2, 3, 4, 5, 6, 7], of: sumFirstThree))
53+
expectEqual(
54+
FloatArrayTan([1, 2, 3]),
55+
gradient(at: [1, 1, 1], of: modifyArray))
4256
}
4357

4458
ArrayAutoDiffTests.test("ArrayLiteral") {

0 commit comments

Comments
 (0)