Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle CallWithMetadata in var_from_nested_derivative #1300

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ end

function var_from_nested_derivative(x,i=0)
x = unwrap(x)
if issym(x)
if issym(x) || x isa CallWithMetadata
(x, i)
elseif iscall(x)
operation(x) isa Differential ?
Expand Down
11 changes: 10 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Symbolics
using Symbolics: symbolic_to_float
using Symbolics: symbolic_to_float, var_from_nested_derivative

@testset "get_variables" begin
@variables t x y z(t)
Expand Down Expand Up @@ -29,3 +29,12 @@ end
@test symbolic_to_float((big(1)//2)*√(279//4)) isa BigFloat
@test symbolic_to_float((-1//2)*√(279//4)) isa Float64
end

@testset "var_from_nested_derivative" begin
@variables t x(t) p(..)
D = Differential(t)
@test var_from_nested_derivative(x) == (x, 0)
@test var_from_nested_derivative(D(x)) == (x, 1)
@test var_from_nested_derivative(p) == (p, 0)
@test var_from_nested_derivative(D(p(x))) == (p(x), 1)
end
Loading