|
| 1 | +using Test: @test, @inferred |
| 2 | +using BaseType: base_numeric_type |
| 3 | +using DualNumbers: DualNumbers |
| 4 | +using DynamicQuantities: DynamicQuantities |
| 5 | +using Measurements: ± |
| 6 | +using StaticArrays: StaticArrays |
| 7 | +using Unitful: Unitful |
| 8 | + |
| 9 | +expected_type_pairs = [ |
| 10 | + Float32 => Float32, |
| 11 | + Float32 => Float32, |
| 12 | + Array{Float64,1} => Float64, |
| 13 | + ComplexF64 => Float64, |
| 14 | + Matrix{ComplexF64} => ComplexF64, |
| 15 | + DualNumbers.Dual{Int64} => Int64, |
| 16 | + DynamicQuantities.Quantity{Float32} => Float32, |
| 17 | + typeof(1.5DynamicQuantities.u"km/s") => Float64, |
| 18 | + typeof(1.5f0Unitful.u"km/s") => Float32, |
| 19 | + typeof(StaticArrays.SArray{Tuple{32,3}}(randn(32, 3))) => Float64, |
| 20 | + typeof(StaticArrays.SArray{Tuple{32,3}}(randn(Float32, 32, 3))) => Float32, |
| 21 | + BigFloat => BigFloat, |
| 22 | + typeof(1.5 ± 0.2) => Float64, |
| 23 | + typeof(1.5f0 ± 0.2f0) => Float32, |
| 24 | +] |
| 25 | + |
| 26 | +for (x, y) in expected_type_pairs |
| 27 | + @eval @test base_numeric_type($x) == $y |
| 28 | + # Make sure compiler can inline it: |
| 29 | + @eval @inferred typeof($y) base_numeric_type($x) |
| 30 | +end |
| 31 | + |
| 32 | +@test base_numeric_type(1.5DynamicQuantities.u"km/s") == base_numeric_type(typeof(1.5DynamicQuantities.u"km/s")) |
| 33 | +@inferred base_numeric_type(1.5DynamicQuantities.u"km/s") |
0 commit comments