Skip to content

Commit

Permalink
Some patches so that Unitful still works on julia 0.5; also, update d…
Browse files Browse the repository at this point in the history
…eps/build.jl.
  • Loading branch information
ajkeller34 committed Dec 31, 2016
1 parent 866ccb7 commit f03dbcd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ else
end
# The hectare is used more frequently than any other power-of-ten of an are.
const ha = Unitful.Units{(Unitful.Unit{:Are}(2,1//1),), typeof(𝐋)}()
const ha = Unitful.Units{(Unitful.Unit{:Are, Unitful.Dimensions{
(Unitful.Dimension{:Length}(2//1),)}}(2,1//1,1.0,100//1),), typeof(𝐋^2)}()
# Time
@unit minute "min" Minute 60s false
Expand Down
4 changes: 2 additions & 2 deletions src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1014,14 +1014,14 @@ end
@generated function inv(x::Dimensions)
tup = x.parameters[1]
length(tup) == 0 && return :(x)
y = *(Dimensions{tup.^-1}())
y = *(Dimensions{map(x->x^-1,tup)}())
:($y)
end

@generated function inv(x::Units)
tup = x.parameters[1]
length(tup) == 0 && return :(x)
tup2 = tup.^-1#map(x->x^-1,tup)
tup2 = map(x->x^-1,tup)
D = typeof(mapreduce(dimension, *, NoDims, tup2))
y = *(Units{tup2, D}())
:($y)
Expand Down
10 changes: 7 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,13 @@ end
@test typeof([1m, 2m, 3m] * 5m) == Array{typeof(1u"m^2"),1}
@test @inferred(5m .* [1m, 2m, 3m]) == [5m^2, 10m^2, 15m^2]
@test typeof(5m .* [1m, 2m, 3m]) == Array{typeof(1u"m^2"),1}
@test_broken @inferred(eye(2).*V) == [1.0V 0.0V; 0.0V 1.0V]

@test_broken @inferred(V.*eye(2)) == [1.0V 0.0V; 0.0V 1.0V]
@static if VERSION >= v"0.6.0-"

This comment has been minimized.

Copy link
@tkelman

tkelman Feb 21, 2017

what change broke this?

This comment has been minimized.

Copy link
@ajkeller34

ajkeller34 Feb 21, 2017

Author Collaborator

It is broken on 0.6.0-dev.1632, but not 0.6.0-dev.1627. I'm pretty sure 0.6.0-dev.1632 broke this (make dot operations fusing broadcasts, PR JuliaLang/julia#17623). I check for that version in Unitful.jl (the file not the package) at a few places but don't see what I am doing wrong.

This comment has been minimized.

Copy link
@tkelman

tkelman Feb 21, 2017

you have another if VERSION >= v"0.6.0-" on defining the dot operators in the first place, making that more specific would probably also be a good idea

This comment has been minimized.

Copy link
@ajkeller34

ajkeller34 Feb 21, 2017

Author Collaborator

This comment has been minimized.

Copy link
@tkelman

tkelman Feb 21, 2017

ah no, guess not the operators themselves, but promotion on them - https://github.com/ajkeller34/Unitful.jl/blob/0762a70a03250f518156335dc2389557fe1ee263/src/Promotion.jl

This comment has been minimized.

Copy link
@ajkeller34

ajkeller34 Feb 21, 2017

Author Collaborator

Right, I think probably the version correct check there is for this PR which did away with promote_op, but iirc this was one of the last changes before 0.5.0 came out and it didn't quite work for me at the time. I got hit pretty hard by the "type stability of Rational" bug in 0.5.0, which I would wager is why I still needed those definitions, but I'm not sure.

In any case, those promotion definitions are always absent in 0.6-dev versions, so it seems like they can't explain why this test is broken.

@test_broken @inferred(eye(2).*V) == [1.0V 0.0V; 0.0V 1.0V]
@test_broken @inferred(V.*eye(2)) == [1.0V 0.0V; 0.0V 1.0V]
else
@test @inferred(eye(2).*V) == [1.0V 0.0V; 0.0V 1.0V]
@test @inferred(V.*eye(2)) == [1.0V 0.0V; 0.0V 1.0V]
end
@test @inferred([1V 2V; 0V 3V].*2) == [2V 4V; 0V 6V]
@test @inferred([1V, 2V] .* [true, false]) == [1V, 0V]
@test @inferred([1.0m, 2.0m] ./ 3) == [1m/3, 2m/3]
Expand Down

0 comments on commit f03dbcd

Please sign in to comment.