Skip to content

Commit 296a869

Browse files
Merge pull request #1276 from AayushSabharwal/as/array-diff2term
feat: improve `diff2term` for array symbolics
2 parents ee77c8a + a291fe3 commit 296a869

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ function diff2term(O, O_metadata::Union{Dict, Nothing, Base.ImmutableDict}=nothi
131131
string(nameof(arguments(oldop)[1]))
132132
elseif oldop == getindex
133133
args = arguments(O)
134-
opname = string(tosymbol(args[1]), "[", map(tosymbol, args[2:end])..., "]")
135-
return Sym{symtype(O)}(Symbol(opname, d_separator, ds))
134+
opname = string(tosymbol(args[1]))
135+
return metadata(Sym{symtype(args[1])}(Symbol(opname, d_separator, ds)), metadata(args[1]))[args[2:end]...]
136136
elseif oldop isa Function
137137
return nothing
138138
else

test/arrays.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ end
3636
@testset "getname" begin
3737
@variables t x(t)[1:4]
3838
v = Symbolics.lower_varname(unwrap(x[2]), unwrap(t), 2)
39-
@test getname(v) == Symbol("x(t)[2]ˍtt")
39+
@test operation(v) == getindex
40+
@test arguments(v)[2] == 2
41+
@test getname(v) == getname(arguments(v)[1]) == Symbol("x(t)ˍtt")
4042
end
4143

4244
@testset "getindex" begin

test/diff.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Dx = Differential(x)
1313

1414
@test Symbol(D(D(uu))) === Symbol("uuˍtt(t)")
1515
@test Symbol(D(uuˍt)) === Symbol(D(D(uu)))
16-
@test Symbol(D(v[2])) === Symbol("v(t)[2]ˍt")
16+
@test Symbol(D(v[2])) === Symbol("getindex(var\"v(t)ˍt\", 2)")
1717

1818
test_equal(a, b) = @test isequal(simplify(a), simplify(b))
1919

0 commit comments

Comments
 (0)