Skip to content

Commit 466845e

Browse files
authored
Fixes and additions in evaluate, including some in-line methods (#357)
* Minor fixes in sqr_orderzero! and power_by_squaring * Fix methods of evaluate for Taylor1{TaylorN{T}} with tests. Some methods have been commented for now * Run Aqua tests only once at the end * Improvements when dealing with intervals * Add evaluate(::Taylor1{T}, ::TaylorN{T}), and other fixes * Add evaluate(::Taylor1{T}, ::Taylor1{TaylorN{T}) * Add _horner! as in-line evaluate method for certain mixtures * Add `fixorder` when needed for evaluate * Fix typo * Another fix (in fixorder) * Add methods for evaluate of a TaylorN by a value or TaylorN, including in-line methods * Fixes and tests * More tests a minor improvement * Avoid using `@isonethread` in evaluate, differentiate and integrate * Bump patch version
1 parent fdfa666 commit 466845e

File tree

9 files changed

+406
-129
lines changed

9 files changed

+406
-129
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TaylorSeries"
22
uuid = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
33
repo = "https://github.com/JuliaDiff/TaylorSeries.jl.git"
4-
version = "0.17.6"
4+
version = "0.17.7"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

ext/TaylorSeriesIAExt.jl

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ for T in (:Taylor1, :TaylorN)
159159
end
160160

161161

162-
function evaluate(a::Taylor1{T}, dx::Interval{S}) where {T<:Real, S<:Real}
162+
function evaluate(a::Taylor1, dx::Interval{S}) where {S<:Real}
163163
order = a.order
164164
uno = one(dx)
165165
dx2 = dx^2
@@ -183,34 +183,13 @@ function evaluate(a::TaylorN, dx::IntervalBox{N,T}) where {T<:Real,N}
183183
@assert N == get_numvars()
184184
a_length = length(a)
185185
suma = zero(constant_term(a)) + Interval{T}(0, 0)
186-
@inbounds for homPol in length(a):-1:1
187-
suma += evaluate(a.coeffs[homPol], dx)
186+
@inbounds for homPol in reverse(eachindex(a))
187+
suma += evaluate(a[homPol], dx)
188188
end
189189

190190
return suma
191191
end
192192

193-
function evaluate(a::Taylor1{TaylorN{T}}, dx::Interval{S}) where {T<:Real, S<:Real}
194-
order = a.order
195-
uno = one(dx)
196-
dx2 = dx^2
197-
if iseven(order)
198-
kend = order-2
199-
@inbounds sum_even = a[end]*uno
200-
@inbounds sum_odd = a[end-1]*zero(dx)
201-
else
202-
kend = order-3
203-
@inbounds sum_odd = a[end]*uno
204-
@inbounds sum_even = a[end-1]*uno
205-
end
206-
@inbounds for k in kend:-2:0
207-
sum_odd = sum_odd*dx2 + a[k+1]
208-
sum_even = sum_even*dx2 + a[k]
209-
end
210-
return sum_even + sum_odd*dx
211-
end
212-
213-
214193
function evaluate(a::HomogeneousPolynomial, dx::IntervalBox{N,T}) where {T<:Real,N}
215194
@assert N == get_numvars()
216195
dx == IntervalBox(-1..1, Val(N)) && return _evaluate(a, dx, Val(true))
@@ -226,16 +205,16 @@ function _evaluate(a::HomogeneousPolynomial, dx::IntervalBox{N,T}, ::Val{true} )
226205
@inbounds suma = a[1]*Interval{T}(0,0)
227206

228207
Ieven = Interval{T}(0,1)
229-
for (i,a_coeff) in enumerate(a.coeffs)
208+
for (i, a_coeff) in enumerate(a.coeffs)
230209
iszero(a_coeff) && continue
231210
if isodd(sum(ct[i]))
232-
suma += sum(a_coeff) * dx[1]
233-
continue
234-
end
235-
@inbounds tmp = iseven(ct[i][1]) ? Ieven : dx[1]
236-
for n in 2:N
237-
@inbounds vv = iseven(ct[i][n]) ? Ieven : dx[1]
238-
tmp *= vv
211+
tmp = dx[1]
212+
else
213+
tmp = Ieven
214+
for n in eachindex(ct[i])
215+
iseven(ct[i][n]) && continue
216+
tmp *= dx[1]
217+
end
239218
end
240219
suma += a_coeff * tmp
241220
end

src/auxiliary.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ end
259259
## fixorder ##
260260
for T in (:Taylor1, :TaylorN)
261261
@eval begin
262-
@inline function fixorder(a::$T{T}, b::$T{T}) where {T<:Number}
262+
@inline function fixorder(a::$T, b::$T)
263263
a.order == b.order && return a, b
264264
minorder = _minorder(a, b)
265265
return $T(copy(a.coeffs), minorder), $T(copy(b.coeffs), minorder)

src/calculus.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ function differentiate(a::HomogeneousPolynomial, r::Int)
141141
coeffs = zeros(T, num_coeffs)
142142
@inbounds posTb = pos_table[a.order]
143143
@inbounds num_coeffs = size_table[a.order+1]
144-
144+
ct = deepcopy(coeff_table[a.order+1])
145145
@inbounds for i = 1:num_coeffs
146-
iind = @isonethread coeff_table[a.order+1][i]
146+
# iind = @isonethread coeff_table[a.order+1][i]
147+
iind = ct[i]
147148
n = iind[r]
148149
n == 0 && continue
149150
iind[r] -= 1
@@ -370,9 +371,10 @@ function integrate(a::HomogeneousPolynomial, r::Int)
370371

371372
T = promote_type(TS.numtype(a), TS.numtype(a[1]/1))
372373
coeffs = zeros(T, size_table[a.order+2])
373-
374+
ct = deepcopy(coeff_table[a.order+1])
374375
@inbounds for i = 1:num_coeffs
375-
iind = @isonethread coeff_table[a.order+1][i]
376+
# iind = @isonethread coeff_table[a.order+1][i]
377+
iind = ct[i]
376378
n = iind[r]
377379
n == order_max && continue
378380
iind[r] += 1

0 commit comments

Comments
 (0)