Skip to content

Commit 6bade48

Browse files
authored
Merge pull request #173 from SymbolicML:improve-coverage
Improve test coverage of arrays
2 parents 61c90cc + 15ffe99 commit 6bade48

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/arrays.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,6 @@ end
127127
return (q1_converted, q2_converted)
128128
end
129129

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-
138130
function Base.convert(::Type{QA}, A::QA) where {QA<:QuantityArray}
139131
return A
140132
end
@@ -358,7 +350,7 @@ Base.fill(x::UnionAbstractQuantity, t::Tuple{}) = QuantityArray(fill(ustrip(x),
358350

359351
# Will be overloaded by `DynamicQuantitiesLinearAlgebraExt`:
360352
function norm end
361-
is_ext_loaded(::Val) = false
353+
is_ext_loaded(::Val) = false # COV_EXCL_LINE
362354

363355
# Define isapprox for vectors of Quantity's
364356
struct AutoTolerance end

test/unittests.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,39 @@ end
15581558
@test typeof(reduce(vcat, [[0.5us"hr"], [0.5us"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

Comments
 (0)