If I have following two variants to write a part of my code and I generally prefer a shorter one. This is the reason why I do like dot-broadcasting in Julia. However I have this example shows that there's something wrong with it.
function test1(A)
n = size(A, 2)
for k in 1:n
for i in k+1:n
A[i, k] /= A[k, k]
end
end
A
end
function test2(A)
n = size(A, 2)
for k in 1:n
A[k+1:n, k] ./= A[k,k]
end
A
end
A = rand(10000,10000)
B = copy(A)
@allocated test1(B) # returns 0
C = copy(A)
@allocated test2(C) # returns 401131136
C == B # returns true
Moreover I tried to eliminate syntactic sugar and wrote one more test function
function test3(A)
n = size(A, 2)
for k in 1:n
broadcast!(/, A[k+1:n, k], A[k+1:n, k], A[k,k])
end
A
end
And this one allocates twice as much memory as test2 and... returns wrong result.
Why does test3 return wrong result, and what's wrong with broadcasting, are there any guides explaining how to use it?