@@ -134,39 +134,32 @@ ProjectTo(::Bool) = ProjectTo{NoTangent}() # same projector as ProjectTo(::Abst
134
134
ProjectTo (:: Real ) = ProjectTo {Real} ()
135
135
ProjectTo (:: Complex ) = ProjectTo {Complex} ()
136
136
ProjectTo (:: Number ) = ProjectTo {Number} ()
137
- for T in (Float16, Float32, Float64, ComplexF16, ComplexF32, ComplexF64)
138
- # Preserve low-precision floats as accidental promotion is a common performance bug
139
- @eval ProjectTo (:: $T ) = ProjectTo {$T} ()
140
- end
137
+
141
138
ProjectTo (x:: Integer ) = ProjectTo (float (x))
142
139
ProjectTo (x:: Complex{<:Integer} ) = ProjectTo (float (x))
143
140
144
141
# Preserve low-precision floats as accidental promotion is a common performance bug
142
+ for T in (Float16, Float32, Float64, ComplexF16, ComplexF32, ComplexF64)
143
+ @eval ProjectTo (:: $T ) = ProjectTo {$T} ()
144
+ end
145
+
145
146
# In these cases we can just `convert` as we know we are dealing with plain and simple types
146
147
(:: ProjectTo{T} )(dx:: AbstractFloat ) where T<: AbstractFloat = convert (T, dx)
147
148
(:: ProjectTo{T} )(dx:: Integer ) where T<: AbstractFloat = convert (T, dx) # needed to avoid ambiguity
149
+ # simple Complex{<:AbstractFloat}} cases
150
+ (:: ProjectTo{T} )(dx:: Complex{<:AbstractFloat} ) where {T<: Complex{<:AbstractFloat} } = convert (T, dx)
151
+ (:: ProjectTo{T} )(dx:: AbstractFloat ) where {T<: Complex{<:AbstractFloat} } = convert (T, dx)
152
+ (:: ProjectTo{T} )(dx:: Complex{<:Integer} ) where {T<: Complex{<:AbstractFloat} } = convert (T, dx)
153
+ (:: ProjectTo{T} )(dx:: Integer ) where {T<: Complex{<:AbstractFloat} } = convert (T, dx)
148
154
149
155
# Other numbers, including e.g. ForwardDiff.Dual and Symbolics.Sym, should pass through.
150
- # We assume (lacking evidence to the contrary) that
156
+ # We assume (lacking evidence to the contrary) that it is the right subspace of numebers
151
157
# The (::ProjectTo{T})(::T) method doesn't work because we are allowing a different
152
158
# Number type that might not be a subtype of the `project_type`.
153
159
(:: ProjectTo{<:Number} )(dx:: Number ) = dx
154
160
155
161
(project:: ProjectTo{<:Real} )(dx:: Complex ) = project (real (dx))
156
-
157
- # Complex
158
-
159
- # Preserve low-precision floats as accidental promotion is a common performance bug
160
- # In these cases we can just `convert` as we know we are dealing with plain and simple types
161
- (:: ProjectTo{T} )(dx:: Complex{<:AbstractFloat} ) where {T<: Complex{<:AbstractFloat} } = convert (T, dx)
162
- (:: ProjectTo{T} )(dx:: AbstractFloat ) where {T<: Complex{<:AbstractFloat} } = convert (T, dx)
163
-
164
- # For on-AbstractFloat other types pass though to project each component
165
- function (:: ProjectTo{<:Complex{T}} )(dx:: Complex ) where T
166
- project = ProjectTo (zero (T))
167
- return Complex (project (real (dx)), project (imag (dx)))
168
- end
169
- (:: ProjectTo{<:Complex{T}} )(dx:: Real ) where T = Complex (ProjectTo (zero (T))(dx))
162
+ (project:: ProjectTo{<:Complex} )(dx:: Real ) = project (complex (dx))
170
163
171
164
# Arrays
172
165
# If we don't have a more specialized `ProjectTo` rule, we just assume that there is
0 commit comments