Skip to content

Commit 6c84a6c

Browse files
committed
make Dropout(0) === identity, cannot mutate
1 parent fec2d8e commit 6c84a6c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/layers/normalise.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ end
6464
Dropout(p::Real, dims, active) = Dropout(p, dims, active, default_rng_value())
6565

6666
function Dropout(p::Real; dims=:, rng = default_rng_value())
67-
0 p 1 || throw(ArgumentError("Dropout expexts 0 ≤ p ≤ 1"))
67+
0 p 1 || throw(ArgumentError("Dropout expexts 0 ≤ p ≤ 1, got p = $p"))
68+
if p isa Integer # Dropout(0)
69+
return p==0 ? identity : zero
70+
end
6871
Dropout(p, dims, nothing, rng)
6972
end
7073

0 commit comments

Comments
 (0)