Skip to content

Commit ff9be21

Browse files
committed
pass through constants in PolyForm constructor
1 parent 4e319d1 commit ff9be21

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/polyform.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ struct PolyForm{T, M} <: Symbolic{T}
3232
sym2term::Dict{Sym,Any} # Symbol("sin-$hash(sin(x+y))") --> sin(x+y) => sin(PolyForm(...))
3333
metadata::M
3434
end
35-
(::Type{PolyForm{T}})(p, d1, d2, m=nothing) where {T} = PolyForm{T, typeof(m)}(p, d1, d2, m)
35+
36+
function (::Type{PolyForm{T}})(p, d1, d2, m=nothing) where {T}
37+
p isa Number && return p
38+
MP.isconstant(p) && return convert(Number, p)
39+
PolyForm{T, typeof(m)}(p, d1, d2, m)
40+
end
3641

3742
Base.hash(p::PolyForm, u::UInt64) = xor(hash(p.p, u), trunc(UInt, 0xbabacacababacaca))
3843
Base.isequal(x::PolyForm, y::PolyForm) = isequal(x.p, y.p)
@@ -156,8 +161,7 @@ function PolyForm(x::Symbolic{<:Number},
156161

157162
# Polyize and return a PolyForm
158163
p = polyize(x, pvar2sym, sym2term, vtype, pow, Fs, recurse)
159-
MP.isconstant(p) && return convert(Number, p)
160-
PolyForm{symtype(x), typeof(metadata)}(p, pvar2sym, sym2term, metadata)
164+
PolyForm{symtype(x)}(p, pvar2sym, sym2term, metadata)
161165
end
162166

163167
PolyForm(x, args...;kw...) = x

0 commit comments

Comments
 (0)