Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected results with variable LHS indices #136

Open
cossio opened this issue Feb 11, 2022 · 1 comment
Open

Unexpected results with variable LHS indices #136

cossio opened this issue Feb 11, 2022 · 1 comment
Labels

Comments

@cossio
Copy link

cossio commented Feb 11, 2022

Why these two are different?

using Tullio
w = collect(1.0:2.0);
h = collect(1.0:3.0);
I = zeros(4);
@tullio I[j+k-1] = w[j] * h[k];
# I = [1.0, 2.0, 3.0, 6.0]

vs.

I .= 0
for j  1:length(w), k in 1:length(h)
    I[j+k-1] += w[j] * h[k]
end
# I = [1.0, 4.0, 7.0, 6.0]
@cossio cossio changed the title Unexpected different results Unexpected results for changing LHS indices Feb 11, 2022
@mcabbott
Copy link
Owner

mcabbott commented Feb 11, 2022

Thanks, this is a bug.

I believe this ought to be an error. Tullio doesn't work the way you are imagining here. For each value of the indices on the left, it always iterates a fixed rectangular region of any reduction indices, i.e. those appearing only on the right. This is what it knows how to parallelise safely.

Debug info:

julia> @tullio I[j+k-1] = w[j] * h[k]  verbose=2 grad=false;
┌ Info: ===== Base actor 
│   verbosetidy(ex_act) =quotelocal @inline(function 𝒜𝒸𝓉!(::Type, ℛ::AbstractArray{𝒯}, w, h, 𝒶𝓍j, 𝒶𝓍k, ♻️ = nothing, 💀 = true) where 𝒯
│                    @inbounds @fastmath(beginfor k = 𝒶𝓍k
│                                    for j = 𝒶𝓍j
│                                        ℛ[(j + k) - 1] = w[j] * h[k]
│                                    endendend)
│                end)
└    end
┌ store.
│   arrays = [:w, :h]

│   leftarray = :I
│   leftind = [:j, :k]
│   leftnames = Symbol[]
│   leftraw = Any[:((j + k) - 1)]

│   plusequals = false
│   redfun = :+
│   redind = Symbol[]
│   right = :(w[j] * h[k])
│   rightind = [:j, :k]

┌ Info: left index ranges
│   j = Base.OneTo(2)
└   k = 1:3

@cossio cossio changed the title Unexpected results for changing LHS indices Unexpected results with variable LHS indices Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants