Skip to content

Commit 7e5ae8e

Browse files
committed
use dispatch not branches for projectto(array(number))
1 parent c4d3669 commit 7e5ae8e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/projection.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,12 @@ end
176176

177177
# For arrays of numbers, just store one projector:
178178
function ProjectTo(x::AbstractArray{T}) where {T<:Number}
179-
element = T <: Irrational ? ProjectTo{Real}() : ProjectTo(zero(T))
180-
if element isa ProjectTo{<:AbstractZero}
181-
return ProjectTo{NoTangent}() # short-circuit if all elements project to zero
182-
else
183-
return ProjectTo{AbstractArray}(; element=element, axes=axes(x))
184-
end
179+
return ProjectTo{AbstractArray}(; element=_eltype_projectto(T), axes=axes(x))
185180
end
181+
ProjectTo(x::AbstractArray{Bool}) = ProjectTo{NoTangent}()
182+
183+
_eltype_projectto(::Type{T}) where {T<:Number} = ProjectTo(zero(T))
184+
_eltype_projectto(::Type{<:Irrational}) = ProjectTo{Real}()
186185

187186
# In other cases, store a projector per element:
188187
function ProjectTo(xs::AbstractArray)

0 commit comments

Comments
 (0)