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
When the same array appears in both side of =, the result from Tullio is strange
using Tullio
a = [1,2]
b = [1 2;3 4]
a = b * a
println(a) # [5,11]
a = [1,2]
@tullio a[x] = b[x,y] * a[y]
println(a) # [5,23]
It seems only the first component is right. When calculate the second componet, the first component is already updated to 5, and the second component is calculated by 3*5+4*2=23.
When there are some complicated operations which have to be seprated into several steps, to avoid extra allocation, I prefer to use the same array repeatedly, and sometimes wrong results may occur like above.
The text was updated successfully, but these errors were encountered:
# @tullio a[x] = b[x,y] * a[y] verbose=2
function 𝒜𝒸𝓉!(::Type, ℛ::AbstractArray{𝒯}, b, a, 𝒶𝓍x, 𝒶𝓍y, ♻️ = nothing, 💀 = true) where 𝒯
for x in 𝒶𝓍x
𝒜𝒸𝒸 = if ♻️ === nothing
zero(𝒯)
else
ℛ[x]
end
for y in 𝒶𝓍y
𝒜𝒸𝒸 = 𝒜𝒸𝒸 + b[x, y] * a[y]
end
ℛ[x] = 𝒜𝒸𝒸
end
end
This is called like 𝒜𝒸𝓉!(typeof(a), a, b, a, axes(a,1), axes(b,2)), and so the loop overwrites values of a that it needs later.
I guess it would be nice to make this an error, by checking for aliasing.
It should still be safe to re-use an array, as long as you are reading and writing at the same point, not different ones. (E.g. things like a .= a .+ 1 are safe, of course.)
When the same array appears in both side of =, the result from Tullio is strange
It seems only the first component is right. When calculate the second componet, the first component is already updated to 5, and the second component is calculated by
3*5+4*2=23
.When there are some complicated operations which have to be seprated into several steps, to avoid extra allocation, I prefer to use the same array repeatedly, and sometimes wrong results may occur like above.
The text was updated successfully, but these errors were encountered: