I am trying to eliminate type unstable parts of my code and Cthulhu.jl is showing the return type of a dictionary access as red:
x = my_dict[first(my_set)]
x is detected as as Array{Float64} but shown in red. I suspect that the return type of first can be the type of the elements in the set or it can be Nothing.
Array{Float64} is an abstract type: an Array has both an element type (in your case, Float64) and a dimension. In your example, the dimension of the Arrays is 1.
You should use either Array{Float64, 1}, or the commonly used name Vector{Float64}.
Right. So If I want to be flexible about the dimension of Array{Float64}, I cannot do that with a type stable code unless I convert any multi-dimensional Array to a Vector? I think that’s doable in my case. Thank you!
If you want myfunc to be flexible so that it can return either an Array{Float64, 1} or an Array{Float64, 2} for example, then by definition it’s not type stable.
The usual solution would be to do as you say, reshape the array to 1 dimension (using vec or reshape is efficient, it doesn’t copy the data).
No it doesn’t mean that. I used Vector because you used one-dimensional arrays in your example. What you do need to do in order to remove the warning is make your arrays concrete types.
If your arrays all have the same dimensionality, you can declare the function using
function my_func(D::Dict{Float64, Array{Float64, N}, s::Set{Float64}) where {N}
...
If, however, the Dict contains arrays with different dimensionalities, then the warning will remain unless you can find a different way to represent your data.