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

Get tests to pass in new TermInterface #587

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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/SymbolicUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using SymbolicIndexingInterface
import Base: +, -, *, /, //, \, ^, ImmutableDict
using ConstructionBase
using TermInterface
import TermInterface: iscall, isexpr, issym, symtype, head, children, operation, arguments
import TermInterface: iscall, isexpr, issym, symtype, head, children, operation, arguments, metadata

function similarterm end
include("types.jl")
Expand Down
13 changes: 8 additions & 5 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function arguments(x::BasicSymbolic)
end
return args
end
children(x::BasicSymbolic) = arguments(x)
0x0f0f0f marked this conversation as resolved.
Show resolved Hide resolved
function unsorted_arguments(x::BasicSymbolic)
@compactified x::BasicSymbolic begin
Term => return x.arguments
Expand Down Expand Up @@ -546,10 +547,12 @@ different type than `t`, because `f` also influences the result.
- The `symtype` of the resulting term. Best effort will be made to set the symtype of the
resulting similar term to this type.
"""
similarterm(t::Symbolic, f, args, symtype; metadata=nothing) =
maketerm(typeof(t), f, args, _promote_symtype(f, args), metadata)
similarterm(t::BasicSymbolic, f, args,
symtype; metadata=nothing) = basic_similarterm(t, f, args, symtype; metadata=metadata)
similarterm(t::Symbolic, f, args; metadata=nothing) =
maketerm(typeof(t), f, args, _promote_symtype(f, args); metadata)
similarterm(t::BasicSymbolic, f, args, symtype; metadata=nothing) =
maketerm(typeof(t), f, args, symtype; metadata=metadata)
maketerm(T::Type{<:Symbolic}, f, args, symtype; metadata=nothing) =
basic_similarterm(T, f, args, symtype; metadata=metadata)

function basic_similarterm(t, f, args, stype; metadata=nothing)
if f isa Symbol
Expand Down Expand Up @@ -813,7 +816,7 @@ function show_term(io::IO, t)
show_pow(io, args)
elseif f === (getindex)
show_ref(io, f, args)
elseif f === (identity) && !issym(args[1]) && iscall(args[1])
elseif f === (identity) && !issym(args[1]) && !iscall(args[1])
0x0f0f0f marked this conversation as resolved.
Show resolved Hide resolved
show(io, args[1])
else
show_call(io, f, args)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ macro matchable(expr)
$expr
SymbolicUtils.iscall(::$name) = true
SymbolicUtils.operation(::$name) = $name
SymbolicUtils.arguments(x::$name) = getfield.((x,), ($(QuoteNode.(fields)...),))
SymbolicUtils.children(x::$name) = getfield.((x,), ($(QuoteNode.(fields)...),))
0x0f0f0f marked this conversation as resolved.
Show resolved Hide resolved
Base.length(x::$name) = $(length(fields) + 1)
SymbolicUtils.similarterm(x::$name, f, args, type; kw...) = f(args...)
end |> esc
Expand Down