-
Notifications
You must be signed in to change notification settings - Fork 28
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
Bool values sometimes converted to Integer #118
Comments
Yes, we use The workaround is to specify the type explicty. |
I'll try your work-around, and hopefully report back. As for suggestions on the dictionary interface, I don't feel I understand Julia well enough to be helpful. I'm still struggling with Abstract data types and generic functions. Each time I try, I end up particularizing the code to get it to work. I'm still learning Julia. |
There seem three possible solutions to having type instability or mangling:
|
At a minimum, I think promotion should be optional. Unexpected, automatic conversions can be quite confusing to debug. Promotion can provide a performance advantage for Arrays by avoiding an indirection, but this seems less useful for Dictionaries. |
Promotion is optional: if you specify the dictionary type precisely and use it's constructor there is no promotion. The issue here is taking a list of pairs and constructing a dictionary with a certian element type (i.e. the Keep in mind in the first example the behavior isn't due to Dictionaries.jl but is due to Julia: julia> [:isvalid => true, :value => 0]
2-element Vector{Pair{Symbol, Int64}}:
:isvalid => 1
:value => 0 The
This isn't true. Harmonizing the types makes arrays faster, and also makes dictionaries faster (which in many use cases for Dictionaries.jl like iteration/mapping/broadcasting/etc are the same speed as arrays, for much the same design decisions).
Again I feel there is a misunderstanding here. Dictionaries in Julia are for homogenous data, just like arrays. On top of that one nice thing you can choose to do in Julia because of it's type system is if you want heterogenous data you can use There is a valid issue with the |
Thanks for the detailed response. |
dictionary([:isvalid => true, :value => 0])
2-element Dictionary{Symbol, Int64}
:isvalid │ 1
:value │ 0
dictionary([:isvalid => true, :value => "0"])
2-element Dictionary{Symbol, Any}
:isvalid │ true
:value │ "0"
Dict works as expected.
Dict(:isvalid => true, :value => 0)
Dict{Symbol, Integer} with 2 entries:
:isvalid => true
:value => 0
Perhaps it is because
Bool <: Integer
but notBool <: Int64
?This seems to occur when there is at least one Integer and Bool value.
Is this a bug? Is there a workaround?
The text was updated successfully, but these errors were encountered: