diff --git a/src/Symbolics.jl b/src/Symbolics.jl index 2b6a45912..a9bcbaa37 100644 --- a/src/Symbolics.jl +++ b/src/Symbolics.jl @@ -28,9 +28,9 @@ import DomainSets: Domain using TermInterface import TermInterface: maketerm, iscall, operation, arguments, metadata -import SymbolicUtils: Term, Add, Mul, Pow, Sym, Div, BasicSymbolic, -FnType, @rule, Rewriters, substitute, symtype, -promote_symtype, isadd, ismul, ispow, isterm, issym, isdiv +import SymbolicUtils: BasicSymbolic, FnType, @rule, Rewriters, substitute, symtype, + promote_symtype, isadd, ismul, ispow, isterm, issym, isdiv, _Sym, + _Term, get_dict, isconst, get_val using SymbolicUtils.Code diff --git a/src/array-lib.jl b/src/array-lib.jl index e33abaded..f0f4f1783 100644 --- a/src/array-lib.jl +++ b/src/array-lib.jl @@ -20,6 +20,13 @@ end function Base.getindex(x::SymArray, idx...) idx = unwrap.(idx) + idx = map(idx) do i + if isconst(i) + get_val(i) + else + i + end + end meta = metadata(unwrap(x)) if iscall(x) && (op = operation(x)) isa Operator args = arguments(x) @@ -32,7 +39,7 @@ function Base.getindex(x::SymArray, idx...) throw(BoundsError(x, idx)) end end - res = Term{eltype(symtype(x))}(getindex, [x, Tuple(ii)...]; metadata = meta) + res = _Term(eltype(symtype(x)), getindex, [x, Tuple(ii)...]; metadata = meta) elseif all(i -> symtype(i) <: Integer, idx) shape(x) !== Unknown() && @boundscheck begin if length(idx) > 1 @@ -43,7 +50,7 @@ function Base.getindex(x::SymArray, idx...) end end end - res = Term{eltype(symtype(x))}(getindex, [x, idx...]; metadata = meta) + res = _Term(eltype(symtype(x)), getindex, [x, idx...]; metadata = meta) elseif length(idx) == 1 && symtype(first(idx)) <: CartesianIndex i = first(idx) ii = i isa CartesianIndex ? Tuple(i) : arguments(i) @@ -70,7 +77,7 @@ function Base.getindex(x::SymArray, idx...) end end - term = Term{Any}(getindex, [x, idx...]; metadata = meta) + term = _Term(Any, getindex, [x, idx...]; metadata = meta) T = eltype(symtype(x)) N = ndims(x) - count(i -> symtype(i) <: Integer, idx) res = ArrayOp(atype(symtype(x)){T,N}, @@ -197,12 +204,12 @@ function Broadcast.copy(bc::Broadcast.Broadcasted{SymBroadcast}) # then you get pairs, and index matcher cannot # recurse into pairs Atype = propagate_atype(broadcast, bc.f, args...) - args = map(x -> x isa Base.RefValue ? Term{Any}(Ref, [x[]]) : x, args) + args = map(x -> x isa Base.RefValue ? _Term(Any, Ref, [x[]]) : x, args) ArrayOp(Atype{symtype(expr),ndim}, (subscripts...,), expr, +, - Term{Any}(broadcast, [bc.f, args...])) + _Term(Any, broadcast, [bc.f, args...])) end # On wrapper: @@ -270,15 +277,15 @@ function symeltype(A) end # TODO: add more such methods function getindex(A::AbstractArray, i::Symbolic{<:Integer}, ii::Symbolic{<:Integer}...) - Term{symeltype(A)}(getindex, [A, i, ii...]) + _Term(symeltype(A), getindex, [A, i, ii...]) end function getindex(A::AbstractArray, i::Int, j::Symbolic{<:Integer}) - Term{symeltype(A)}(getindex, [A, i, j]) + _Term(symeltype(A), getindex, [A, i, j]) end function getindex(A::AbstractArray, j::Symbolic{<:Integer}, i::Int) - Term{symeltype(A)}(getindex, [A, j, i]) + _Term(symeltype(A), getindex, [A, j, i]) end function getindex(A::Arr, i::Int, j::Symbolic{<:Integer}) @@ -341,7 +348,7 @@ function _map(f, x, xs...) (idx...,), expr, +, - Term{Any}(map, [f, x, xs...])) + _Term(Any, map, [f, x, xs...])) end @inline _mapreduce(f, g, x, dims, kw) = mapreduce(f, g, x; dims=dims, kw...) @@ -359,7 +366,7 @@ end expr = f(x[idx...]) T = symtype(g(expr, expr)) if dims === (:) - return Term{T}(_mapreduce, [f, g, x, dims, (kw...,)]) + return _Term(T, _mapreduce, [f, g, x, dims, (kw...,)]) end Atype = propagate_atype(_mapreduce, f, g, x, dims, (kw...,)) @@ -367,7 +374,7 @@ end (out_idx...,), expr, g, - Term{Any}(_mapreduce, [f, g, x, dims, (kw...,)])) + _Term(Any, _mapreduce, [f, g, x, dims, (kw...,)])) end false for (ff, opts) in [sum => (identity, +, false), diff --git a/src/arrays.jl b/src/arrays.jl index ac65fb616..f72a3f4ad 100644 --- a/src/arrays.jl +++ b/src/arrays.jl @@ -181,9 +181,9 @@ macro arrayop(output_idx, expr, options...) end |> esc end -const SymArray = Union{ArrayOp, Symbolic{<:AbstractArray}} -const SymMat = Union{ArrayOp{<:AbstractMatrix}, Symbolic{<:AbstractMatrix}} -const SymVec = Union{ArrayOp{<:AbstractVector}, Symbolic{<:AbstractVector}} +const SymArray = Union{ArrayOp, BasicSymbolic{<:AbstractArray}} +const SymMat = Union{ArrayOp{<:AbstractMatrix}, BasicSymbolic{<:AbstractMatrix}} +const SymVec = Union{ArrayOp{<:AbstractVector}, BasicSymbolic{<:AbstractVector}} ### Propagate ### # @@ -415,7 +415,7 @@ function array_term(f, args...; end end S = container_type{eltype, ndims} - setmetadata(Term{S}(f, Any[args...]), ArrayShapeCtx, shape) + setmetadata(_Term(S, f, Any[args...]), ArrayShapeCtx, shape) end """ @@ -504,7 +504,7 @@ const ArrayLike{T,N} = Union{ ArrayOp{AbstractArray{T,N}}, Symbolic{AbstractArray{T,N}}, Arr{T,N}, - SymbolicUtils.Term{AbstractArray{T, N}} + SymbolicUtils.BasicSymbolic{AbstractArray{T, N}} } # Like SymArray but includes Arr and Term{Arr} unwrap(x::Arr) = x.value @@ -688,7 +688,7 @@ function scalarize_op(f::typeof(_det), arr) end @wrapped function LinearAlgebra.det(x::AbstractMatrix; laplace=true) - Term{eltype(x)}(_det, [x, laplace]) + _Term(eltype(x), _det, [x, laplace]) end false @@ -1055,7 +1055,7 @@ function get_inputs(x::ArrayOp) end function similar_arrayvar(ex, name) - Sym{symtype(ex)}(name) #TODO: shape? + _Sym(symtype(ex), name) #TODO: shape? end function reset_to_one(range) @@ -1064,7 +1064,7 @@ function reset_to_one(range) end function reset_sym(i) - Sym{Int}(Symbol(nameof(i), "′")) + _Sym(Int, Symbol(nameof(i), "′")) end function inplace_expr(x::ArrayOp, outsym = :_out, intermediates = nothing) diff --git a/src/build_function.jl b/src/build_function.jl index 06b433b1c..ca2d91f81 100644 --- a/src/build_function.jl +++ b/src/build_function.jl @@ -310,7 +310,7 @@ function _build_function(target::JuliaTarget, rhss::AbstractArray, args...; oop_expr = wrap_code[1](oop_expr) end - out = Sym{Any}(:ˍ₋out) + out = _Sym(Any, :ˍ₋out) ip_body = if iip postprocess_fbody(set_array(parallel, dargs, @@ -553,13 +553,13 @@ _set_array(out, outputidxs, rhs, checkbounds, skipzeros, cse) = rhs function vars_to_pairs(name,vs::Union{Tuple, AbstractArray}, symsdict=Dict()) vs_names = tosymbol.(vs) for (v,k) in zip(vs_names, vs) - symsdict[k] = Sym{symtype(k)}(v) + symsdict[k] = _Sym(symtype(k), v) end exs = [:($name[$i]) for (i, u) ∈ enumerate(vs)] vs_names,exs end function vars_to_pairs(name,vs, symsdict) - symsdict[vs] = Sym{symtype(vs)}(tosymbol(vs)) + symsdict[vs] = _Sym(symtype(vs), tosymbol(vs)) [tosymbol(vs)], [name] end diff --git a/src/complex.jl b/src/complex.jl index dc0ab983a..e4ed2cae3 100644 --- a/src/complex.jl +++ b/src/complex.jl @@ -48,7 +48,7 @@ function Base.show(io::IO, a::Complex{Num}) return print(io, arguments(rr)[1]) end - i = Sym{Real}(:im) + i = _Sym(Real, :im) show(io, real(a) + i * imag(a)) end diff --git a/src/diff.jl b/src/diff.jl index 891e2cde2..f7d98c909 100644 --- a/src/diff.jl +++ b/src/diff.jl @@ -103,11 +103,11 @@ function occursin_info(x, expr, fail = true) if all(_isfalse, args) return false end - Term{Real}(true, args) + _Term(Real, true, args) end end -function occursin_info(x, expr::Sym, fail) +function occursin_info(x, expr::BasicSymbolic, fail) if symtype(expr) <: AbstractArray && fail error("Differentiation of expressions involving arrays and array variables is not yet supported.") end @@ -139,7 +139,7 @@ function recursive_hasoperator(op, O) return true else if isadd(O) || ismul(O) - any(recursive_hasoperator(op), keys(O.dict)) + any(recursive_hasoperator(op), keys(get_dict(O))) elseif ispow(O) recursive_hasoperator(op)(O.base) || recursive_hasoperator(op)(O.exp) elseif isdiv(O) @@ -636,7 +636,7 @@ end isidx(x) = x isa TermCombination -basic_mkterm(t, g, args, m) = metadata(Term{Any}(g, args), m) +basic_mkterm(t, g, args, m) = metadata(_Term(Any, g, args), m) let # we do this in a let block so that Revise works on the list of rules diff --git a/src/difference.jl b/src/difference.jl index b3921d01d..a7366c316 100644 --- a/src/difference.jl +++ b/src/difference.jl @@ -24,7 +24,7 @@ struct Difference <: Operator update::Bool Difference(t; dt, update=false) = new(value(t), dt, update) end -(D::Difference)(t) = Term{symtype(t)}(D, [t]) +(D::Difference)(t) = _Term(symtype(t), D, [t]) (D::Difference)(t::Num) = Num(D(value(t))) SymbolicUtils.promote_symtype(::Difference, t) = t """ diff --git a/src/extra_functions.jl b/src/extra_functions.jl index 0a78b96f7..569738fa6 100644 --- a/src/extra_functions.jl +++ b/src/extra_functions.jl @@ -8,7 +8,7 @@ function _binomial(nothing, n, k) end), unwrapped_args)) Base.binomial(unwrapped_args...) else - SymbolicUtils.Term{Int}(Base.binomial, unwrapped_args) + _Term(Int, Base.binomial, unwrapped_args) end if typeof.(args) == typeof.(unwrapped_args) return res diff --git a/src/integral.jl b/src/integral.jl index ffc625c7f..e3229550a 100644 --- a/src/integral.jl +++ b/src/integral.jl @@ -4,7 +4,7 @@ struct Integral{T <: Symbolics.VarDomainPairing} <: Function Integral(domain) = new{typeof(domain)}(domain) end -(I::Integral)(x) = Term{SymbolicUtils.symtype(x)}(I, [x]) +(I::Integral)(x) = _Term(SymbolicUtils.symtype(x), I, [x]) (I::Integral)(x::Num) = Num(I(Symbolics.value(x))) SymbolicUtils.promote_symtype(::Integral, x) = x diff --git a/src/latexify_recipes.jl b/src/latexify_recipes.jl index 7f801b6c9..4a17c9afa 100644 --- a/src/latexify_recipes.jl +++ b/src/latexify_recipes.jl @@ -142,7 +142,7 @@ function _toexpr(O) denom = Any[] # We need to iterate over each term in m, ignoring the numeric coefficient. - # This iteration needs to be stable, so we can't iterate over m.dict. + # This iteration needs to be stable, so we can't iterate over get_dict(m). for term in Iterators.drop(sorted_arguments(m), isone(m.coeff) ? 0 : 1) if !ispow(term) push!(numer, _toexpr(term)) @@ -260,7 +260,7 @@ function diffdenom(e) elseif ismul(e) LaTeXString(prod( "\\mathrm{d}$(k)$(isone(v) ? "" : "^{$v}")" - for (k, v) in e.dict + for (k, v) in get_dict(e) )) else e diff --git a/src/num.jl b/src/num.jl index 5d0a3bac0..270b04fa9 100644 --- a/src/num.jl +++ b/src/num.jl @@ -97,7 +97,7 @@ Base.show(io::IO, n::Num) = show_numwrap[] ? print(io, :(Num($(value(n))))) : Ba Base.promote_rule(::Type{<:Number}, ::Type{<:Num}) = Num Base.promote_rule(::Type{BigFloat}, ::Type{<:Num}) = Num Base.promote_rule(::Type{<:Symbolic{<:Number}}, ::Type{<:Num}) = Num -function Base.getproperty(t::Union{Add, Mul, Pow, Term}, f::Symbol) +function Base.getproperty(t::BasicSymbolic, f::Symbol) if f === :op Base.depwarn("`x.op` is deprecated, use `operation(x)` instead", :getproperty, force=true) operation(t) diff --git a/src/parsing.jl b/src/parsing.jl index 4d89a3109..84a2784f2 100644 --- a/src/parsing.jl +++ b/src/parsing.jl @@ -81,7 +81,7 @@ function parse_expr_to_symbolic(ex, mod::Module) else x = parse_expr_to_symbolic(ex.args[1], mod) ys = parse_expr_to_symbolic.(ex.args[2:end],(mod,)) - return Term{Real}(x,[ys...]) + return _Term(Real, x,[ys...]) end end end diff --git a/src/register.jl b/src/register.jl index ea9394891..6ae862594 100644 --- a/src/register.jl +++ b/src/register.jl @@ -35,7 +35,7 @@ macro register_symbolic(expr, define_promotion = true, Ts = :([]), wrap_arrays = res = if !any($is_symbolic_or_array_of_symbolic, unwrapped_args) $f(unwrapped_args...) # partial-eval if all args are unwrapped else - $Term{$ret_type}($f, unwrapped_args) + $_Term($ret_type, $f, unwrapped_args) end if typeof.(args) == typeof.(unwrapped_args) return res @@ -115,7 +115,7 @@ function register_array_symbolic(f, ftype, argnames, Ts, ret_type, partial_defs elseif $ret_type == nothing || ($ret_type <: AbstractArray) $array_term($(Expr(:parameters, [Expr(:kw, k, v) for (k, v) in defs]...)), $f, unwrapped_args...) else - $Term{$ret_type}($f, unwrapped_args) + $_Term($ret_type, $f, unwrapped_args) end if typeof.(args) == typeof.(unwrapped_args) diff --git a/src/semipoly.jl b/src/semipoly.jl index a717541db..168c921a4 100644 --- a/src/semipoly.jl +++ b/src/semipoly.jl @@ -60,7 +60,7 @@ end # return a dictionary of exponents with respect to variables function pdegrees(x) if ismul(x) - return x.dict + return get_dict(x) elseif isdiv(x) num_dict = pdegrees(x.num) den_dict = pdegrees(x.den) @@ -136,7 +136,7 @@ Base.:nameof(m::SemiMonomial) = Symbol(:SemiMonomial, m.p, m.coeff) isop(x, op) = iscall(x) && operation(x) === op isop(op) = Base.Fix2(isop, op) -simpleterm(T, f, args, m) = Term{SymbolicUtils._promote_symtype(f, args)}(f, args) +simpleterm(T, f, args, m) = _Term(SymbolicUtils._promote_symtype(f, args), f, args) function mark_and_exponentiate(expr, vars) # Step 1 @@ -197,16 +197,16 @@ function mark_vars(expr, vars) if op === (^) || op == (/) args = arguments(expr) @assert length(args) == 2 - return Term{symtype(expr)}(op, map(mark_vars(vars), args)) + return _Term(symtype(expr), op, map(mark_vars(vars), args)) end args = arguments(expr) if op === (+) || op === (*) - return Term{symtype(expr)}(op, map(mark_vars(vars), args)) + return _Term(symtype(expr), op, map(mark_vars(vars), args)) elseif length(args) == 1 if op == sqrt return mark_vars(args[1]^(1//2), vars) elseif linearity_1(op) - return Term{symtype(expr)}(op, mark_vars(args[1], vars)) + return _Term(symtype(expr), op, mark_vars(args[1], vars)) end end return SemiMonomial(1, expr) diff --git a/src/utils.jl b/src/utils.jl index 2167bed06..4d4cda076 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -71,12 +71,14 @@ end get_variables!(vars, e::Number, varlist=nothing) = vars function get_variables!(vars, e::Symbolic, varlist=nothing) - if is_singleton(e) - if isnothing(varlist) || any(isequal(e), varlist) - push!(vars, e) + if !isconst(e) + if is_singleton(e) + if isnothing(varlist) || any(isequal(e), varlist) + push!(vars, e) + end + else + foreach(x -> get_variables!(vars, x, varlist), arguments(e)) end - else - foreach(x -> get_variables!(vars, x, varlist), arguments(e)) end return (vars isa AbstractVector) ? unique!(vars) : vars end @@ -132,7 +134,7 @@ function diff2term(O, O_metadata::Union{Dict, Nothing, Base.ImmutableDict}=nothi elseif oldop == getindex args = arguments(O) opname = string(tosymbol(args[1])) - return metadata(Sym{symtype(args[1])}(Symbol(opname, d_separator, ds)), metadata(args[1]))[args[2:end]...] + return metadata(_Sym(symtype(args[1]), Symbol(opname, d_separator, ds)), metadata(args[1]))[args[2:end]...] elseif oldop isa Function return nothing else @@ -227,7 +229,7 @@ function makesubscripts(n) map(1:n) do i repeats = ceil(Int, i / m) c = set[(i-1) % m + 1] - Sym{Int}(Symbol(join([c for _ in 1:repeats], ""))) + _Sym(Int, Symbol(join([c for _ in 1:repeats], ""))) end end @@ -279,9 +281,9 @@ function degree(p, sym=nothing) return Int(isequal(p, sym)) end elseif ismul(p) - return sum(degree(k^v, sym) for (k, v) in zip(keys(p.dict), values(p.dict))) + return sum(degree(k^v, sym) for (k, v) in zip(keys(get_dict(p)), values(get_dict(p)))) elseif isadd(p) - return maximum(degree(key, sym) for key in keys(p.dict)) + return maximum(degree(key, sym) for key in keys(get_dict(p))) elseif ispow(p) return p.exp * degree(p.base, sym) elseif isdiv(p) @@ -344,7 +346,7 @@ function coeff(p, sym=nothing) if sym===nothing p.coeff else - sum(coeff(k, sym) * v for (k, v) in p.dict) + sum(coeff(k, sym) * v for (k, v) in get_dict(p)) end elseif ismul(p) args = arguments(p) diff --git a/src/variable.jl b/src/variable.jl index b5230f07b..b53b10b66 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -1,4 +1,4 @@ -using SymbolicUtils: FnType, Sym, metadata +using SymbolicUtils: FnType, metadata using Setfield const IndexMap = Dict{Char,Char}( @@ -183,7 +183,7 @@ function construct_dep_array_vars(macroname, lhs, type, call_args, indices, val, end end argtypes = arg_types_from_call_args(call_args) - ex = :($CallWithMetadata($Sym{$FnType{$argtypes, Array{$type, $ndim}, $(fntype...)}}($_vname))) + ex = :($CallWithMetadata($_Sym($FnType{$argtypes, Array{$type, $ndim}, $(fntype...)}, $_vname))) else vname = lhs if isruntime @@ -191,7 +191,7 @@ function construct_dep_array_vars(macroname, lhs, type, call_args, indices, val, else _vname = Meta.quot(vname) end - ex = :($Sym{$FnType{Tuple, Array{$type, $ndim}}}($_vname)(map($unwrap, ($(call_args...),))...)) + ex = :($_Sym($FnType{Tuple, Array{$type, $ndim}}, $_vname)(map($unwrap, ($(call_args...),))...)) end ex = :($setmetadata($ex, $ArrayShapeCtx, ($(indices...),))) @@ -336,16 +336,16 @@ end function construct_var(macroname, var_name, type, call_args, val, prop) expr = if call_args === nothing - :($Sym{$type}($var_name)) + :($_Sym($type, $var_name)) elseif call_args_are_function(call_args) # function syntax is (x::TFunc)(.. or ::TArg1, ::TArg2)::TRet # .. is Vararg # (..)::ArgT is Vararg{ArgT} var_name, fntype = function_name_and_type(var_name) argtypes = arg_types_from_call_args(call_args) - :($CallWithMetadata($Sym{$FnType{$argtypes, $type, $(fntype...)}}($var_name))) + :($CallWithMetadata($_Sym($FnType{$argtypes, $type, $(fntype...)}, $var_name))) else - :($Sym{$FnType{NTuple{$(length(call_args)), Any}, $type}}($var_name)($(map(x->:($value($x)), call_args)...))) + :($_Sym($FnType{NTuple{$(length(call_args)), Any}, $type}, $var_name)($(map(x->:($value($x)), call_args)...))) end if val !== nothing @@ -367,19 +367,19 @@ function _construct_array_vars(macroname, var_name, type, call_args, val, prop, need_scalarize = false expr = if call_args === nothing - ex = :($Sym{Array{$type, $ndim}}($var_name)) + ex = :($_Sym(Array{$type, $ndim}, $var_name)) :($setmetadata($ex, $ArrayShapeCtx, ($(indices...),))) elseif call_args_are_function(call_args) need_scalarize = true var_name, fntype = function_name_and_type(var_name) argtypes = arg_types_from_call_args(call_args) - ex = :($Sym{Array{$FnType{$argtypes, $type, $(fntype...)}, $ndim}}($var_name)) + ex = :($_Sym(Array{$FnType{$argtypes, $type, $(fntype...)}, $ndim}, $var_name)) ex = :($setmetadata($ex, $ArrayShapeCtx, ($(indices...),))) :($map($CallWithMetadata, $ex)) else # [(R -> R)(R) ....] need_scalarize = true - ex = :($Sym{Array{$FnType{Tuple, $type}, $ndim}}($var_name)) + ex = :($_Sym(Array{$FnType{Tuple, $type}, $ndim}, $var_name)) ex = :($setmetadata($ex, $ArrayShapeCtx, ($(indices...),))) :($map($CallWith(($(call_args...),)), $ex)) end @@ -670,7 +670,7 @@ Also see `variables`. """ function variable(name, idx...; T=Real) name_ij = Symbol(name, join(map_subscripts.(idx), "ˏ")) - v = Sym{T}(name_ij) + v = _Sym(T, name_ij) if T <: FnType v = CallWithMetadata(v) end @@ -747,9 +747,3 @@ function (::Type{Variable{T}})(s, i...) where {T} end (::Type{Variable})(s, i...) = Variable{Real}(s, i...) - -function (::Type{Sym{T}})(s, x, i...) where {T} - Base.depwarn("Sym{T}(name, x, idx...) is deprecated, use variable(name, x, idx...; T=T)", :Variable, force=true) - variable(s, x, i...; T=T) -end -(::Type{Sym})(s, x, i...) = Sym{Real}(s, x, i...) diff --git a/test/arrays.jl b/test/arrays.jl index 27041d846..9ba007250 100644 --- a/test/arrays.jl +++ b/test/arrays.jl @@ -2,7 +2,7 @@ using Symbolics using SymbolicUtils, Test using Symbolics: symtype, shape, wrap, unwrap, Unknown, Arr, array_term, jacobian, @variables, value, get_variables, @arrayop, getname, metadata, scalarize using Base: Slice -using SymbolicUtils: Sym, term, operation +using SymbolicUtils: _Sym, term, operation import LinearAlgebra: dot struct TestMetaT end @@ -22,8 +22,8 @@ Symbolics.option_to_metadata_type(::Val{:test_meta}) = TestMetaT B = A[3:5] @test axes(B) == (Slice(1:3),) - i = Sym{Int}(:i) - j = Sym{Int}(:j) + i = _Sym(Int, :i) + j = _Sym(Int, :j) @test symtype(X[i, j]) == Real @test symtype(X[1, j]) == Real @@ -37,7 +37,7 @@ end @variables t x(t)[1:4] v = Symbolics.lower_varname(unwrap(x[2]), unwrap(t), 2) @test operation(v) == getindex - @test arguments(v)[2] == 2 + @test SymbolicUtils.get_val(arguments(v)[2]) == 2 @test getname(v) == getname(arguments(v)[1]) == Symbol("x(t)ˍtt") end diff --git a/test/macro.jl b/test/macro.jl index 0dd82728b..8b9cff3ef 100644 --- a/test/macro.jl +++ b/test/macro.jl @@ -1,12 +1,12 @@ using Symbolics import Symbolics: CallWithMetadata, getsource, getdefaultval, wrap, unwrap, getname -import SymbolicUtils: Term, symtype, FnType, BasicSymbolic, promote_symtype +import SymbolicUtils: _Term, symtype, FnType, BasicSymbolic, promote_symtype, Symbolic using LinearAlgebra using Test @variables t Symbolics.@register_symbolic fff(t) -@test isequal(fff(t), Symbolics.Num(Symbolics.Term{Real}(fff, [Symbolics.value(t)]))) +@test isequal(fff(t), Symbolics.Num(_Term(Real, fff, [Symbolics.value(t)]))) const SymMatrix{T,N} = Symmetric{T, AbstractArray{T, N}} many_vars = @variables t=0 a=1 x[1:4]=2 y(t)[1:4]=3 w[1:4] = 1:4 z(t)[1:4] = 2:5 p(..)[1:4] @@ -75,7 +75,7 @@ _args = [[a 2a; 4a 6a; 3a 5a], [4a, 6a]] hh = ccwa(_args...) @test size(hh) == (3, 2, 10) @test eltype(hh) == Real -@test isequal(arguments(unwrap(hh)), unwrap.(_args)) +@test isequal(arguments(unwrap(hh)), convert(Vector{SymbolicUtils.Symbolic}, map(x -> unwrap.(x), _args))) @test all(t->getsource(t)[1] === :variables, many_vars) @test getdefaultval(t) == 0 diff --git a/test/overloads.jl b/test/overloads.jl index be893876e..63dee8920 100644 --- a/test/overloads.jl +++ b/test/overloads.jl @@ -1,4 +1,4 @@ -using Symbolics: Sym, FnType, Term, value, scalarize +using Symbolics: FnType, _Term, value, scalarize using Symbolics using LinearAlgebra using SparseArrays: sparse @@ -11,8 +11,8 @@ vars = @variables t $a $b(t) $c(t)[1:3] @test b === :value_b @test c === :value_c @test isequal(vars[1], t) -@test isequal(vars[2], Num(Sym{Real}(a))) -@test isequal(vars[3], Num(Sym{FnType{Tuple{Any},Real}}(b)(value(t)))) +@test isequal(vars[2], Num(_Sym(Real, a))) +@test isequal(vars[3], Num(_Sym(FnType{Tuple{Any},Real}, b)(value(t)))) vars = @variables a,b,c,d,e,f,g,h,i @test isequal(vars, [a,b,c,d,e,f,g,h,i]) @@ -163,7 +163,7 @@ z2 = c + d * im @test conj(a) === a @test imag(a) === Num(0) -@test isequal(sign(x), Num(SymbolicUtils.Term{Int}(sign, [Symbolics.value(x)]))) +@test isequal(sign(x), Num(_Term(Int, sign, [Symbolics.value(x)]))) @test sign(Num(1)) isa Num @test isequal(sign(Num(1)), Num(1)) @test isequal(sign(Num(-1)), Num(-1)) diff --git a/test/struct.jl b/test/struct.jl index 8eef42dc1..6d0baab3e 100644 --- a/test/struct.jl +++ b/test/struct.jl @@ -1,5 +1,6 @@ using Test, Symbolics -using Symbolics: symstruct, juliatype, symbolic_getproperty, symbolic_setproperty!, symbolic_constructor +using Symbolics: symstruct, juliatype, symbolic_getproperty, symbolic_setproperty!, + symbolic_constructor, BasicSymbolic struct Jörgen a::Int @@ -11,15 +12,15 @@ S = symstruct(Jörgen) xa = Symbolics.unwrap(symbolic_getproperty(x, :a)) @test Symbolics.symtype(xa) == Int @test Symbolics.operation(xa) == Symbolics.typed_getfield -@test isequal(Symbolics.arguments(xa), [Symbolics.unwrap(x), Val{:a}()]) +@test isequal(Symbolics.arguments(xa), BasicSymbolic[Symbolics.unwrap(x), Val{:a}()]) xa = Symbolics.unwrap(symbolic_setproperty!(x, :a, 10)) @test Symbolics.operation(xa) == setfield! -@test isequal(Symbolics.arguments(xa), [Symbolics.unwrap(x), Meta.quot(:a), 10]) +@test isequal(Symbolics.arguments(xa), BasicSymbolic[Symbolics.unwrap(x), Meta.quot(:a), 10]) @test Symbolics.symtype(xa) == Int xb = Symbolics.unwrap(symbolic_setproperty!(x, :b, 10)) @test Symbolics.operation(xb) == setfield! -@test isequal(Symbolics.arguments(xb), [Symbolics.unwrap(x), Meta.quot(:b), 10]) +@test isequal(Symbolics.arguments(xb), BasicSymbolic[Symbolics.unwrap(x), Meta.quot(:b), 10]) @test Symbolics.symtype(xb) == Float64 s = Symbolics.symbolic_constructor(S, 1, 1.0)