fix and add test

This commit is contained in:
Roger-luo 2018-10-26 14:06:17 -04:00
parent a3cda9016c
commit e5d58699e6
2 changed files with 7 additions and 2 deletions

View File

@ -88,8 +88,8 @@ Base.view(x::TrackedArray, inds...) = track(Base.view, x, inds...)
view(data(x), inds...), function (Δ)
grad_output = zero(x)
subgrad = view(grad_output, inds...)
subgrad[:] = Δ
(grad_output, map(_->nothing, inds)...)
subgrad[:] = data(Δ)
(nobacksies(:view, grad_output), map(_->nothing, inds)...)
end
end

View File

@ -33,6 +33,11 @@ gradtest(f, dims...) = gradtest(f, rand.(Float64, dims)...)
@test gradtest(Flux.crossentropy, rand(5,5), rand(5, 5))
@test gradtest(x -> x', rand(5))
@testset "indexing & slicing" begin
gradtest(x->view(x, 1:2, 1:2), rand(4, 4))
end
function promotiontest(f, A, B, C)
r0 = f(A, B, C)
r1 = f(param(A), B, C)