Skip to content

Commit

Permalink
support symbolic arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
oameye committed Oct 7, 2024
1 parent 2abbad3 commit e40b947
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Symbolics_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ end
"Return the name of a variable (excluding independent variables)"
function var_name(x::Num)
var = Symbolics._toexpr(x)
return var isa Expr ? String(var.args[1]) : String(var)
while var isa Expr
try
var = var.args[1]
catch
break
end
end
return String(var)
end
# var_name(x::Term) = String(Symbolics._toexpr(x).args[1])
var_name(x::Sym) = String(x.name)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ end
include("powers.jl")
include("harmonics.jl")
include("fourier.jl")
include("symbolic_utils.jl")
end

@testset "IO" begin
Expand Down
6 changes: 6 additions & 0 deletions test/symbolic_utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@testset "Symbolics arrays" begin
using Symbolics, HarmonicBalance
@variables x[1:2]
vars = Symbolics.scalarize(x)
HarmonicBalance.var_name(vars[1])
end

0 comments on commit e40b947

Please sign in to comment.