Skip to content

Commit 010397b

Browse files
authored
Fix eltype for recurisve adjoint/transpose (#709)
The eltype may change due to the recursive nature of adjoint and transpose.
1 parent b4f7e5e commit 010397b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/linalg.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ end
6262

6363
return quote
6464
$(Expr(:meta, :inline))
65-
@inbounds return similar_type($m, Size($Snew))(tuple($(exprs...)))
65+
elements = tuple($(exprs...))
66+
@inbounds return similar_type($m, eltype(elements), Size($Snew))(elements)
6667
end
6768
end
6869

@@ -78,7 +79,8 @@ end
7879

7980
return quote
8081
$(Expr(:meta, :inline))
81-
@inbounds return similar_type($m, Size($Snew))(tuple($(exprs...)))
82+
elements = tuple($(exprs...))
83+
@inbounds return similar_type($m, eltype(elements), Size($Snew))(elements)
8284
end
8385
end
8486

test/linalg.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ using LinearAlgebra: checksquare
147147
@test @inferred(adjoint(@SMatrix [m m; m m])) == adjoint([[m] [m]; [m] [m]])
148148
@test @inferred(transpose(@SMatrix [m m; m m])) == transpose([[m] [m]; [m] [m]])
149149

150+
# Recursive adjoint/transpose correctly handles eltype (#708)
151+
@test (@inferred(adjoint(SMatrix{2,2}(fill([1,2], 2,2)))))::SMatrix == SMatrix{2,2}(fill(adjoint([1,2]), 2,2))
152+
@test (@inferred(transpose(SMatrix{2,2}(fill([1,2], 2,2)))))::SMatrix == SMatrix{2,2}(fill(transpose([1,2]), 2,2))
150153
end
151154

152155
@testset "normalization" begin

0 commit comments

Comments
 (0)