Skip to content

Commit ddb250c

Browse files
fix: fix getguess for array variables
1 parent a9f4251 commit ddb250c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/variables.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ end
456456
## Guess ======================================================================
457457
struct VariableGuess end
458458
Symbolics.option_to_metadata_type(::Val{:guess}) = VariableGuess
459-
getguess(x::Num) = getguess(Symbolics.unwrap(x))
459+
getguess(x::Union{Num, Symbolics.Arr}) = getguess(Symbolics.unwrap(x))
460460

461461
"""
462462
getguess(x)
@@ -469,8 +469,6 @@ Create variables with a guess like this
469469
```
470470
"""
471471
function getguess(x)
472-
p = Symbolics.getparent(x, nothing)
473-
p === nothing || (x = p)
474472
Symbolics.getmetadata(x, VariableGuess, nothing)
475473
end
476474

test/test_variable_metadata.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ using ModelingToolkit
1616
@test hasguess(y) === true
1717
@test ModelingToolkit.dump_variable_metadata(y).guess == 0
1818

19+
# Issue#2653
20+
@variables y[1:3] [guess = ones(3)]
21+
@test getguess(y) == ones(3)
22+
@test hasguess(y) === true
23+
@test ModelingToolkit.dump_variable_metadata(y).guess == ones(3)
24+
25+
for i in 1:3
26+
@test getguess(y[i]) == 1.0
27+
@test hasguess(y[i]) === true
28+
@test ModelingToolkit.dump_variable_metadata(y[i]).guess == 1.0
29+
end
30+
1931
@variables y
2032
@test hasguess(y) === false
2133
@test !haskey(ModelingToolkit.dump_variable_metadata(y), :guess)

0 commit comments

Comments
 (0)