|
108 | 108 | ) |
109 | 109 | end |
110 | 110 |
|
| 111 | +@inline function promote_except_value(q1::Q1, q2::QA2) where { |
| 112 | + T1,D1,T2,D2,Q1<:UnionAbstractQuantity{T1,D1},Q2, |
| 113 | + QA2<:QuantityArray{T2,N2,D2,Q2} where N2, |
| 114 | +} |
| 115 | + if D1 == D2 && constructorof(Q1) == constructorof(Q2) |
| 116 | + return (q1, q2) |
| 117 | + end |
| 118 | + Q = promote_type(Q1, Q2) |
| 119 | + D = promote_type(D1, D2) |
| 120 | + |
| 121 | + # Create quantity with the properly promoted dimension type |
| 122 | + q1_converted = convert(with_type_parameters(Q, T1, D), q1) |
| 123 | + # Create a promoted QuantityArray |
| 124 | + d2 = convert(with_type_parameters(Q, T2, D), new_quantity(Q, one(T2), dimension(q2))) |
| 125 | + q2_converted = QuantityArray(ustrip(q2), d2) |
| 126 | + |
| 127 | + return (q1_converted, q2_converted) |
| 128 | +end |
| 129 | + |
| 130 | +@inline function promote_except_value(q1::QA1, q2::Q2) where { |
| 131 | + T1,D1,T2,D2,Q1,Q2<:UnionAbstractQuantity{T2,D2}, |
| 132 | + QA1<:QuantityArray{T1,N1,D1,Q1} where N1, |
| 133 | +} |
| 134 | + q2_converted, q1_converted = promote_except_value(q2, q1) |
| 135 | + return (q1_converted, q2_converted) |
| 136 | +end |
| 137 | + |
111 | 138 | function Base.convert(::Type{QA}, A::QA) where {QA<:QuantityArray} |
112 | 139 | return A |
113 | 140 | end |
|
126 | 153 | @inline ustrip(A::QuantityArray) = A.value |
127 | 154 | @inline ustrip(A::AbstractArray{<:UnionAbstractQuantity}) = ustrip.(A) |
128 | 155 | @inline function ustrip(unit::UnionAbstractQuantity, q::QuantityArray) |
| 156 | + unit, q = promote_except_value(unit, q) |
129 | 157 | dimension(unit) == dimension(q) || throw(DimensionError(unit, q)) |
130 | 158 | conversion_factor = ustrip(dimension(q) / unit) |
131 | 159 | return ustrip(q) .* conversion_factor |
|
0 commit comments