From 14e6b7594d7f7dbd08a0c64bf4919400f0e152fb Mon Sep 17 00:00:00 2001 From: Jeremiah Lewis <4462211+jeremiahpslewis@users.noreply.github.com> Date: Wed, 9 Aug 2023 13:40:55 +0200 Subject: [PATCH] Fix projecto conversion, apply to complex numbers --- src/projection.jl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/projection.jl b/src/projection.jl index afb3a86b1..dbdf9a0c6 100644 --- a/src/projection.jl +++ b/src/projection.jl @@ -161,15 +161,23 @@ ProjectTo(::Number) = ProjectTo{Number}() function ProjectTo(x::Integer) @static if int2float_type == "Float16" - return ProjectTo{Float16}() + return ProjectTo(Float16(x)) elseif int2float_type == "Float32" - return ProjectTo{Float32}() + return ProjectTo(Float32(x)) else # Float64 - return ProjectTo{Float64}() + return ProjectTo(Float64(x)) end end -ProjectTo(x::Complex{<:Integer}) = ProjectTo(float(x)) +function ProjectTo(x::Complex{<:Integer}) + @static if int2float_type == "Float16" + return ProjectTo(Float16(x)) + elseif int2float_type == "Float32" + return ProjectTo(Float32(x)) + else # Float64 + return ProjectTo(Float64(x)) + end +end # Preserve low-precision floats as accidental promotion is a common performance bug for T in (Float16, Float32, Float64, ComplexF16, ComplexF32, ComplexF64)