|
143 | 143 | test_rrule(∇getindex, [rand(2) for _ in 1:3], rand(2), 3; check_inferred=false) |
144 | 144 | test_rrule(∇getindex, [rand(2) for _ in 1:3], [rand(2), rand(2)], 1:2; check_inferred=false) |
145 | 145 | end |
| 146 | + |
| 147 | + @testset "GPU" begin |
| 148 | + x_23_gpu = jl(rand(2, 3)) |
| 149 | + |
| 150 | + # Scalar indexing, copied from: @macroexpand @allowscalar A[i] |
| 151 | + # Gives an error in Pkg.test, no idea why |
| 152 | + # y1, bk1 = rrule(CFG, Base.task_local_storage, () -> x_23_gpu[1], :ScalarIndexing, ScalarAllowed) |
| 153 | + # @test y1 == @allowscalar x_gpu[1] |
| 154 | + # bk1(1.0) # This is zero, because finite-differencing ignores the function |
| 155 | + # ... but this works, and calls the rule: |
| 156 | + # Zygote.gradient(x -> @allowscalar(x[1]), jl(rand(3)))[1] |
| 157 | + |
| 158 | + y2, bk2 = rrule(getindex, x_23_gpu, :, 2:3) # fast path, just broadcast .+= |
| 159 | + @test unthunk(bk2(jl(ones(2,2)))[2]) == jl([0 1 1; 0 1 1]) |
| 160 | + |
| 161 | + y3, bk3 = rrule(getindex, x_23_gpu, 1, [1,1,2]) # slow path, copy to CPU |
| 162 | + @test_skip Array(y3) == Array(x_gpu)[1, [1,1,2]] # error in Pkg.test, no idea why |
| 163 | + @test unthunk(bk3(jl(ones(3)))[2]) == jl([2 1 0; 0 0 0]) |
| 164 | + end |
146 | 165 | end |
147 | 166 |
|
148 | 167 | @testset "first & tail" begin |
|
178 | 197 | end |
179 | 198 |
|
180 | 199 | @testset "unsafe_getindex" begin |
| 200 | + # In real life this is called only on some AbstractRanges, but easier to test on Array: |
181 | 201 | test_frule(Base.unsafe_getindex, collect(1:0.1:2), 3) |
182 | 202 | test_rrule(Base.unsafe_getindex, collect(1:0.1:2), 3) |
183 | 203 | end |
|
0 commit comments