Skip to content

Commit

Permalink
Merge pull request #1040 from JuliaSymbolics/myb/fix
Browse files Browse the repository at this point in the history
`variable(.., T=FnType)` and `at variables` should be consistent
  • Loading branch information
ChrisRackauckas authored Jan 18, 2024
2 parents 493e276 + 5cf5a06 commit 9303964
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ Also see `variables`.
"""
function variable(name, idx...; T=Real)
name_ij = Symbol(name, join(map_subscripts.(idx), "ˏ"))
v = Sym{T}(name_ij)
if T <: FnType
first(@variables $name_ij(..))
else
first(@variables $name_ij::T)
v = CallWithMetadata(v)
end
Num(setmetadata(v, VariableSource, (:variables, name_ij)))
end

##### Renaming #####
Expand Down
12 changes: 12 additions & 0 deletions test/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,15 @@ let
@test foo(x) isa Num
@test foo(unwrap(x)) isa BasicSymbolic
end

@variables t y(t)
yy = Symbolics.variable(:y, T = Symbolics.FnType{Tuple{Any}, Real})
yyy = yy(t)
@test isequal(yyy, y)
@test yyy isa Num
@test y isa Num
yy = Symbolics.variable(:y, T = Symbolics.FnType{Tuple, Real})
yyy = yy(t)
@test !isequal(yyy, y)
@variables y(..)
@test isequal(yyy, y(t))

0 comments on commit 9303964

Please sign in to comment.