You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The dropout! function applies @inbounds to a for loop iterating over 1:length(x) where x is not guaranteed to have standard indexing. As a consequence the function can return incorrect results and silently access out-of-bounds memory.
julia>using Knet, OffsetArrays
julia> a = Float64[n for n in1:21];
julia> o =OffsetArray(a, -10:10);
julia>dropout(o, .5, drop=true)
21-element OffsetArray(::Array{Float64,1}, -10:10) with eltype Float64 with indices -10:10:0.50715900646116420.83229533357795820.33886106129789130.91776283449563590.59193436443282790.65572219677287480.143564327933915160.5967842390778870.54272239318477110.56261765630288110.81765378792940990.00.00.00.00.00.036.00.00.00.0
When an array with nonstandard indexing is passed to dropout, similar(array) is passed to dropout!. similar for OffsetArrays returns another OffsetArray and dropout access indices 1:10 (valid) and 11:21 (invalid), while leaving uninitialized memory with arbitrary values at indices -10:0 as seen above.
The text was updated successfully, but these errors were encountered:
The
dropout!
function applies@inbounds
to a for loop iterating over1:length(x)
wherex
is not guaranteed to have standard indexing. As a consequence the function can return incorrect results and silently access out-of-bounds memory.Knet.jl/src/ops20/dropout.jl
Lines 50 to 56 in f1de18b
A concrete example is with
OffsetArrays
:When an array with nonstandard indexing is passed to
dropout
,similar(array)
is passed todropout!
.similar
forOffsetArray
s returns anotherOffsetArray
anddropout
access indices1:10
(valid) and11:21
(invalid), while leaving uninitialized memory with arbitrary values at indices-10:0
as seen above.The text was updated successfully, but these errors were encountered: