Typestability in matrix multiplication, intended behaviour or bug?

The first one seems intended behaviour, is the second one a bug?

julia> rand(3, 3) * [1.0, missing, missing]
3-element Array{Union{Missing, Float64},1}:
 missing
 missing
 missing

julia> rand(3, 3) * [1.0f0, missing, missing]
3-element Array{Any,1}:
 missing
 missing
 missing

I would expect the second one to have elements of type Union{Missing, Float64}.

julia> rand(3, 3) * [1.0f0, 1.0f0, 1.0f0]
3-element Array{Float64,1}:
 0.905265774575643 
 1.93440074935859  
 1.3997240853999218

Rand by default is Float64. Using Float32 gets what you want:

julia> rand(Float32, 3, 3) * [1.0f0, missing, missing]
3-element Array{Union{Missing, Float32},1}:
missing
missing
missing

Although I’m not sure why that results in Any when you multiply Float32 and Float64.

Edit: seems like any combination of two numbers and missing in an array multiplication gives any.
julia> [2, 3] * [1.0 missing]
2Ă—2 Array{Any,2}:
2.0 missing
3.0 missing

This seems odd, especially because

julia> promote_type(Union{Missing, Float32}, Union{Missing, Float64})
Union{Missing, Float64}

Especially when:

julia> [2, 3] .* [1.0 missing]
2Ă—2 Array{Union{Missing, Float64},2}:
2.0 missing
3.0 missing

Edit: with float not all ints!

The bug appears to have been fixed on master, please check with 1.1.

2 Likes

Yes, is fixed in Julia 1.1, is there going to be a fix for 1.0?

Unlikely.

Isn’t 1.0 supposed to be a long term support version?

Yes, but changing return types can break someones code.

Note that there is no commitment to backporting every bug fix (see the “Long term support” part):

For my usecase, I fixed it with

y = mul!(similar(x), A, x)

this is not generalizable, but works for my use case.

1 Like