Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix unnecessary oneunit call in get_unit #3108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/systems/unit_check.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ get_unit(x::SciMLBase.NullParameters) = unitless
get_unit(op::typeof(instream), args) = get_unit(args[1])

function get_unit(op, args) # Fallback
result = oneunit(op(get_unit.(args)...))
result = op(get_unit.(args)...)
try
get_unit(result)
catch
Expand Down
7 changes: 7 additions & 0 deletions test/units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,10 @@ sys = complete(sys)
@test isequal(ModelingToolkit.getdefault(sys.pt.a), sys.v * sys.τ)
@test ModelingToolkit.getdefault(sys.v) ≈ 2.0
@test ModelingToolkit.getdefault(sys.τ) ≈ 3.0

@testset "Issue#3017" begin
@constants c = 1 [unit = us"mol/nmol"]
@variables k(t) [unit = us"mol/nmol"]
@test ModelingToolkit.get_unit(c) == ModelingToolkit.get_unit(-c)
@test_nowarn NonlinearSystem([k ~ c], [k], []; name=:example)
end
Loading