Skip to content

Commit

Permalink
Refactor some promotion rules
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Nov 19, 2023
1 parent 84711c8 commit cb6fb7b
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@ end
function Base.promote_rule(::Type{Dimensions{R1}}, ::Type{Dimensions{R2}}) where {R1,R2}
return Dimensions{promote_type(R1,R2)}
end
function Base.promote_rule(::Type{<:GenericQuantity{T1,D1}}, ::Type{<:GenericQuantity{T2,D2}}) where {T1,T2,D1,D2}
return GenericQuantity{promote_type(T1,T2),promote_type(D1,D2)}
end
function Base.promote_rule(::Type{<:Quantity{T1,D1}}, ::Type{<:Quantity{T2,D2}}) where {T1,T2,D1,D2}
return Quantity{promote_type(T1,T2),promote_type(D1,D2)}
end
function Base.promote_rule(::Type{<:RealQuantity{T1,D1}}, ::Type{<:RealQuantity{T2,D2}}) where {T1,T2,D1,D2}
return RealQuantity{promote_type(T1,T2),promote_type(D1,D2)}
for (_, _, concrete_type) in ABSTRACT_QUANTITY_TYPES
@eval function Base.promote_rule(::Type{<:$concrete_type{T1,D1}}, ::Type{<:$concrete_type{T2,D2}}) where {T1,T2,D1,D2}
return $concrete_type{promote_type(T1,T2),promote_type(D1,D2)}
end
end

function Base.promote_rule(::Type{<:Quantity{T1,D1}}, ::Type{<:GenericQuantity{T2,D2}}) where {T1,T2,D1,D2}
Expand Down

0 comments on commit cb6fb7b

Please sign in to comment.