|
1 | 1 | @testset "getindex" begin
|
2 | 2 | @testset "getindex(::Matrix{<:Number},...)" begin
|
3 | 3 | x = [1.0 2.0 3.0; 10.0 20.0 30.0]
|
| 4 | + x̄ = [1.4 2.5 3.7; 10.5 20.1 30.2] |
| 5 | + full_ȳ = [7.4 5.5 2.7; 8.5 11.1 4.2] |
4 | 6 |
|
5 | 7 | @testset "single element" begin
|
6 |
| - test_rrule(getindex, x, 2 ⊢ nothing) |
7 |
| - test_rrule(getindex, x, 2 ⊢ nothing, 1 ⊢ nothing) |
8 |
| - test_rrule(getindex, x, 2 ⊢ nothing, 2 ⊢ nothing) |
| 8 | + rrule_test(getindex, 2.3, (x, x̄), (2, nothing)) |
| 9 | + rrule_test(getindex, 2.3, (x, x̄), (2, nothing), (1, nothing)) |
| 10 | + rrule_test(getindex, 2.3, (x, x̄), (2, nothing), (2, nothing)) |
9 | 11 |
|
10 |
| - test_rrule(getindex, x, CartesianIndex(2, 3) ⊢ nothing) |
| 12 | + rrule_test(getindex, 2.3, (x, x̄), (CartesianIndex(2, 3), nothing)) |
11 | 13 | end
|
12 | 14 |
|
13 | 15 | @testset "slice/index postions" begin
|
14 |
| - test_rrule(getindex, x, 2:3 ⊢ nothing) |
15 |
| - test_rrule(getindex, x, 3:-1:2 ⊢ nothing) |
16 |
| - test_rrule(getindex, x, [3,2] ⊢ nothing) |
17 |
| - test_rrule(getindex, x, [2,3] ⊢ nothing) |
| 16 | + rrule_test(getindex, [2.3, 3.1], (x, x̄), (2:3, nothing)) |
| 17 | + rrule_test(getindex, [2.3, 3.1], (x, x̄), (3:-1:2, nothing)) |
| 18 | + rrule_test(getindex, [2.3, 3.1], (x, x̄), ([3,2], nothing)) |
| 19 | + rrule_test(getindex, [2.3, 3.1], (x, x̄), ([2,3], nothing)) |
18 | 20 |
|
19 |
| - test_rrule(getindex, x, 1:2 ⊢ nothing, 2:3 ⊢ nothing) |
20 |
| - test_rrule(getindex, x, (:) ⊢ nothing, 2:3 ⊢ nothing) |
| 21 | + rrule_test(getindex, [2.3 3.1; 4.1 5.1], (x, x̄), (1:2, nothing), (2:3, nothing)) |
| 22 | + rrule_test(getindex, [2.3 3.1; 4.1 5.1], (x, x̄), (:, nothing), (2:3, nothing)) |
21 | 23 |
|
22 |
| - test_rrule(getindex, x, 1:2 ⊢ nothing, 1 ⊢ nothing) |
23 |
| - test_rrule(getindex, x, 1 ⊢ nothing, 1:2 ⊢ nothing) |
| 24 | + rrule_test(getindex, [2.3, 3.1], (x, x̄), (1:2, nothing), (1, nothing)) |
| 25 | + rrule_test(getindex, [2.3, 3.1], (x, x̄), (1, nothing), (1:2, nothing)) |
24 | 26 |
|
25 |
| - test_rrule(getindex, x, 1:2 ⊢ nothing, 2:3 ⊢ nothing) |
26 |
| - test_rrule(getindex, x, (:) ⊢ nothing, 2:3 ⊢ nothing) |
| 27 | + rrule_test(getindex, [2.3 3.1; 4.1 5.1], (x, x̄), (1:2, nothing), (2:3, nothing)) |
| 28 | + rrule_test(getindex, [2.3 3.1; 4.1 5.1], (x, x̄), (:, nothing), (2:3, nothing)) |
27 | 29 |
|
28 |
| - test_rrule(getindex, x, (:) ⊢ nothing, (:) ⊢ nothing) |
29 |
| - test_rrule(getindex, x, (:) ⊢ nothing) |
| 30 | + |
| 31 | + rrule_test(getindex, full_ȳ, (x, x̄), (:, nothing), (:, nothing)) |
| 32 | + rrule_test(getindex, full_ȳ[:], (x, x̄), (:, nothing)) |
30 | 33 | end
|
31 | 34 |
|
32 | 35 | @testset "masking" begin
|
33 |
| - test_rrule(getindex, x, trues(size(x)) ⊢ nothing) |
34 |
| - test_rrule(getindex, x, trues(length(x)) ⊢ nothing) |
| 36 | + rrule_test(getindex, full_ȳ, (x, x̄), (trues(size(x)), nothing)) |
| 37 | + rrule_test(getindex, full_ȳ[:], (x, x̄), (trues(length(x)), nothing)) |
35 | 38 |
|
36 | 39 | mask = falses(size(x))
|
37 | 40 | mask[2,3] = true
|
38 | 41 | mask[1,2] = true
|
39 |
| - test_rrule(getindex, x, mask ⊢ nothing) |
| 42 | + rrule_test(getindex, [2.3, 3.1], (x, x̄), (mask, nothing)) |
40 | 43 |
|
41 |
| - test_rrule(getindex, x, [true, false] ⊢ nothing, (:) ⊢ nothing) |
| 44 | + rrule_test( |
| 45 | + getindex, full_ȳ[1,:], (x, x̄), ([true, false], nothing), (:, nothing) |
| 46 | + ) |
42 | 47 | end
|
43 | 48 |
|
44 | 49 | @testset "By position with repeated elements" begin
|
45 |
| - test_rrule(getindex, x, [2, 2] ⊢ nothing) |
46 |
| - test_rrule(getindex, x, [2, 2, 2] ⊢ nothing) |
47 |
| - test_rrule(getindex, x, [2,2] ⊢ nothing, [3,3] ⊢ nothing) |
| 50 | + rrule_test(getindex, [2.3, 3.1], (x, x̄), ([2, 2], nothing)) |
| 51 | + rrule_test(getindex, [2.3, 3.1, 4.1], (x, x̄), ([2, 2, 2], nothing)) |
| 52 | + rrule_test( |
| 53 | + getindex, [2.3 3.1; 4.1 5.1], (x, x̄), ([2,2], nothing), ([3,3], nothing) |
| 54 | + ) |
48 | 55 | end
|
49 | 56 | end
|
50 | 57 | end
|
0 commit comments