Skip to content

Commit

Permalink
support InverseFunctions for Fix1(ustrip, ::Units) (#622)
Browse files Browse the repository at this point in the history
* support InverseFunctions

* review comments

* Project order as Aqua

* Update ext/InverseFunctionsUnitfulExt.jl

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

* fix order

---------

Co-authored-by: Sebastian Stock <[email protected]>
  • Loading branch information
aplavin and sostock authored May 11, 2023
1 parent bd09747 commit 3ab02d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 9 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Unitful"
uuid = "1986cc42-f94f-5a68-af5c-568840ba703d"
version = "1.13.1"
version = "1.14.0"

[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Expand All @@ -13,11 +13,18 @@ Aqua = "0.6"
ConstructionBase = "1"
julia = "1"

[extensions]
InverseFunctionsUnitfulExt = "InverseFunctions"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

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

[weakdeps]
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
8 changes: 8 additions & 0 deletions ext/InverseFunctionsUnitfulExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module InverseFunctionsUnitfulExt
using Unitful
import InverseFunctions: inverse

# `true` plays the role of 1, but doesn't promote unnecessary
inverse(f::Base.Fix1{typeof(ustrip), <:Unitful.Units}) = Base.Fix1(*, true*f.x)

end
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Unitful
using Test, LinearAlgebra, Random, ConstructionBase
using Test, LinearAlgebra, Random, ConstructionBase, InverseFunctions
import Unitful: DimensionError, AffineError
import Unitful: LogScaled, LogInfo, Level, Gain, MixedUnits, Decibel
import Unitful: FreeUnits, ContextUnits, FixedUnits, AffineUnits, AffineQuantity
Expand Down Expand Up @@ -85,6 +85,11 @@ const colon = Base.:(:)
@test ConstructionBase.constructorof(typeof(1.0m))(2) === 2m
end

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

@testset "Types" begin
@test Base.complex(Quantity{Float64,NoDims,NoUnits}) ==
Quantity{Complex{Float64},NoDims,NoUnits}
Expand Down

0 comments on commit 3ab02d8

Please sign in to comment.