Skip to content

Commit

Permalink
Merge pull request #1276 from AayushSabharwal/as/array-diff2term
Browse files Browse the repository at this point in the history
feat: improve `diff2term` for array symbolics
  • Loading branch information
ChrisRackauckas authored Sep 24, 2024
2 parents ee77c8a + a291fe3 commit 296a869
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ function diff2term(O, O_metadata::Union{Dict, Nothing, Base.ImmutableDict}=nothi
string(nameof(arguments(oldop)[1]))
elseif oldop == getindex
args = arguments(O)
opname = string(tosymbol(args[1]), "[", map(tosymbol, args[2:end])..., "]")
return Sym{symtype(O)}(Symbol(opname, d_separator, ds))
opname = string(tosymbol(args[1]))
return metadata(Sym{symtype(args[1])}(Symbol(opname, d_separator, ds)), metadata(args[1]))[args[2:end]...]
elseif oldop isa Function
return nothing
else
Expand Down
4 changes: 3 additions & 1 deletion test/arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ 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")
@test operation(v) == getindex
@test arguments(v)[2] == 2
@test getname(v) == getname(arguments(v)[1]) == Symbol("x(t)ˍtt")
end

@testset "getindex" begin
Expand Down
2 changes: 1 addition & 1 deletion test/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Dx = Differential(x)

@test Symbol(D(D(uu))) === Symbol("uuˍtt(t)")
@test Symbol(D(uuˍt)) === Symbol(D(D(uu)))
@test Symbol(D(v[2])) === Symbol("v(t)[2]ˍt")
@test Symbol(D(v[2])) === Symbol("getindex(var\"v(t)ˍt\", 2)")

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

Expand Down

0 comments on commit 296a869

Please sign in to comment.