Skip to content

Commit

Permalink
Improve support for InverseFunctions (#652)
Browse files Browse the repository at this point in the history
* Support InverseFunctions on Julia < v1.9

* Document ustrip support for InverseFunctions

* Fix up whitespace in test/runtests.jl

Co-authored-by: Mosè Giordano <[email protected]>

* Move ustrip inverse docs

* Fix ustrip inverse docs

Co-authored-by: Sebastian Stock <[email protected]>

* Improve Aqua tests

Co-authored-by: Sebastian Stock <[email protected]>

* Update Aqua config in tests

Co-authored-by: Sebastian Stock <[email protected]>

* Require Aqua v0.6.3

Co-authored-by: Sebastian Stock <[email protected]>

---------

Co-authored-by: Mosè Giordano <[email protected]>
Co-authored-by: Sebastian Stock <[email protected]>
  • Loading branch information
3 people authored Jun 12, 2023
1 parent 3798720 commit 9356228
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
16 changes: 9 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ version = "1.14.0"
[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
Aqua = "0.6"
ConstructionBase = "1"
julia = "1"
[weakdeps]
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"

[extensions]
InverseFunctionsUnitfulExt = "InverseFunctions"

[compat]
Aqua = "0.6.3"
ConstructionBase = "1"
InverseFunctions = "0.1"
julia = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
Expand All @@ -25,6 +30,3 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "InverseFunctions", "LinearAlgebra", "Test", "Random"]

[weakdeps]
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"

Expand Down
1 change: 1 addition & 0 deletions docs/src/manipulations.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
```@meta
DocTestSetup = quote
using Unitful
using InverseFunctions
end
```
# Manipulating units
Expand Down
4 changes: 4 additions & 0 deletions src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ include("complex.jl")
include("pkgdefaults.jl")
include("dates.jl")

if !isdefined(Base, :get_extension)
include("../ext/InverseFunctionsUnitfulExt.jl")
end

end
7 changes: 7 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ true
julia> ustrip(Float64, u"m", 2u"mm") == 0.002
true
```
`ustrip` supports `InverseFunctions.inverse`:
```jldoctest
julia> inverse(Base.Fix1(ustrip, u"m"))(5)
5 m
```
"""
@inline ustrip(u::Units, x) = ustrip(uconvert(u, x))
@inline ustrip(T::Type, u::Units, x) = convert(T, ustrip(u, x))
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const colon = Base.:(:)
@test ConstructionBase.constructorof(typeof(1.0m))(2) === 2m
end

VERSION >= v"1.9-" && @testset "inverse" begin
@testset "inverse" begin
InverseFunctions.test_inverse(Base.Fix1(ustrip, m), 2m)
InverseFunctions.test_inverse(Base.Fix1(ustrip, m), 2mm)
end
Expand Down Expand Up @@ -2178,4 +2178,4 @@ end

using Aqua

Aqua.test_all(Unitful, ambiguities=VERSIONv"1.1", unbound_args=false, piracy=VERSIONv"1.8")
Aqua.test_all(Unitful, ambiguities=VERSIONv"1.1", unbound_args=false, piracy=VERSIONv"1.8", project_toml_formatting=VERSIONv"1.6")

0 comments on commit 9356228

Please sign in to comment.