Skip to content

Commit 76bff8f

Browse files
Merge pull request #3015 from aml5600/aml5600/array-units-fix
Dispatch for symbolic array units
2 parents 70b0c23 + 8f2d885 commit 76bff8f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/systems/unit_check.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ get_unit(x::Real) = unitless
6969
get_unit(x::DQ.AbstractQuantity) = screen_unit(x)
7070
get_unit(x::AbstractArray) = map(get_unit, x)
7171
get_unit(x::Num) = get_unit(unwrap(x))
72+
get_unit(x::Symbolics.Arr) = get_unit(unwrap(x))
7273
get_unit(op::Differential, args) = get_unit(args[1]) / get_unit(op.x)
7374
get_unit(op::Difference, args) = get_unit(args[1]) / get_unit(op.t)
7475
get_unit(op::typeof(getindex), args) = get_unit(args[1])

test/dq_units.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,10 @@ let
239239
@test mm2units == MT.oneunit(mm2units)
240240
@test mmunits == mm2units
241241
end
242+
243+
# test for array variable units https://github.com/SciML/ModelingToolkit.jl/issues/3009
244+
let
245+
@variables x_vec(t)[1:3] [unit = u"1"] x_mat(t)[1:3, 1:3] [unit = u"1"]
246+
@test MT.get_unit(x_vec) == u"1"
247+
@test MT.get_unit(x_mat) == u"1"
248+
end

0 commit comments

Comments
 (0)