Skip to content

Commit

Permalink
Merge pull request #3015 from aml5600/aml5600/array-units-fix
Browse files Browse the repository at this point in the history
Dispatch for symbolic array units
  • Loading branch information
ChrisRackauckas authored Sep 8, 2024
2 parents 70b0c23 + 8f2d885 commit 76bff8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/systems/unit_check.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ get_unit(x::Real) = unitless
get_unit(x::DQ.AbstractQuantity) = screen_unit(x)
get_unit(x::AbstractArray) = map(get_unit, x)
get_unit(x::Num) = get_unit(unwrap(x))
get_unit(x::Symbolics.Arr) = get_unit(unwrap(x))
get_unit(op::Differential, args) = get_unit(args[1]) / get_unit(op.x)
get_unit(op::Difference, args) = get_unit(args[1]) / get_unit(op.t)
get_unit(op::typeof(getindex), args) = get_unit(args[1])
Expand Down
7 changes: 7 additions & 0 deletions test/dq_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,10 @@ let
@test mm2units == MT.oneunit(mm2units)
@test mmunits == mm2units
end

# test for array variable units https://github.com/SciML/ModelingToolkit.jl/issues/3009
let
@variables x_vec(t)[1:3] [unit = u"1"] x_mat(t)[1:3, 1:3] [unit = u"1"]
@test MT.get_unit(x_vec) == u"1"
@test MT.get_unit(x_mat) == u"1"
end

0 comments on commit 76bff8f

Please sign in to comment.