Skip to content

Commit dd721c2

Browse files
committed
Fix test and update docs
1 parent 5cda1f0 commit dd721c2

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

src/systems/abstractsystem.jl

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ end
258258
end
259259
end
260260

261-
rename(x::AbstractSystem, name) = @set x.name = name
261+
rename(x, name) = @set x.name = name
262262

263263
function Base.propertynames(sys::AbstractSystem; private = false)
264264
if private
@@ -875,38 +875,28 @@ end
875875
"""
876876
@named y = foo(x)
877877
@named y[1:10] = foo(x)
878-
@named y 1:10 i -> foo(x*i)
878+
@named y 1:10 i -> foo(x*i) # This is not recommended
879879
880-
Rewrite `@named y = foo(x)` to `y = foo(x; name=:y)`.
881-
882-
Rewrite `@named y[1:10] = foo(x)` to `y = map(i′->foo(x; name=Symbol(:y_, i′)), 1:10)`.
883-
884-
Rewrite `@named y 1:10 i -> foo(x*i)` to `y = map(i->foo(x*i; name=Symbol(:y_, i)), 1:10)`.
880+
Pass the LHS name to the model.
885881
886882
Examples:
887-
```julia
883+
```julia-repl
888884
julia> using ModelingToolkit
889885
890-
julia> foo(i; name) = i, name
886+
julia> foo(i; name) = (; i, name)
891887
foo (generic function with 1 method)
892888
893889
julia> x = 41
894890
41
895891
896892
julia> @named y = foo(x)
897-
(41, :y)
893+
(i = 41, name = :y)
898894
899895
julia> @named y[1:3] = foo(x)
900-
3-element Vector{Tuple{Int64, Symbol}}:
901-
(41, :y_1)
902-
(41, :y_2)
903-
(41, :y_3)
904-
905-
julia> @named y 1:3 i -> foo(x*i)
906-
3-element Vector{Tuple{Int64, Symbol}}:
907-
(41, :y_1)
908-
(82, :y_2)
909-
(123, :y_3)
896+
3-element Vector{NamedTuple{(:i, :name), Tuple{Int64, Symbol}}}:
897+
(i = 41, name = :y_1)
898+
(i = 41, name = :y_2)
899+
(i = 41, name = :y_3)
910900
```
911901
"""
912902
macro named(expr)

test/direct.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ if VERSION >= v"1.5"
252252
@test collect(cool_name) == [pp; :ff => ff]
253253
end
254254

255-
foo(i; name) = i, name
255+
foo(i; name) = (; i, name)
256256
@named goo[1:3] = foo(10)
257-
@test isequal(goo, [(10, Symbol(:goo_, i)) for i in 1:3])
257+
@test isequal(goo, [(i = 10, name = Symbol(:goo_, i)) for i in 1:3])
258258
@named koo 1:3 i->foo(10i)
259-
@test isequal(koo, [(10i, Symbol(:koo_, i)) for i in 1:3])
259+
@test isequal(koo, [(i = 10i, name = Symbol(:koo_, i)) for i in 1:3])

test/odesystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ eqs = [D(x) ~ σ * (y - x),
1919

2020
ModelingToolkit.toexpr.(eqs)[1]
2121
@named de = ODESystem(eqs; defaults = Dict(x => 1))
22+
@named des[1:3] = ODESystem(eqs)
23+
@test length(unique(x -> ModelingToolkit.get_tag(x), des)) == 1
2224
@test eval(toexpr(de)) == de
2325
@test hash(deepcopy(de)) == hash(de)
2426

0 commit comments

Comments
 (0)