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

Possible type related bug in Dict #24233

Closed
1oly opened this issue Oct 20, 2017 · 3 comments
Closed

Possible type related bug in Dict #24233

1oly opened this issue Oct 20, 2017 · 3 comments

Comments

@1oly
Copy link

1oly commented Oct 20, 2017

Hi there,

By a coincidence I stumbled upon a possible bug in Dict.
See MWE below:

A test function that copies keys and values from one dict to another:

function foo(e::T,c::S) where {S,T}
    mydict1 = Dict{String,T}()
    mydict1["a"] = zero(T)
    mydict1["b"] = one(T)

    mydict2 = Dict{String,Array{T,1}}()
    N = 3
    a = zeros(S,N)
    for (key,value) in mydict1
        for i in 1:N
            a[i] = value
        end
        mydict2[key] = a
    end
    return mydict2
end

If T==S then the output is wrong:

julia> foo(1.,1.)
Dict{String,Array{Float64,1}} with 2 entries:
  "b" => [0.0, 0.0, 0.0]
  "a" => [0.0, 0.0, 0.0]

Or

julia> foo(1,1)
Dict{String,Array{Float64,1}} with 2 entries:
  "b" => [0, 0, 0]
  "a" => [0, 0, 0]

But if T != S then I get the correct output:

julia> foo(1,1.)
Dict{String,Array{Int64,1}} with 2 entries:
  "b" => [1, 1, 1]
  "a" => [0, 0, 0]

julia> foo(1.,1)
Dict{String,Array{Float64,1}} with 2 entries:
  "b" => [1.0, 1.0, 1.0]
  "a" => [0.0, 0.0, 0.0]

Tried to track it down further but could not find the source. Am I doing something silly here or is it a bug?

Can try to look more into if I can get some guidance :)

julia> versioninfo()
Julia Version 0.6.0
Commit 903644385b (2017-06-19 13:05 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, skylake)

Best, Oliver

@yuyichao
Copy link
Contributor

This is not a bug. There's no implicit copying so all values will point to the same object.

@yuyichao
Copy link
Contributor

And ref #12441 though the aliasing behavior is definatly the expected one here.

@1oly
Copy link
Author

1oly commented Oct 20, 2017

Thanks for the quick reply and reference!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants