Skip to content

Commit f4c1ce2

Browse files
Fix eltype of nearest_rotation (#301)
1 parent 8ede817 commit f4c1ce2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/core_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ See [Wahba's problem](https://en.wikipedia.org/wiki/Wahba%27s_problem) for more
235235
function nearest_rotation(M::StaticMatrix{N,N}) where N
236236
u, _, v = svd(M)
237237
s = sign(det(u * v'))
238-
d = @SVector ones(N-1)
238+
d = @SVector ones(eltype(M), N-1)
239239
R = u * Diagonal(push(d,s)) * v'
240240
return RotMatrix{N}(R)
241241
end

test/nearest_rotation.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,11 @@
3232
@test all(sort(eigvals(Symmetric(V)))[2:end] .≥ 0)
3333
end
3434
end
35+
@testset "return eltype" begin
36+
for T in (Float16, Float32, Float64)
37+
M = @SMatrix randn(T, 3, 3)
38+
R = nearest_rotation(M)
39+
@test eltype(M) == eltype(R)
40+
end
41+
end
3542
end

0 commit comments

Comments
 (0)