File tree 1 file changed +48
-0
lines changed
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 275
275
@test d. z == [2.0 , 3.0 ]
276
276
@test d. z isa SubArray
277
277
end
278
+
279
+
280
+ @testset " aliasing" begin
281
+ a = Base. RefValue (1.5 )
282
+ b = (a, 1.0 , a)
283
+ db = zero_tangent (b)
284
+ @test iszero (db)
285
+ @test_broken db[1 ] === db[3 ]
286
+ @test db[2 ] == 0.0
287
+
288
+ x = [1.5 ]
289
+ y = [x, [1.0 ], x]
290
+ dy = zero_tangent (y)
291
+ @test iszero (dy)
292
+ @test_broken dy[1 ] === dy[3 ]
293
+ @test dy[2 ] == [0.0 ]
294
+ end
295
+
296
+ @testset " cyclic references" begin
297
+ mutable struct Link
298
+ data:: Float64
299
+ next:: Link
300
+ Link (data) = new (data)
301
+ end
302
+
303
+ lk = Link (1.5 )
304
+ lk. next = lk
305
+
306
+ @test_broken d = zero_tangent (lk)
307
+ @test_broken d. data == 0.0
308
+ @test_broken d. next === d
309
+
310
+ struct CarryingArray
311
+ x:: Vector
312
+ end
313
+ ca = CarryingArray (Any[1.5 ])
314
+ push! (ca. x, ca)
315
+ @test_broken d_ca = zero_tangent (ca)
316
+ @test_broken d_ca[1 ] == 0.0
317
+ @test_broken d_ca[2 ] === _ca
318
+
319
+ # Idea: check if typeof(xs) <: eltype(xs), if so need to cache it before computing
320
+ xs = Any[1.5 ]
321
+ push! (xs, xs)
322
+ @test_broken d_xs = zero_tangent (xs)
323
+ @test_broken d_xs[1 ] == 0.0
324
+ @test_broken d_xs[2 ] == d_xs
325
+ end
278
326
end
You can’t perform that action at this time.
0 commit comments