From e40b94713fabcceae78d926e9610d273365c1f0d Mon Sep 17 00:00:00 2001 From: Orjan Ameye Date: Mon, 7 Oct 2024 11:13:46 +0200 Subject: [PATCH] support symbolic arrays --- src/Symbolics_utils.jl | 9 ++++++++- test/runtests.jl | 1 + test/symbolic_utils.jl | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/symbolic_utils.jl diff --git a/src/Symbolics_utils.jl b/src/Symbolics_utils.jl index aae6e8fb..9a4fc4c8 100644 --- a/src/Symbolics_utils.jl +++ b/src/Symbolics_utils.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 1716d5b8..85901839 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -40,6 +40,7 @@ end include("powers.jl") include("harmonics.jl") include("fourier.jl") + include("symbolic_utils.jl") end @testset "IO" begin diff --git a/test/symbolic_utils.jl b/test/symbolic_utils.jl new file mode 100644 index 00000000..679807d4 --- /dev/null +++ b/test/symbolic_utils.jl @@ -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