Typestability in matrix multiplication, intended behaviour or bug?

question

#1

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


#2

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


#3

This seems odd, especially because

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

#4

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!


#5

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


#6

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


#7

Unlikely.


#8

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


#9

Yes, but changing return types can break someones code.


#10

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


#11

For my usecase, I fixed it with

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

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