Skip to content

Commit

Permalink
Merge pull request #755 from JuliaSymbolics/myb/getname
Browse files Browse the repository at this point in the history
Handle getname edge case
  • Loading branch information
YingboMa authored Oct 5, 2022
2 parents 54b583c + db1e1d0 commit 1b50175
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ const _fail = Dict()
_getname(x, _) = nameof(x)
_getname(x::Symbol, _) = x
function _getname(x::Symbolic, val)
issym(x) && return nameof(x)
if istree(x) && issym(operation(x))
return nameof(operation(x))
end
Expand Down
8 changes: 7 additions & 1 deletion test/arrays.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Symbolics
using SymbolicUtils, Test
using Symbolics: symtype, shape, wrap, unwrap, Unknown, Arr, arrterm, jacobian, @variables, value, get_variables, @arrayop
using Symbolics: symtype, shape, wrap, unwrap, Unknown, Arr, arrterm, jacobian, @variables, value, get_variables, @arrayop, getname
using Base: Slice
using SymbolicUtils: Sym, term, operation

Expand Down Expand Up @@ -29,6 +29,12 @@ using SymbolicUtils: Sym, term, operation
@test isequal(get_variables(2x[1]), [x[1]])
end

@testset "getname" begin
@variables t x(t)[1:4]
v = Symbolics.lower_varname(unwrap(x[2]), unwrap(t), 2)
@test getname(v) == Symbol("x(t)[2]ˍtt")
end

@testset "getindex" begin
@variables X[1:5, 1:5] Y[1:5, 1:5]

Expand Down

0 comments on commit 1b50175

Please sign in to comment.