Skip to content

Commit ffb1747

Browse files
committed
make Dropout(0) === identity, cannot mutate
1 parent 5a53ff9 commit ffb1747

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
@@ -68,7 +68,10 @@ end
6868
Dropout(p::Real, dims, active) = Dropout(p, dims, active, default_rng_value())
6969

7070
function Dropout(p::Real; dims=:, rng = default_rng_value())
71-
0 p 1 || throw(ArgumentError("Dropout expexts 0 ≤ p ≤ 1"))
71+
0 p 1 || throw(ArgumentError("Dropout expexts 0 ≤ p ≤ 1, got p = $p"))
72+
if p isa Integer # Dropout(0)
73+
return p==0 ? identity : zero
74+
end
7275
Dropout(p, dims, nothing, rng)
7376
end
7477

0 commit comments

Comments
 (0)