add support for 0-element Chain
This commit is contained in:
parent
ccfe0f8720
commit
5c2a071713
@ -47,6 +47,9 @@ Calculate the forward results of each layers in Chain `c`
|
|||||||
"""
|
"""
|
||||||
activations(m, x) = activations(Chain(m), x)
|
activations(m, x) = activations(Chain(m), x)
|
||||||
function activations(c::Chain, x)
|
function activations(c::Chain, x)
|
||||||
|
if length(c) == 0
|
||||||
|
return []
|
||||||
|
end
|
||||||
rst = [c[1](x), ]
|
rst = [c[1](x), ]
|
||||||
if length(c) == 1
|
if length(c) == 1
|
||||||
return rst
|
return rst
|
||||||
|
@ -9,6 +9,7 @@ import Flux: activations
|
|||||||
@test_nowarn activations(dummy_model[1:end-1], x)
|
@test_nowarn activations(dummy_model[1:end-1], x)
|
||||||
@test_nowarn activations(dummy_model, x)
|
@test_nowarn activations(dummy_model, x)
|
||||||
|
|
||||||
|
@test activations(Chain(), x)[1] == []
|
||||||
@test activations(dummy_model, x)[1] == dummy_model[1](x)
|
@test activations(dummy_model, x)[1] == dummy_model[1](x)
|
||||||
@test activations(dummy_model, x)[2] == x |> dummy_model[1] |> dummy_model[2]
|
@test activations(dummy_model, x)[2] == x |> dummy_model[1] |> dummy_model[2]
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user