StatProfilerHTML.jl report
Generated on Thu, 26 Mar 2020 19:09:01
File source code
Line Exclusive Inclusive Code
1 Base.convert(::Type{M}, v::Variable) where {Vars, M <: Monomial{Vars}} = convert(M, Monomial(v))
2 Base.convert(::Type{Monomial}, v::Variable) = Monomial(v)
3 Base.convert(::Type{Term{T, M1}}, m::Monomial) where {T, M1} = Term(one(T), convert(M1, m))
4 Base.convert(::Type{Term{T, M}}, v::Variable) where {T, M} = Term(one(T), convert(M, v))
5 Base.convert(T::Type{Polynomial{C1, T1, V1}}, p::Polynomial) where {C1, T1, V1} = T(convert(V1, p.terms))
6 # Break ambibuity
7 Base.convert(T::Type{Polynomial{C1, T1, V1}}, x::MP.AbstractTermLike) where {C1, T1, V1} = convert(T, Polynomial(convert(T1, x)))
8
9 MP.convertconstant(T::Type{Term{T1, M1}}, α) where {T1, M1} = T(convert(T1, α), M1())
10 MP.convertconstant(T::Type{Polynomial{C1, T1, V1}}, α) where {C1, T1, V1} = convert(T, Polynomial(convert(T1, α)))
11
12 Base.convert(T::Type{Monomial{V}}, m::Monomial) where {V} = convert(Monomial{V, nvariables(T)}, m)
13
14 @pure function matchindices(::Type{Monomial{V1, N1}}, ::Type{Monomial{V2, N2}}) where {V1, N1, V2, N2}
15 i2 = 1
16 inds = ntuple(i -> begin
17 if i2 > N2
18 0
19 elseif V1[i] === V2[i2]
20 i2 += 1
21 i2 - 1
22 else
23 0
24 end
25 end, Val{N1}())
26 if i2 <= N2
27 throw(InexactError(:matchindices, Monomial{V1, N1}, Monomial{V2, N2}))
28 end
29 inds
30 end
31
32 function Base.convert(::Type{Monomial{V1, N1}}, m::Monomial) where {V1, N1}
33 inds = matchindices(Monomial{V1, N1}, typeof(m))
34 exps = ntuple(i -> begin
35 @inbounds ii = inds[i]
36 if ii == 0
37 0
38 else
39 m.exponents[ii]
40 end
41 end, Val{N1}())
42 Monomial{V1, N1}(exps)
43 end
44
45 Base.convert(::Type{Term{T1, M1}}, t::Term) where {T1, M1} = Term{T1, M1}(MA.scaling_convert(T1, t.coefficient), convert(M1, t.monomial))
46 79 (9 %)
79 (9 %) samples spent in polynomial!
79 (100 %) (incl.) when called from polynomial! line 69
79 (100 %) samples spent calling Polynomial
MP.polynomial!(v::AbstractVector{<:Term}, ::MP.SortedUniqState) = Polynomial(v)
47 function MP.polynomial(p::P, ::Type{C}) where {P<:PolynomialLike, C}
48 convert(polynomialtype(P, C), p)
49 end