From cd666f1224437d08ee86636b7c6e8627fa0cc5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kr=C3=B6pelin?= Date: Wed, 19 Nov 2025 16:20:52 +0100 Subject: [PATCH] Fix eltype of nearest_rotation --- src/core_types.jl | 2 +- test/nearest_rotation.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core_types.jl b/src/core_types.jl index 358266d2..952a7a34 100644 --- a/src/core_types.jl +++ b/src/core_types.jl @@ -235,7 +235,7 @@ See [Wahba's problem](https://en.wikipedia.org/wiki/Wahba%27s_problem) for more function nearest_rotation(M::StaticMatrix{N,N}) where N u, _, v = svd(M) s = sign(det(u * v')) - d = @SVector ones(N-1) + d = @SVector ones(eltype(M), N-1) R = u * Diagonal(push(d,s)) * v' return RotMatrix{N}(R) end diff --git a/test/nearest_rotation.jl b/test/nearest_rotation.jl index 6bd0b864..ef529003 100644 --- a/test/nearest_rotation.jl +++ b/test/nearest_rotation.jl @@ -32,4 +32,11 @@ @test all(sort(eigvals(Symmetric(V)))[2:end] .≥ 0) end end + @testset "return eltype" begin + for T in (Float16, Float32, Float64) + M = @SMatrix randn(T, 3, 3) + R = nearest_rotation(M) + @test eltype(M) == eltype(R) + end + end end