Skip to content

Commit 0e53bc0

Browse files
committed
Merge remote-tracking branch 'origin/master' into jp/evaluate
2 parents ce153e4 + 9a7c39b commit 0e53bc0

8 files changed

Lines changed: 54 additions & 34 deletions

File tree

Project.toml

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

66
[deps]

ext/TaylorSeriesIAExt.jl

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,16 @@ function TS.sqrt!(c::Taylor1{Interval{T}}, a::Taylor1{Interval{T}},
318318
@inbounds for i = imin+1:imax
319319
c[k] += c[i] * c[k+k0-i]
320320
end
321+
intvl2 = interval(T(2))
321322
if k+k0 a_order
322-
@inbounds aux = a[k+k0] - interval(T(2)) * c[k]
323+
@inbounds aux = a[k+k0] - intvl2 * c[k]
323324
else
324-
@inbounds aux = - interval(T(2)) * c[k]
325+
@inbounds aux = - intvl2 * c[k]
325326
end
326327
if kodd == 0
327328
@inbounds aux = aux - c[kend+k0+1]^2
328329
end
329-
@inbounds c[k] = aux / (interval(T(2)) * c[k0])
330+
@inbounds c[k] = aux / (intvl2 * c[k0])
330331
return nothing
331332
end
332333

@@ -347,12 +348,13 @@ function TS.sqrt!(c::TaylorN{Interval{T}}, a::TaylorN{Interval{T}},
347348
# @inbounds c[k] <- c[k] - (c[kend+1])^2
348349
@inbounds TS.mul_scalar!(c[k], -interval(T(1)), c[kend+1], c[kend+1])
349350
end
351+
intvl2 = interval(T(2))
350352
@inbounds for i = 1:kend
351353
# c[k] <- c[k] - 2*c[i]*c[k-i]
352-
TS.mul_scalar!(c[k], -interval(T(2)), c[i], c[k-i])
354+
TS.mul_scalar!(c[k], -intvl2, c[i], c[k-i])
353355
end
354356
# @inbounds c[k] <- c[k] / (2*c[0])
355-
TS.div!(c[k], c[k], interval(T(2))*constant_term(c))
357+
TS.div!(c[k], c[k], intvl2*constant_term(c))
356358

357359
return nothing
358360
end
@@ -469,11 +471,12 @@ function TS.exp!(c::Taylor1{Interval{T}}, a::Taylor1{Interval{T}}, k::Int) where
469471
@inbounds c[0] = exp(constant_term(a))
470472
return nothing
471473
end
472-
@inbounds c[k] = interval(T(k)) * a[k] * c[0]
474+
intvlk = interval(T(k))
475+
@inbounds c[k] = intvlk * a[k] * c[0]
473476
@inbounds for i = 1:k-1
474477
c[k] += interval(T(k-i)) * a[k-i] * c[i]
475478
end
476-
@inbounds c[k] = c[k] / interval(T(k))
479+
@inbounds c[k] = c[k] / intvlk
477480
return nothing
478481
end
479482

@@ -482,11 +485,12 @@ function TS.exp!(c::TaylorN{Interval{T}}, a::TaylorN{Interval{T}}, k::Int) where
482485
@inbounds c[0] = exp(constant_term(a))
483486
return nothing
484487
end
485-
@inbounds TS.mul!(c[k], interval(T(k)) * a[k], c[0])
488+
intvlk = interval(T(k))
489+
@inbounds TS.mul!(c[k], intvlk * a[k], c[0])
486490
@inbounds for i = 1:k-1
487491
TS.mul!(c[k], interval(T(k-i)) * a[k-i], c[i])
488492
end
489-
@inbounds c[k] = c[k] / interval(T(k))
493+
@inbounds c[k] = c[k] / intvlk
490494
return nothing
491495
end
492496

@@ -496,11 +500,12 @@ function TS.expm1!(c::Taylor1{Interval{T}}, a::Taylor1{Interval{T}}, k::Int) whe
496500
return nothing
497501
end
498502
c0 = c[0]+one(c[0])
499-
@inbounds c[k] = interval(T(k)) * a[k] * c0
503+
intvlk = interval(T(k))
504+
@inbounds c[k] = intvlk * a[k] * c0
500505
@inbounds for i = 1:k-1
501506
c[k] += interval(T(k-i)) * a[k-i] * c[i]
502507
end
503-
@inbounds c[k] = c[k] / interval(T(k))
508+
@inbounds c[k] = c[k] / intvlk
504509
return nothing
505510
end
506511

@@ -510,11 +515,12 @@ function TS.expm1!(c::TaylorN{Interval{T}}, a::TaylorN{Interval{T}}, k::Int) whe
510515
return nothing
511516
end
512517
c0 = c[0]+one(c[0])
513-
@inbounds TS.mul!(c[k], interval(T(k)) * a[k], c0)
518+
intvlk = interval(T(k))
519+
@inbounds TS.mul!(c[k], intvlk * a[k], c0)
514520
@inbounds for i = 1:k-1
515521
TS.mul!(c[k], interval(T(k-i)) * a[k-i], c[i])
516522
end
517-
@inbounds c[k] = c[k] / interval(T(k))
523+
@inbounds c[k] = c[k] / intvlk
518524
return nothing
519525
end
520526

@@ -601,8 +607,9 @@ function TS.sincos!(s::Taylor1{Interval{T}}, c::Taylor1{Interval{T}},
601607
s[k] += x * c[k-i]
602608
c[k] -= x * s[k-i]
603609
end
604-
@inbounds s[k] = s[k] / interval(T(k))
605-
@inbounds c[k] = c[k] / interval(T(k))
610+
intvlk = interval(T(k))
611+
@inbounds s[k] = s[k] / intvlk
612+
@inbounds c[k] = c[k] / intvlk
606613
return nothing
607614
end
608615

@@ -621,8 +628,9 @@ function TS.sincos!(s::TaylorN{Interval{T}}, c::TaylorN{Interval{T}},
621628
TS.mul!(s[k], x, c[k-i])
622629
TS.mul!(c[k], -x, s[k-i])
623630
end
624-
@inbounds s[k] = s[k] / interval(T(k))
625-
@inbounds c[k] = c[k] / interval(T(k))
631+
intvlk = interval(T(k))
632+
@inbounds s[k] = s[k] / intvlk
633+
@inbounds c[k] = c[k] / intvlk
626634
return nothing
627635
end
628636

@@ -634,11 +642,12 @@ function TS.tan!(c::Taylor1{Interval{T}}, a::Taylor1{Interval{T}},
634642
@inbounds c2[0] = aux^2
635643
return nothing
636644
end
637-
@inbounds c[k] = interval(T(k)) * a[k] * c2[0]
645+
intvlk = interval(T(k))
646+
@inbounds c[k] = intvlk * a[k] * c2[0]
638647
@inbounds for i = 1:k-1
639648
c[k] += interval(T(k-i)) * a[k-i] * c2[i]
640649
end
641-
@inbounds c[k] = a[k] + c[k]/interval(T(k))
650+
@inbounds c[k] = a[k] + c[k]/intvlk
642651
TS.sqr!(c2, c, zero(c[0]), k)
643652
return nothing
644653
end
@@ -651,11 +660,12 @@ function TS.tan!(c::TaylorN{Interval{T}}, a::TaylorN{Interval{T}},
651660
@inbounds c2[0] = aux^2
652661
return nothing
653662
end
654-
@inbounds TS.mul!(c[k], interval(T(k)) * a[k], c2[0])
663+
intvlk = interval(T(k))
664+
@inbounds TS.mul!(c[k], intvlk * a[k], c2[0])
655665
@inbounds for i = 1:k-1
656666
TS.mul!(c[k], interval(T(k-i)) * a[k-i], c2[i])
657667
end
658-
@inbounds c[k] = a[k] + c[k]/interval(T(k))
668+
@inbounds c[k] = a[k] + c[k]/intvlk
659669
TS.sqr!(c2, c, zero(c[0][1]), k)
660670
return nothing
661671
end
@@ -777,8 +787,9 @@ function TS.sinhcosh!(s::Taylor1{Interval{T}}, c::Taylor1{Interval{T}},
777787
s[k] += x * c[k-i]
778788
c[k] += x * s[k-i]
779789
end
780-
s[k] = s[k] / interval(T(k))
781-
c[k] = c[k] / interval(T(k))
790+
intvlk = interval(T(k))
791+
s[k] = s[k] / intvlk
792+
c[k] = c[k] / intvlk
782793
return nothing
783794
end
784795

@@ -797,8 +808,9 @@ function TS.sinhcosh!(s::TaylorN{Interval{T}}, c::TaylorN{Interval{T}},
797808
TS.mul!(s[k], x, c[k-i])
798809
TS.mul!(c[k], x, s[k-i])
799810
end
800-
s[k] = s[k] / interval(T(k))
801-
c[k] = c[k] / interval(T(k))
811+
intvlk = interval(T(k))
812+
s[k] = s[k] / intvlk
813+
c[k] = c[k] / intvlk
802814
return nothing
803815
end
804816

@@ -1045,7 +1057,7 @@ function TS._evaluate(a::HomogeneousPolynomial{T},
10451057
@inbounds suma = a[1]*interval(zero(T))
10461058
for (i, a_coeff) in enumerate(a.coeffs)
10471059
TS._isthinzero(a_coeff) && continue
1048-
@inbounds tmp = prod(dx .^ ct[i])
1060+
@inbounds tmp = prod(Base.literal_pow.(^, dx, Val.(ct[i])))
10491061
suma += a_coeff * tmp
10501062
end
10511063
return suma
@@ -1112,7 +1124,7 @@ function TS._evaluate(a::HomogeneousPolynomial{T},
11121124
suma = zero(a[1])*vals[1]
11131125
for (i, a_coeff) in enumerate(a.coeffs)
11141126
TS._isthinzero(a_coeff) && continue
1115-
@inbounds tmp = prod( vals .^ ct[i] )
1127+
@inbounds tmp = prod( Base.literal_pow.(^, vals, Val.(ct[i])) )
11161128
suma += a_coeff * tmp
11171129
end
11181130
return suma

src/TaylorSeries.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Base: iterate, size, eachindex, firstindex, lastindex,
3636
import Base: zero, one, zeros, ones, isinf, isnan, iszero, isless,
3737
convert, promote_rule, promote, show, sum!,
3838
real, imag, conj, adjoint,
39-
rem, mod, mod2pi, abs, abs2,
39+
round, rem, mod, mod2pi, abs, abs2,
4040
sqrt, exp, expm1, log, log1p,
4141
sin, cos, sincos, sinpi, cospi, sincospi, tan,
4242
asin, acos, atan, sinh, cosh, tanh, atanh, asinh, acosh,

src/evaluate.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ function _evaluate(a::HomogeneousPolynomial{T}, vals::NTuple) where {T}
224224
order(a) == 0 && return a[1]*one(vals[1])
225225
ct = a.space.coeff_table[order(a)+1]
226226
suma = zero(a[1])*vals[1]
227-
vv = vals .^ ct[1]
227+
vv = Base.literal_pow.(^, vals, Val.(ct[1]))
228228
for (i, a_coeff) in enumerate(a.coeffs)
229229
TS._isthinzero(a_coeff) && continue
230-
@inbounds vv .= vals .^ ct[i]
230+
@inbounds vv .= Base.literal_pow.(^, vals, Val.(ct[i]))
231231
tmp = prod( vv )
232232
suma += a_coeff * tmp
233233
end
@@ -441,7 +441,7 @@ function _evaluate!(suma::TaylorN{T}, a::HomogeneousPolynomial{T}, ind::Int,
441441
suma[0][1] = a[1]*one(val)
442442
return nothing
443443
end
444-
vv = val .^ (0:order)
444+
vv = Base.literal_pow.(^, val, Val.(0:order))
445445
vct = zero(a.space.coeff_table[order+1][1])
446446
zct = zero(a.space.coeff_table[order+1][1])
447447
for (i, a_coeff) in enumerate(a.coeffs)

src/other_functions.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ for T in (:Taylor1, :HomogeneousPolynomial, :TaylorN)
2323
@eval isnan(a::$T) = any(isnan, a.coeffs)
2424
end
2525

26+
# Rounding
27+
round(::Type{T}, x::AbstractSeries; kwargs...) where {T <: NumberNotSeries} =
28+
round(T, x, RoundNearest; kwargs...)
29+
round(::Type{T}, x::AbstractSeries, r::RoundingMode; kwargs...) where {T <: NumberNotSeries} =
30+
round(T, constant_term(x), r; kwargs...)
2631

2732
## Division functions: rem and mod ##
2833
for op in (:mod, :rem)
@@ -264,7 +269,7 @@ end
264269

265270
#update! function for TaylorN
266271
function update!(a::TaylorN{T}, vals::Vector{T}) where {T<:Number}
267-
a.coeffs .= evaluate(a, variables(order(a)) .+ vals).coeffs
272+
a.coeffs .= evaluate(a, variables(a.space; order=order(a)) .+ vals).coeffs
268273
return nothing
269274
end
270275
function update!(a::TaylorN{T}, vals::Vector{S}) where {T<:Number, S<:Number}

test/manyvariables.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ end
172172
@test get_variable_symbols() == [:x, :y]
173173
@test get_variable_symbols() == [:x, :y]
174174
@test TS.lookupvar(:x) == 1
175-
@test TS.lookupvar() == 0
175+
@test TS.lookupvar(TS.default_space[], ) == 0
176176
@test TS.get_variable_names() == ["x", "y"]
177177
@test x == HomogeneousPolynomial(Float64, 1)
178178
@test x == HomogeneousPolynomial(1)
@@ -364,6 +364,7 @@ end
364364
@test (1/(1-xT))[3] == HomogeneousPolynomial([1.0],3)
365365
@test xH^20 == HomogeneousPolynomial([0], order())
366366
@test (yT/(1-xT))[4] == xH^3 * yH
367+
@test round(Int, 1.0 + xT) === round(Int, 1.0 + yT) === round(Int, 1.0)
367368
@test mod(1+xT,1) == +xT
368369
@test (rem(1+xT,1))[0] == 0
369370
@test mod(1+xT,1.0) == +xT

test/mixtures.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ using Test
126126
@test -2*tN1 < -tN1^2 0
127127
end
128128

129+
@test round(Int, tN1 + 1.0) === round(Int, t1N + 1.0) === round(Int, 1.0)
129130
@test mod(tN1+1,1.0) == 0+tN1
130131
@test mod(tN1-1.125,2) == 0.875+tN1
131132
@test (rem(tN1+1.125,1.0))[0][1] == 0.125 + t

test/onevariable.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ Base.iszero(::SymbNumber) = false
237237
@test trational^3/complex(7,1) == Taylor1([0,0,0,complex(7//50,-1//50)],15)
238238
@test sqrt(zero(t)) == zero(t)
239239

240+
@test round(Int, 4.1 + t) === round(Int, 4.1)
240241
@test isapprox( rem(4.1 + t,4)[0], 0.1 )
241242
@test isapprox( mod(4.1 + t,4)[0], 0.1 )
242243
@test isapprox( rem(1+Taylor1(Int,4),4.0)[0], 1.0 )

0 commit comments

Comments
 (0)