Skip to content

Commit cf733cc

Browse files
authored
Merge pull request #362 from JuliaDiff/mz/indexingtests
indexing.jl autotangent
2 parents e049442 + c2cfde0 commit cf733cc

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

test/rulesets/Base/indexing.jl

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,50 @@
11
@testset "getindex" begin
22
@testset "getindex(::Matrix{<:Number},...)" begin
33
x = [1.0 2.0 3.0; 10.0 20.0 30.0]
4-
= [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]
64

75
@testset "single element" begin
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))
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)
119

12-
rrule_test(getindex, 2.3, (x, x̄), (CartesianIndex(2, 3), nothing))
10+
test_rrule(getindex, x, CartesianIndex(2, 3) nothing)
1311
end
1412

1513
@testset "slice/index postions" begin
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))
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)
2018

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))
19+
test_rrule(getindex, x, 1:2 nothing, 2:3 nothing)
20+
test_rrule(getindex, x, (:) nothing, 2:3 nothing)
2321

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))
22+
test_rrule(getindex, x, 1:2 nothing, 1 nothing)
23+
test_rrule(getindex, x, 1 nothing, 1:2 nothing)
2624

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))
25+
test_rrule(getindex, x, 1:2 nothing, 2:3 nothing)
26+
test_rrule(getindex, x, (:) nothing, 2:3 nothing)
2927

30-
31-
rrule_test(getindex, full_ȳ, (x, x̄), (:, nothing), (:, nothing))
32-
rrule_test(getindex, full_ȳ[:], (x, x̄), (:, nothing))
28+
test_rrule(getindex, x, (:) nothing, (:) nothing)
29+
test_rrule(getindex, x, (:) nothing)
3330
end
3431

3532
@testset "masking" begin
36-
rrule_test(getindex, full_ȳ, (x, x̄), (trues(size(x)), nothing))
37-
rrule_test(getindex, full_ȳ[:], (x, x̄), (trues(length(x)), nothing))
33+
test_rrule(getindex, x, trues(size(x)) nothing)
34+
test_rrule(getindex, x, trues(length(x)) nothing)
3835

3936
mask = falses(size(x))
4037
mask[2,3] = true
4138
mask[1,2] = true
42-
rrule_test(getindex, [2.3, 3.1], (x, x̄), (mask, nothing))
39+
test_rrule(getindex, x, mask nothing)
4340

44-
rrule_test(
45-
getindex, full_ȳ[1,:], (x, x̄), ([true, false], nothing), (:, nothing)
46-
)
41+
test_rrule(getindex, x, [true, false] nothing, (:) nothing)
4742
end
4843

4944
@testset "By position with repeated elements" begin
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-
)
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)
5548
end
5649
end
5750
end

0 commit comments

Comments
 (0)