Skip to content

Commit

Permalink
Resolve issue #225.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkeller34 committed Dec 1, 2019
1 parent 51a8650 commit 8e8e00d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Base: Integer, Rational, typemin, typemax
import Base: steprange_last, unsigned

import LinearAlgebra: Diagonal, Bidiagonal, Tridiagonal, SymTridiagonal
import LinearAlgebra: istril, istriu, norm
import LinearAlgebra: istril, istriu, norm, pinv
import Random

import ConstructionBase: constructorof
Expand Down
9 changes: 7 additions & 2 deletions src/quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ function *(x::AbstractQuantity, y::Number)
return Quantity(x.val*y, unit(x))
end

*(A::Units, B::AbstractArray) = broadcast(*, A, B)
*(A::AbstractArray, B::Units) = broadcast(*, A, B)
for f in (:/, :*)
if f != :/
@eval ($f)(A::Units, B::AbstractArray) = broadcast($f, A, B)
end
@eval ($f)(A::AbstractArray, B::Units) = broadcast($f, A, B)
end
/(x::Units, v::AbstractVector) = x*pinv(v)

# Division (units)
/(x::AbstractQuantity, y::Units) = Quantity(x.val, unit(x) / y)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,14 @@ end
@test @inferred([1.0m, 2.0m] ./ 3) == [1m/3, 2m/3]
@test @inferred([1V, 2.0V] ./ [3m, 4m]) == [1V/(3m), 0.5V/m]

@test @inferred(kg * [1, 2]) == [1, 2] * kg
@test @inferred([1, 2]kg) == [1, 2] * kg
@test @inferred([1, 2]kg .* [2, 3]kg^-1) == [2, 6]
end
@testset ">> Array division" begin
@test @inferred(kg / [1, 1]) == [0.5 0.5]kg
@test @inferred([1, 2] / kg) == [1/kg, 2/kg]
end
@testset ">> Array addition" begin
@test @inferred([1m, 2m] + [3m, 4m]) == [4m, 6m]
@test @inferred([1m, 2m] + [1m, 1cm]) == [2m, 201m//100]
Expand Down

0 comments on commit 8e8e00d

Please sign in to comment.