Skip to content

Commit 79f524d

Browse files
committed
Fix Term construction
1 parent d5d5d58 commit 79f524d

File tree

12 files changed

+30
-30
lines changed

12 files changed

+30
-30
lines changed

src/Symbolics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import TermInterface: maketerm, iscall, operation, arguments, metadata
3030

3131
import SymbolicUtils: BasicSymbolic, FnType, @rule, Rewriters, substitute, symtype,
3232
promote_symtype, isadd, ismul, ispow, isterm, issym, isdiv, _Sym,
33-
get_dict
33+
_Term, get_dict
3434

3535
using SymbolicUtils.Code
3636

src/array-lib.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Base.getindex(x::SymArray, idx...)
3232
throw(BoundsError(x, idx))
3333
end
3434
end
35-
res = Term{eltype(symtype(x))}(getindex, [x, Tuple(ii)...]; metadata = meta)
35+
res = _Term(eltype(symtype(x)), getindex, [x, Tuple(ii)...]; metadata = meta)
3636
elseif all(i -> symtype(i) <: Integer, idx)
3737
shape(x) !== Unknown() && @boundscheck begin
3838
if length(idx) > 1
@@ -43,7 +43,7 @@ function Base.getindex(x::SymArray, idx...)
4343
end
4444
end
4545
end
46-
res = Term{eltype(symtype(x))}(getindex, [x, idx...]; metadata = meta)
46+
res = _Term(eltype(symtype(x)), getindex, [x, idx...]; metadata = meta)
4747
elseif length(idx) == 1 && symtype(first(idx)) <: CartesianIndex
4848
i = first(idx)
4949
ii = i isa CartesianIndex ? Tuple(i) : arguments(i)
@@ -70,7 +70,7 @@ function Base.getindex(x::SymArray, idx...)
7070
end
7171
end
7272

73-
term = Term{Any}(getindex, [x, idx...]; metadata = meta)
73+
term = _Term(Any, getindex, [x, idx...]; metadata = meta)
7474
T = eltype(symtype(x))
7575
N = ndims(x) - count(i -> symtype(i) <: Integer, idx)
7676
res = ArrayOp(atype(symtype(x)){T,N},
@@ -197,12 +197,12 @@ function Broadcast.copy(bc::Broadcast.Broadcasted{SymBroadcast})
197197
# then you get pairs, and index matcher cannot
198198
# recurse into pairs
199199
Atype = propagate_atype(broadcast, bc.f, args...)
200-
args = map(x -> x isa Base.RefValue ? Term{Any}(Ref, [x[]]) : x, args)
200+
args = map(x -> x isa Base.RefValue ? _Term(Any, Ref, [x[]]) : x, args)
201201
ArrayOp(Atype{symtype(expr),ndim},
202202
(subscripts...,),
203203
expr,
204204
+,
205-
Term{Any}(broadcast, [bc.f, args...]))
205+
_Term(Any, broadcast, [bc.f, args...]))
206206
end
207207

208208
# On wrapper:
@@ -270,15 +270,15 @@ function symeltype(A)
270270
end
271271
# TODO: add more such methods
272272
function getindex(A::AbstractArray, i::Symbolic{<:Integer}, ii::Symbolic{<:Integer}...)
273-
Term{symeltype(A)}(getindex, [A, i, ii...])
273+
_Term(symeltype(A), getindex, [A, i, ii...])
274274
end
275275

276276
function getindex(A::AbstractArray, i::Int, j::Symbolic{<:Integer})
277-
Term{symeltype(A)}(getindex, [A, i, j])
277+
_Term(symeltype(A), getindex, [A, i, j])
278278
end
279279

280280
function getindex(A::AbstractArray, j::Symbolic{<:Integer}, i::Int)
281-
Term{symeltype(A)}(getindex, [A, j, i])
281+
_Term(symeltype(A), getindex, [A, j, i])
282282
end
283283

284284
function getindex(A::Arr, i::Int, j::Symbolic{<:Integer})
@@ -341,7 +341,7 @@ function _map(f, x, xs...)
341341
(idx...,),
342342
expr,
343343
+,
344-
Term{Any}(map, [f, x, xs...]))
344+
_Term(Any, map, [f, x, xs...]))
345345
end
346346

347347
@inline _mapreduce(f, g, x, dims, kw) = mapreduce(f, g, x; dims=dims, kw...)
@@ -359,15 +359,15 @@ end
359359
expr = f(x[idx...])
360360
T = symtype(g(expr, expr))
361361
if dims === (:)
362-
return Term{T}(_mapreduce, [f, g, x, dims, (kw...,)])
362+
return _Term(T, _mapreduce, [f, g, x, dims, (kw...,)])
363363
end
364364

365365
Atype = propagate_atype(_mapreduce, f, g, x, dims, (kw...,))
366366
ArrayOp(Atype{T,ndims(x)},
367367
(out_idx...,),
368368
expr,
369369
g,
370-
Term{Any}(_mapreduce, [f, g, x, dims, (kw...,)]))
370+
_Term(Any, _mapreduce, [f, g, x, dims, (kw...,)]))
371371
end false
372372

373373
for (ff, opts) in [sum => (identity, +, false),

src/arrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function array_term(f, args...;
407407
end
408408
end
409409
S = container_type{eltype, ndims}
410-
setmetadata(Term{S}(f, Any[args...]), ArrayShapeCtx, shape)
410+
setmetadata(_Term(S, f, Any[args...]), ArrayShapeCtx, shape)
411411
end
412412

413413
"""
@@ -680,7 +680,7 @@ function scalarize_op(f::typeof(_det), arr)
680680
end
681681

682682
@wrapped function LinearAlgebra.det(x::AbstractMatrix; laplace=true)
683-
Term{eltype(x)}(_det, [x, laplace])
683+
_Term(eltype(x), _det, [x, laplace])
684684
end false
685685

686686

src/diff.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function occursin_info(x, expr, fail = true)
103103
if all(_isfalse, args)
104104
return false
105105
end
106-
Term{Real}(true, args)
106+
_Term(Real, true, args)
107107
end
108108
end
109109

@@ -636,7 +636,7 @@ end
636636

637637
isidx(x) = x isa TermCombination
638638

639-
basic_mkterm(t, g, args, m) = metadata(Term{Any}(g, args), m)
639+
basic_mkterm(t, g, args, m) = metadata(_Term(Any, g, args), m)
640640

641641
let
642642
# we do this in a let block so that Revise works on the list of rules

src/difference.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct Difference <: Operator
2424
update::Bool
2525
Difference(t; dt, update=false) = new(value(t), dt, update)
2626
end
27-
(D::Difference)(t) = Term{symtype(t)}(D, [t])
27+
(D::Difference)(t) = _Term(symtype(t), D, [t])
2828
(D::Difference)(t::Num) = Num(D(value(t)))
2929
SymbolicUtils.promote_symtype(::Difference, t) = t
3030
"""

src/extra_functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function _binomial(nothing, n, k)
88
end), unwrapped_args))
99
Base.binomial(unwrapped_args...)
1010
else
11-
SymbolicUtils.Term{Int}(Base.binomial, unwrapped_args)
11+
_Term(Int, Base.binomial, unwrapped_args)
1212
end
1313
if typeof.(args) == typeof.(unwrapped_args)
1414
return res

src/integral.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct Integral{T <: Symbolics.VarDomainPairing} <: Function
44
Integral(domain) = new{typeof(domain)}(domain)
55
end
66

7-
(I::Integral)(x) = Term{SymbolicUtils.symtype(x)}(I, [x])
7+
(I::Integral)(x) = _Term(SymbolicUtils.symtype(x), I, [x])
88
(I::Integral)(x::Num) = Num(I(Symbolics.value(x)))
99
SymbolicUtils.promote_symtype(::Integral, x) = x
1010

src/parsing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function parse_expr_to_symbolic(ex, mod::Module)
8181
else
8282
x = parse_expr_to_symbolic(ex.args[1], mod)
8383
ys = parse_expr_to_symbolic.(ex.args[2:end],(mod,))
84-
return Term{Real}(x,[ys...])
84+
return _Term(Real, x,[ys...])
8585
end
8686
end
8787
end

src/register.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro register_symbolic(expr, define_promotion = true, Ts = :([]), wrap_arrays =
3535
res = if !any($is_symbolic_or_array_of_symbolic, unwrapped_args)
3636
$f(unwrapped_args...) # partial-eval if all args are unwrapped
3737
else
38-
$Term{$ret_type}($f, unwrapped_args)
38+
$_Term($ret_type, $f, unwrapped_args)
3939
end
4040
if typeof.(args) == typeof.(unwrapped_args)
4141
return res
@@ -115,7 +115,7 @@ function register_array_symbolic(f, ftype, argnames, Ts, ret_type, partial_defs
115115
elseif $ret_type == nothing || ($ret_type <: AbstractArray)
116116
$array_term($(Expr(:parameters, [Expr(:kw, k, v) for (k, v) in defs]...)), $f, unwrapped_args...)
117117
else
118-
$Term{$ret_type}($f, unwrapped_args)
118+
$_Term($ret_type, $f, unwrapped_args)
119119
end
120120

121121
if typeof.(args) == typeof.(unwrapped_args)

src/semipoly.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Base.:nameof(m::SemiMonomial) = Symbol(:SemiMonomial, m.p, m.coeff)
136136
isop(x, op) = iscall(x) && operation(x) === op
137137
isop(op) = Base.Fix2(isop, op)
138138

139-
simpleterm(T, f, args, m) = Term{SymbolicUtils._promote_symtype(f, args)}(f, args)
139+
simpleterm(T, f, args, m) = _Term(SymbolicUtils._promote_symtype(f, args), f, args)
140140

141141
function mark_and_exponentiate(expr, vars)
142142
# Step 1
@@ -197,16 +197,16 @@ function mark_vars(expr, vars)
197197
if op === (^) || op == (/)
198198
args = arguments(expr)
199199
@assert length(args) == 2
200-
return Term{symtype(expr)}(op, map(mark_vars(vars), args))
200+
return _Term(symtype(expr), op, map(mark_vars(vars), args))
201201
end
202202
args = arguments(expr)
203203
if op === (+) || op === (*)
204-
return Term{symtype(expr)}(op, map(mark_vars(vars), args))
204+
return _Term(symtype(expr), op, map(mark_vars(vars), args))
205205
elseif length(args) == 1
206206
if op == sqrt
207207
return mark_vars(args[1]^(1//2), vars)
208208
elseif linearity_1(op)
209-
return Term{symtype(expr)}(op, mark_vars(args[1], vars))
209+
return _Term(symtype(expr), op, mark_vars(args[1], vars))
210210
end
211211
end
212212
return SemiMonomial(1, expr)

0 commit comments

Comments
 (0)