StaticArrays.jl icon indicating copy to clipboard operation
StaticArrays.jl copied to clipboard

`*` and `UniformScaling`

Open btmit opened this issue 3 years ago • 2 comments

I'm seeing some strange typing when multiplying StaticArrays and UniformScaling. Is all of this expected?

N = 2

typeof(rand(SMatrix{N,N}) * I)  # SMatrix{N, N}

typeof(rand(SMatrix{N,N}) * I(N))  # Matrix

typeof(rand(SVector{N}) * I)  # Matrix

typeof(I * rand(SVector{N}))  # SVector{N}

typeof(rand(SVector{N}) * I(1))  # Matrix

typeof(I(N) * rand(SVector{N}))  # SizedVector{N}

Should all these be outputs <: StaticArray?

If not, what is the rule for expected output type of these operations?

btmit avatar Oct 13 '22 19:10 btmit

To me it looks like all of them should be static, so it's just a matter of adding more methods to *.

mateuszbaran avatar Oct 13 '22 20:10 mateuszbaran

julia> I
UniformScaling{Bool}
true*I

julia> I*3
UniformScaling{Int64}
3*I

julia> I(3)
3×3 Diagonal{Bool, Vector{Bool}}:
 1  ⋅  ⋅
 ⋅  1  ⋅
 ⋅  ⋅  1

Note that the I(N) case is not a UniformScaling example because it produces a Diagonal wrapping a Vector. But Diagonal matrices are all square so there's still room to improve the output type.

mikmoore avatar Jun 09 '23 17:06 mikmoore