Skip to content

Commit 57516a9

Browse files
committed
[AutoDiff] Add tests exercising zero derivative of Array.DifferentiableView.+ and .move
Tests for false positive precondition triggered by a .zero gradient, i.e. empty [] array, back-propagated through concatenation and move methods Implements a simplified reproducer of SR-14297
1 parent 81794c8 commit 57516a9

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
@@ -344,6 +344,10 @@ ArrayAutoDiffTests.test("Array.+") {
344344
}
345345
let v = FloatArrayTan([4, -5, 6])
346346
expectEqual(v, pullback(at: [1, 2, 3], of: identity)(v))
347+
348+
let v1: [Float] = [1, 1]
349+
let v2: [Float] = [1, 1, 1]
350+
expectEqual((.zero, .zero), pullback(at: v1, v2, of: +)(.zero))
347351
}
348352

349353
ArrayAutoDiffTests.test("Array.+=") {
@@ -438,4 +442,14 @@ ArrayAutoDiffTests.test("Array.DifferentiableView.base") {
438442
backprop(FloatArrayTan([1, 2, 3, 4])))
439443
}
440444

445+
ArrayAutoDiffTests.test("Array.DifferentiableView.move") {
446+
var v: [Float] = [1, 2, 3]
447+
v.move(by: .zero)
448+
expectEqual(v, [1, 2, 3])
449+
450+
var z: [Float] = []
451+
z.move(by: .zero)
452+
expectEqual(z, [])
453+
}
454+
441455
runAllTests()

0 commit comments

Comments
 (0)