Skip to content

Commit f37b58e

Browse files
authored
Fix convert(::Type{<:StaticArray}, ::UniformScaling) (#759)
1 parent f82bb09 commit f37b58e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/linalg.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ end
102102
# because we do not have `SArray{Tuple{2,3}} <: StaticMatrix`.
103103
(::Type{SM})(I::UniformScaling) where {SM<:(StaticArray{Tuple{N,M}} where {N,M})} =
104104
_scalar_matrix(Size(SM), SM, I.λ)
105+
convert(T::Type{<:StaticArrayLike}, I::UniformScaling) = T(I)
105106

106107
# Construct a matrix with the scalar λ on the diagonal and zeros off the
107108
# diagonal. The matrix can be non-square.

test/linalg.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ using LinearAlgebra: checksquare
7575
@test @inferred(SDiagonal{3}(2.0I))::SDiagonal{3,Float64} == 2I3x3
7676
@test @inferred(SDiagonal{3,Float64}(I))::SDiagonal{3,Float64} == I3x3
7777
@test @inferred(SDiagonal{3,Float32}(2.0I))::SDiagonal{3,Float32} == 2I3x3
78+
79+
# convert from UniformScaling falls back to constructors
80+
@test @inferred(convert(SMatrix{2,2,Float64}, I)) === SA_F64[1 0; 0 1]
81+
@test @inferred(convert(MMatrix{2,2,Float64}, I))::MMatrix{2,2,Float64} == SA[1 0; 0 1]
82+
@test @inferred(convert(SMatrix{2,2}, I)) === SA{Bool}[1 0; 0 1]
83+
@test @inferred(convert(SArray{Tuple{2,2}}, I)) === SA{Bool}[1 0; 0 1]
84+
@test @inferred(convert(SDiagonal{2}, I)) === Diagonal{Bool,SArray{Tuple{2},Bool,1,2}}((1,1))
7885
end
7986

8087
@testset "diagm()" begin

0 commit comments

Comments
 (0)