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

feat: use SymbolicUtils.@cache in occursin_info #1466

Merged
Merged
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ StaticArraysCore = "1.4"
SymPy = "2.2"
SymbolicIndexingInterface = "0.3.14"
SymbolicLimits = "0.2.2"
SymbolicUtils = "3.14"
SymbolicUtils = "3.17"
TermInterface = "2"
julia = "1.10"

Expand Down
10 changes: 9 additions & 1 deletion src/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ Base.hash(D::Differential, u::UInt) = hash(D.x, xor(u, 0xdddddddddddddddd))
_isfalse(occ::Bool) = occ === false
_isfalse(occ::Symbolic) = iscall(occ) && _isfalse(operation(occ))

SymbolicUtils.@cache function occursin_info(x::BasicSymbolic, expr::BasicSymbolic, fail::Bool = true)::Union{Bool, BasicSymbolic{Real}}
_occursin_info(x, expr, fail)
end

function occursin_info(x, expr, fail = true)
_occursin_info(x, expr, fail)
end

function _occursin_info(x, expr, fail = true)
if symtype(expr) <: AbstractArray
if fail
error("Differentiation with array expressions is not yet supported")
Expand Down Expand Up @@ -107,7 +115,7 @@ function occursin_info(x, expr, fail = true)
end
end

function occursin_info(x, expr::Sym, fail)
function _occursin_info(x, expr::Sym, fail)
if symtype(expr) <: AbstractArray && fail
error("Differentiation of expressions involving arrays and array variables is not yet supported.")
end
Expand Down
Loading