OffsetArrays do not work in let blocks as expected

Here’s a simpler demonstration:

julia> f = let
         z = rand(3)
         function g(x)
           x .= z
           z = [1]
           sum(x)
         end
       end;

julia> f(ones(3))
1.5738779450861395

julia> f(ones(3))
3.0

The variable z is not local to the function, and thus binding it to a new value changes the result of the second run.

If you don’t want this, then you should give the sum a different name, such as odummy2 = sum(odummy,dims=2).

For completeness, the minimal way to get the error from the above is to run this:

C_mat(rand(2N+1).+im, (1.1, 2.2, 3.3), 4.4) # axes(odummy) = (-15:15, -5:5, -5:5)
C_mat(rand(2N+1).+im, (1.1, 2.2, 3.3), 4.4) # axes(odummy) = (-15:15, -5:-5, -5:5)
1 Like