@@ -187,43 +187,42 @@ function _evaluate(a::HomogeneousPolynomial{T}, vals::NTuple) where {T}
187187 return suma
188188end
189189
190- function _evaluate (a:: HomogeneousPolynomial{T} , vals:: NTuple{N,<:TaylorN{T}} ) where
191- {N,T<: NumberNotSeries }
192- # @assert length(vals) == get_numvars()
193- a. order == 0 && return a[1 ]* one (vals[1 ])
190+ function _evaluate! (res:: TaylorN{T} , a:: HomogeneousPolynomial{T} , vals:: NTuple{N,<:TaylorN{T}} ,
191+ valscache:: Vector{TaylorN{T}} , aux:: TaylorN{T} ) where {N,T<: NumberNotSeries }
194192 ct = coeff_table[a. order+ 1 ]
195- suma = TaylorN (zero (T), vals[1 ]. order)
196- #
197- # vv = power_by_squaring.(vals, ct[1])
198- vv = vals .^ ct[1 ]
199- tmp = zero (suma)
200- aux = one (suma)
193+ for el in eachindex (valscache)
194+ power_by_squaring! (valscache[el], vals[el], aux, ct[1 ][el])
195+ end
201196 for (i, a_coeff) in enumerate (a. coeffs)
202197 iszero (a_coeff) && continue
203- # @inbounds vv .= power_by_squaring.(vals, ct[i])
204- vv .= vals .^ ct[i]
205- # tmp = prod( vv )
206- for ord in eachindex (tmp)
207- @inbounds one! (aux, vv[1 ], ord)
198+ # valscache .= vals .^ ct[i]
199+ @inbounds for el in eachindex (valscache)
200+ power_by_squaring! (valscache[el], vals[el], aux, ct[i][el])
208201 end
209- for j in eachindex (vv)
210- for ord in eachindex (tmp)
211- zero! (tmp, ord)
212- @inbounds mul! (tmp, aux, vv[j], ord)
213- end
214- for ord in eachindex (tmp)
215- identity! (aux, tmp, ord)
216- end
202+ # aux = one(valscache[1])
203+ for ord in eachindex (aux)
204+ @inbounds one! (aux, valscache[1 ], ord)
217205 end
218- # suma += a_coeff * tmp
219- for ord in eachindex (tmp)
220- for ordQ in eachindex (tmp[ord ])
221- zero! (aux[ord], ordQ)
222- aux[ord][ordQ] = a_coeff * tmp[ord][ordQ]
223- suma[ ord][ordQ] += aux[ord][ordQ]
224- end
206+ for j in eachindex (valscache)
207+ # aux *= valscache[j]
208+ mul! (aux, valscache[j ])
209+ end
210+ # res + = a_coeff * aux
211+ for ord in eachindex ( aux)
212+ muladd! (res, a_coeff, aux, ord)
225213 end
226214 end
215+ return nothing
216+ end
217+
218+ function _evaluate (a:: HomogeneousPolynomial{T} , vals:: NTuple{N,<:TaylorN{T}} ) where
219+ {N,T<: NumberNotSeries }
220+ # @assert length(vals) == get_numvars()
221+ a. order == 0 && return a[1 ]* one (vals[1 ])
222+ suma = TaylorN (zero (T), vals[1 ]. order)
223+ valscache = [zero (val) for val in vals]
224+ aux = zero (suma)
225+ _evaluate! (suma, a, vals, valscache, aux)
227226 return suma
228227end
229228
@@ -319,6 +318,17 @@ _evaluate(a::TaylorN{T}, vals::NTuple, ::Val{true}) where {T<:NumberNotSeries} =
319318_evaluate (a:: TaylorN{T} , vals:: NTuple , :: Val{false} ) where {T<: Number } =
320319 sum ( _evaluate (a, vals) )
321320
321+ function _evaluate (a:: TaylorN{T} , vals:: NTuple{N,<:TaylorN} , :: Val{false} ) where {N,T<: Number }
322+ R = promote_type (T, TS. numtype (vals[1 ]))
323+ res = TaylorN (zero (R), vals[1 ]. order)
324+ valscache = [zero (val) for val in vals]
325+ aux = zero (res)
326+ @inbounds for homPol in eachindex (a)
327+ _evaluate! (res, a[homPol], vals, valscache, aux)
328+ end
329+ return res
330+ end
331+
322332function _evaluate (a:: TaylorN{T} , vals:: NTuple{N,<:Number} ) where {N,T<: Number }
323333 R = promote_type (T, typeof (vals[1 ]))
324334 a_length = length (a)
@@ -329,13 +339,20 @@ function _evaluate(a::TaylorN{T}, vals::NTuple{N,<:Number}) where {N,T<:Number}
329339 return suma
330340end
331341
332- function _evaluate (a:: TaylorN{T} , vals:: NTuple{N,<:TaylorN} ) where {N,T<: Number }
333- R = TaylorN{promote_type (T, TS. numtype (vals[1 ]))}
334- a_length = length (a)
335- suma = zeros (R, a_length)
342+ function _evaluate! (res:: Vector{TaylorN{T}} , a:: TaylorN{T} , vals:: NTuple{N,<:TaylorN} ,
343+ valscache:: Vector{TaylorN{T}} , aux:: TaylorN{T} ) where {N,T<: Number }
336344 @inbounds for homPol in eachindex (a)
337- suma [homPol+ 1 ] = _evaluate ( a[homPol], vals)
345+ _evaluate! (res [homPol+ 1 ], a[homPol], vals, valscache, aux )
338346 end
347+ return nothing
348+ end
349+
350+ function _evaluate (a:: TaylorN{T} , vals:: NTuple{N,<:TaylorN} ) where {N,T<: Number }
351+ R = promote_type (T, TS. numtype (vals[1 ]))
352+ suma = [TaylorN (zero (R), vals[1 ]. order) for _ in eachindex (a)]
353+ valscache = [zero (val) for val in vals]
354+ aux = zero (suma[1 ])
355+ _evaluate! (suma, a, vals, valscache, aux)
339356 return suma
340357end
341358
@@ -486,6 +503,22 @@ function evaluate!(x::AbstractArray{TaylorN{T}}, δx::Array{TaylorN{T},1},
486503 return nothing
487504end
488505
506+ function evaluate! (a:: TaylorN{T} , vals:: NTuple{N,TaylorN{T}} , dest:: TaylorN{T} , valscache:: Vector{TaylorN{T}} , aux:: TaylorN{T} ) where {N,T<: Number }
507+ @inbounds for homPol in eachindex (a)
508+ _evaluate! (dest, a[homPol], vals, valscache, aux)
509+ end
510+ return nothing
511+ end
512+
513+ function evaluate! (a:: AbstractArray{TaylorN{T}} , vals:: NTuple{N,TaylorN{T}} , dest:: AbstractArray{TaylorN{T}} ) where {N,T<: Number }
514+ valscache = [zero (val) for val in vals]
515+ aux = zero (dest[1 ])
516+ for i in eachindex (a)
517+ (! iszero (a[i])) && zero! (dest[i])
518+ evaluate! (a[i], vals, dest[i], valscache, aux)
519+ end
520+ return nothing
521+ end
489522
490523# In-place Horner methods, used when the result of an evaluation (substitution)
491524# is Taylor1{}
0 commit comments