Skip to content

Commit

Permalink
Merge pull request #2428 from SciML/myb/var
Browse files Browse the repository at this point in the history
Consistent variable creation
  • Loading branch information
YingboMa authored Jan 25, 2024
2 parents eb33a8a + 90124ec commit 0e04e8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function generate_var!(dict, a, b, varclass;
vd isa Vector && (vd = first(vd))
vd[a] = Dict{Symbol, Any}()
var = if indices === nothing
Symbolics.variable(a, T = SymbolicUtils.FnType{Tuple{Real}, Real})(iv)
Symbolics.variable(a, T = SymbolicUtils.FnType{Tuple{Any}, Real})(iv)
else
vd[a][:size] = Tuple(lastindex.(indices))
first(@variables $a(iv)[indices...])
Expand Down
18 changes: 15 additions & 3 deletions test/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,9 @@ end
# Ensure that modules consisting MTKModels with component arrays and icons of
# `Expr` type and `unit` metadata can be precompiled.
module PrecompilationTest
using Unitful, Test, ModelingToolkit
push!(LOAD_PATH, joinpath(@__DIR__, "precompile_test"))
using Unitful, Test, ModelParsingPrecompile, ModelingToolkit
@testset "Precompile packages with MTKModels" begin
push!(LOAD_PATH, joinpath(@__DIR__, "precompile_test"))

using ModelParsingPrecompile: ModelWithComponentArray

@named model_with_component_array = ModelWithComponentArray()
Expand Down Expand Up @@ -539,3 +538,16 @@ end
@test Equation[ternary_true.ternary_parameter_true ~ 0] == equations(ternary_true)
@test Equation[ternary_false.ternary_parameter_false ~ 0] == equations(ternary_false)
end

_b = Ref{Any}()
@mtkmodel MyModel begin
@variables begin
x___(t) = 0
end
begin
_b[] = x___
end
end
@named m = MyModel()
@variables t x___(t)
@test isequal(x___, _b[])

0 comments on commit 0e04e8a

Please sign in to comment.