Skip to content

Commit

Permalink
Updates for after julia PRs 18457 and 19670.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkeller34 committed Jan 16, 2017
1 parent 67e8f77 commit 231e222
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,11 @@ end
# performant method.

for (_x,_y) in [(:fma, :_fma), (:muladd, :_muladd)]
@eval @inline ($_x){T<:Number}(x::Quantity{T}, y::T, z::T) = ($_y)(x,y,z)
@eval @inline ($_x){T<:Number}(x::T, y::Quantity{T}, z::T) = ($_y)(x,y,z)
@eval @inline ($_x){T<:Number}(x::T, y::T, z::Quantity{T}) = ($_y)(x,y,z)
@eval @inline ($_x){T<:Number}(x::Quantity{T}, y::Quantity{T}, z::T) = ($_y)(x,y,z)
@eval @inline ($_x){T<:Number}(x::T, y::Quantity{T}, z::Quantity{T}) = ($_y)(x,y,z)
@eval @inline ($_x){T<:Number}(x::Quantity{T}, y::T, z::Quantity{T}) = ($_y)(x,y,z)
# Catch some signatures pre-promotion
@eval @inline ($_x)(x::Number, y::Quantity, z::Quantity) = ($_y)(x,y,z)
@eval @inline ($_x)(x::Quantity, y::Number, z::Quantity) = ($_y)(x,y,z)

# Post-promotion
@eval @inline ($_x){T<:Number}(x::Quantity{T}, y::Quantity{T}, z::Quantity{T}) = ($_y)(x,y,z)

# It seems like most of this is optimized out by the compiler, including the
Expand Down
34 changes: 25 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,19 @@ end
@testset "> Arrays" begin
@testset ">> Array multiplication" begin
# Quantity, quantity
@test @inferred([1m, 2m]' * [3m, 4m]) == [11m^2]
@static if VERSION >= v"0.6.0-" # RowVector change...

This comment has been minimized.

Copy link
@tkelman

tkelman Feb 21, 2017

0.6.0-dev.2074

@test @inferred([1m, 2m]' * [3m, 4m]) == 11m^2
@test @inferred([1m, 2m]' * [3/m, 4/m]) == 11
@test typeof([1m, 2m]' * [3/m, 4/m]) == Int
@test typeof([1m, 2V]' * [3/m, 4/V]) == Int
else
@test @inferred([1m, 2m]' * [3m, 4m]) == [11m^2]
@test @inferred([1m, 2m]' * [3/m, 4/m]) == [11]
@test typeof([1m, 2m]' * [3/m, 4/m]) == Array{Int,1}
@test typeof([1m, 2V]' * [3/m, 4/V]) == Array{Int,1}
end
@test @inferred([1V,2V]*[0.1/m, 0.4/m]') == [0.1V/m 0.4V/m; 0.2V/m 0.8V/m]
@test @inferred([1m, 2m]' * [3/m, 4/m]) == [11]
@test typeof([1m, 2m]' * [3/m, 4/m]) == Array{Int,1}
@test typeof([1m, 2V]' * [3/m, 4/V]) == Array{Int,1}

@static if VERSION >= v"0.6.0-"
@test_broken @inferred([1m, 2V]' * [3/m, 4/V]) == [11]
@test_broken @inferred([1m, 2V] * [3/m, 4/V]') ==
Expand All @@ -652,12 +660,20 @@ end
# Quantity, number or vice versa
@test @inferred([1 2] * [3m,4m]) == [11m]
@test typeof([1 2] * [3m,4m]) == Array{typeof(1u"m"),1}
@test @inferred([1,2] * [3m 4m]) == [3m 4m; 6m 8m]
@test typeof([1,2] * [3m 4m]) == Array{typeof(1u"m"),2}
@test @inferred([3m 4m] * [1,2]) == [11m]
@test typeof([3m 4m] * [1,2]) == Array{typeof(1u"m"),1}
@test @inferred([3m,4m] * [1 2]) == [3m 6m; 4m 8m]
@test typeof([3m,4m] * [1 2]) == Array{typeof(1u"m"),2}

@static if VERSION >= v"0.6.0-"
@test @inferred([1,2] * [3m,4m]') == [3m 4m; 6m 8m]
@test typeof([1,2] * [3m,4m]') == Array{typeof(1u"m"),2}
@test @inferred([3m,4m] * [1,2]') == [3m 6m; 4m 8m]
@test typeof([3m,4m] * [1,2]') == Array{typeof(1u"m"),2}
else
@test @inferred([1,2] * [3m 4m]) == [3m 4m; 6m 8m]
@test typeof([1,2] * [3m 4m]) == Array{typeof(1u"m"),2}
@test @inferred([3m,4m] * [1 2]) == [3m 6m; 4m 8m]
@test typeof([3m,4m] * [1 2]) == Array{typeof(1u"m"),2}
end
end

@testset ">> Element-wise multiplication" begin
Expand Down Expand Up @@ -754,7 +770,7 @@ let fname = tempname()
end
end

@static if VERSION >= v"0.6.0-"
@static if VERSION >= v"0.6.0-" #test_warn commit

This comment has been minimized.

Copy link
@tkelman

tkelman Feb 21, 2017

0.6.0-dev.1980

# check for the warning...
@test_warn "ShadowUnits" eval(:(u"m"))
end
Expand Down

0 comments on commit 231e222

Please sign in to comment.