Skip to content

Incorrect promotion behavior of MVectors? #516

Closed
@danielmatz

Description

@danielmatz

I'm not sure if this is intended, but it surprised me when I encountered it today:

julia> a = @MVector rand(3)
3-element MArray{Tuple{3},Float64,1,3}:
@ 0.20369959817130678
 0.6240643747079531
 0.08155951665146732

julia> b = @MVector rand(3)
3-element MArray{Tuple{3},Float64,1,3}:
 0.06021624735568731
 0.5019016054805225
 0.0691906293351614

julia> a + b
3-element SArray{Tuple{3},Float64,1,3}:
 0.2639158455269941
 1.1259659801884756
 0.15075014598662873

julia> a .+ b
3-element SArray{Tuple{3},Float64,1,3}:
 0.2639158455269941
 1.1259659801884756
 0.15075014598662873

I was expecting both a + b and a .+ b to return MArrays.

Interestingly, promote_type does the right thing:

julia> promote_type(MArray{Tuple{3}, Float64, 1, 3}, MArray{Tuple{3}, Float64, 1, 3})
MArray{Tuple{3},Float64,1,3}

Metadata

Metadata

Assignees

No one assigned

    Labels

    designspeculative design related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions