Skip to content

Commit 598e891

Browse files
committed
use dispatch not branches for projectto(array(number))
1 parent 1014715 commit 598e891

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
@@ -179,13 +179,12 @@ end
179179

180180
# For arrays of numbers, just store one projector:
181181
function ProjectTo(x::AbstractArray{T}) where {T<:Number}
182-
element = T <: Irrational ? ProjectTo{Real}() : ProjectTo(zero(T))
183-
if element isa ProjectTo{<:AbstractZero}
184-
return ProjectTo{NoTangent}() # short-circuit if all elements project to zero
185-
else
186-
return ProjectTo{AbstractArray}(; element=element, axes=axes(x))
187-
end
182+
return ProjectTo{AbstractArray}(; element=_eltype_projectto(T), axes=axes(x))
188183
end
184+
ProjectTo(x::AbstractArray{Bool}) = ProjectTo{NoTangent}()
185+
186+
_eltype_projectto(::Type{T}) where {T<:Number} = ProjectTo(zero(T))
187+
_eltype_projectto(::Type{<:Irrational}) = ProjectTo{Real}()
189188

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

0 commit comments

Comments
 (0)