@@ -1558,6 +1558,39 @@ end
15581558 @test typeof (reduce (vcat, [[0.5 us " hr" ], [0.5 us " m" ]])) <: Vector{<:Quantity{Float64,<:SymbolicDimensions}}
15591559 end
15601560
1561+ @testset " Array promotion" begin
1562+ A_f32 = QuantityArray (Float32[1.0 2.0 ; 3.0 4.0 ], Q {Float32} (u " m" ))
1563+ B_f64 = QuantityArray (Float64[5.0 6.0 ; 7.0 8.0 ], Q (u " s" ))
1564+ C_mul = A_f32 * B_f64
1565+
1566+ @test eltype (C_mul) <: Q{Float64}
1567+ @test dimension (C_mul) == dimension (u " m*s" )
1568+ @test ustrip (C_mul) ≈ Float64[19.0 22.0 ; 43.0 50.0 ]
1569+
1570+ A = QuantityArray ([1.0 , 2.0 ], Q (u " m" ))
1571+ q_f32 = 2.0f0 * Q {Float32} (u " s" )
1572+ C_bcast = A .* q_f32
1573+
1574+ @test eltype (C_bcast) <: Q{Float64} # Promoted value type
1575+ @test dimension (C_bcast) == dimension (u " m*s" )
1576+ @test ustrip (C_bcast) ≈ [2.0 , 4.0 ]
1577+
1578+ A_dim = QuantityArray ([1.0 2.0 ; 3.0 4.0 ], Q (u " m" )) # Uses Dimensions
1579+ B_sym = QuantityArray ([5.0 6.0 ; 7.0 8.0 ], Q (us " km/s" )) # Uses SymbolicDimensions
1580+ C_mixed_mul = A_dim * B_sym
1581+ @test eltype (C_mixed_mul) <: Q{Float64,<:Dimensions}
1582+ @test dimension (C_mixed_mul) == dimension (u " m^2/s" )
1583+ @test ustrip (C_mixed_mul) ≈ [1.0 2.0 ; 3.0 4.0 ] * [5000.0 6000.0 ; 7000.0 8000.0 ]
1584+
1585+ A_vec_dim = QuantityArray ([1.0 , 2.0 ], Q (u " m" ))
1586+ B_vec_sym = QuantityArray ([3.0 , 4.0 ], Q (us " km" ))
1587+ C_mixed_bcast = A_vec_dim .* B_vec_sym
1588+
1589+ @test eltype (C_mixed_bcast) <: Q{Float64,<:Dimensions}
1590+ @test dimension (C_mixed_bcast) == dimension (u " m^2" )
1591+ @test ustrip (C_mixed_bcast) ≈ [3000.0 , 8000.0 ]
1592+ end
1593+
15611594 Q in (Quantity, RealQuantity) && @testset " Broadcast different arrays $Q " begin
15621595 f (x, y, z, w) = x * y + z * w
15631596 g (x, y, z, w) = f .(x, y, z, w)
0 commit comments