Skip to content

Commit b506908

Browse files
committed
"Manual" cherry-pick of 2de2acb
1 parent 0f66de4 commit b506908

File tree

4 files changed

+55
-50
lines changed

4 files changed

+55
-50
lines changed

ext/TaylorSeriesIAExt.jl

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using TaylorSeries
44

55
import Base: ^, sqrt, log, asin, acos, acosh, atanh, iszero, ==
66

7-
import TaylorSeries: _pow, pow!, evaluate, _evaluate, normalize_taylor
7+
import TaylorSeries: _pow, pow!, evaluate, _evaluate, normalize_taylor, aff_normalize
88

99
using IntervalArithmetic
1010

@@ -815,6 +815,7 @@ end
815815
evaluate(a::TaylorN{Taylor1{T}}, vals::AbstractVector{Interval{S}}) where
816816
{T<:Real, S<:NumTypes} = TS._evaluate(a, (vals...,), Val(false))
817817

818+
818819
# _evaluate
819820
function TS._evaluate(a::HomogeneousPolynomial{T},
820821
dx::AbstractVector{Interval{S}}) where {T<:Real, S<:NumTypes}
@@ -906,81 +907,80 @@ are mapped by an affine transformation to the intervals `-1..1`
906907
normalize_taylor(a::TaylorN, I::AbstractVector{Interval{T}},
907908
symI::Bool=true) where {T<:NumTypes} = _normalize(a, I, Val(symI))
908909

910+
aff_normalize(x, I::Interval, ::Val{true}) = interval(mid(I)) + x*interval(radius(I))
911+
aff_normalize(x, I::Interval, ::Val{false}) = interval(inf(I)) + x*interval(diam(I))
912+
909913
# I -> -1..1
910914
function _normalize(a::Taylor1, I::Interval{T}, ::Val{true}) where {T<:NumTypes}
911-
order = get_order(a)
912-
t = Taylor1(TS.numtype(a), order)
913-
tnew = mid(I) + t*radius(I)
914-
return a(tnew)
915+
t = Taylor1(TS.numtype(a), get_order(a))
916+
return a(aff_normalize(t, I, Val(true)))
915917
end
916918

917-
function _normalize(a::Taylor1{Interval{T}}, I::Interval{T}, ::Val{true}) where
918-
{T<:NumTypes}
919-
order = get_order(a)
920-
t = Taylor1(TS.numtype(a), order)
921-
tnew = interval(mid(I)) + t*interval(radius(I))
922-
return a(tnew)
923-
end
919+
# function _normalize(a::Taylor1{Interval{T}}, I::Interval{T}, ::Val{true}) where
920+
# {T<:NumTypes}
921+
# t = Taylor1(TS.numtype(a), get_order(a))
922+
# return a(aff_normalize(t, I, Val(true)))
923+
# end
924924

925925
# I -> 0..1
926926
function _normalize(a::Taylor1, I::Interval{T}, ::Val{false}) where {T<:NumTypes}
927-
order = get_order(a)
928-
t = Taylor1(TS.numtype(a), order)
929-
tnew = inf(I) + t*diam(I)
930-
return a(tnew)
927+
t = Taylor1(TS.numtype(a), get_order(a))
928+
return a(aff_normalize(t, I, Val(false)))
931929
end
932930

933-
function _normalize(a::Taylor1{Interval{T}}, I::Interval{T}, ::Val{false}) where
934-
{T<:NumTypes}
935-
order = get_order(a)
936-
t = Taylor1(TS.numtype(a), order)
937-
tnew = interval(inf(I)) + t*interval(diam(I))
938-
return a(tnew)
939-
end
931+
# function _normalize(a::Taylor1{Interval{T}}, I::Interval{T}, ::Val{false}) where
932+
# {T<:NumTypes}
933+
# t = Taylor1(TS.numtype(a), get_order(a))
934+
# return a(aff_normalize(t, I, Val(false)))
935+
# end
940936

941937
# I -> IntervalBox(-1..1, Val(N))
942938
function _normalize(a::TaylorN, I::AbstractVector{Interval{T}},
943939
::Val{true}) where {T<:NumTypes}
944940
order = get_order(a)
945941
x = Vector{typeof(a)}(undef, length(I))
946942
@inbounds for ind in eachindex(x)
947-
x[ind] = mid(I[ind]) + TaylorN(ind, order=order)*radius(I[ind])
943+
# x[ind] = mid(I[ind]) + TaylorN(ind, order=order)*radius(I[ind])
944+
x[ind] = aff_normalize(TaylorN(ind, order=order), I[ind], Val(true))
948945
end
949946
return a(x)
950947
end
951948

952-
function _normalize(a::TaylorN{Interval{T}}, I::AbstractVector{Interval{T}},
953-
::Val{true}) where {T<:NumTypes}
954-
order = get_order(a)
955-
x = Vector{typeof(a)}(undef, length(I))
956-
@inbounds for ind in eachindex(x)
957-
x[ind] = interval(mid(I[ind])) +
958-
TaylorN(ind, order=order)*interval(radius(I[ind]))
959-
end
960-
return a(x)
961-
end
949+
# function _normalize(a::TaylorN{Interval{T}}, I::AbstractVector{Interval{T}},
950+
# ::Val{true}) where {T<:NumTypes}
951+
# order = get_order(a)
952+
# x = Vector{typeof(a)}(undef, length(I))
953+
# @inbounds for ind in eachindex(x)
954+
# # x[ind] = interval(mid(I[ind])) +
955+
# # TaylorN(ind, order=order)*interval(radius(I[ind]))
956+
# x[ind] = aff_normalize(TaylorN(ind, order=order), I[ind], Val(true))
957+
# end
958+
# return a(x)
959+
# end
962960

963961
# I -> IntervalBox(0..1, Val(N))
964962
function _normalize(a::TaylorN, I::AbstractVector{Interval{T}},
965963
::Val{false}) where {T<:NumTypes}
966964
order = get_order(a)
967965
x = Vector{typeof(a)}(undef, length(I))
968966
@inbounds for ind in eachindex(x)
969-
x[ind] = inf(I[ind]) + TaylorN(ind, order=order)*diam(I[ind])
967+
# x[ind] = inf(I[ind]) + TaylorN(ind, order=order)*diam(I[ind])
968+
x[ind] = aff_normalize(TaylorN(ind, order=order), I[ind], Val(false))
970969
end
971970
return a(x)
972971
end
973972

974-
function _normalize(a::TaylorN{Interval{T}}, I::AbstractVector{Interval{T}},
975-
::Val{false}) where {T<:NumTypes}
976-
order = get_order(a)
977-
x = Vector{typeof(a)}(undef, length(I))
978-
@inbounds for ind in eachindex(x)
979-
x[ind] = interval(inf(I[ind])) +
980-
TaylorN(ind, order=order)*interval(diam(I[ind]))
981-
end
982-
return a(x)
983-
end
973+
# function _normalize(a::TaylorN{Interval{T}}, I::AbstractVector{Interval{T}},
974+
# ::Val{false}) where {T<:NumTypes}
975+
# order = get_order(a)
976+
# x = Vector{typeof(a)}(undef, length(I))
977+
# @inbounds for ind in eachindex(x)
978+
# # x[ind] = interval(inf(I[ind])) +
979+
# # TaylorN(ind, order=order)*interval(diam(I[ind]))
980+
# x[ind] = aff_normalize(TaylorN(ind, order=order), I[ind], Val(false))
981+
# end
982+
# return a(x)
983+
# end
984984

985985
# Printing-related methods numbr2str
986986
function TS.numbr2str(zz::Interval, ifirst::Bool=false)

src/auxiliary.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ Returns the type of the elements of the coefficients of `a`.
244244

245245
# Dumb methods included to properly export normalize_taylor (if IntervalArithmetic is loaded)
246246
@inline normalize_taylor(a::AbstractSeries) = a
247+
@inline aff_normalize(a::AbstractSeries) = a
247248

248249

249250
## _minorder

src/evaluate.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,16 @@ function evaluate(a::Taylor1{T}, dx::Taylor1{TaylorN{T}}) where {T<:NumberNotSer
102102
end
103103

104104

105-
# Evaluate a Taylor1{TaylorN{T}} on Vector{TaylorN} is interpreted
105+
# Evaluate a Taylor1{TaylorN{T}} on Vector{T} (or Vector{TaylorN{T}}) is interpreted
106106
# as a substitution on the TaylorN vars
107-
function evaluate(a::Taylor1{TaylorN{T}}, dx::Vector{TaylorN{T}}) where {T<:NumberNotSeries}
107+
function evaluate(a::Taylor1{TaylorN{T}}, dx::AbstractVector{S}) where {T<:NumberNotSeries, S<:NumberNotSeries}
108+
@assert length(dx) == get_numvars()
109+
suma = Taylor1( zero(a[0][0][1])*one(dx[1]), a.order)
110+
suma.coeffs .= evaluate.(a[:], Ref(dx))
111+
return suma
112+
end
113+
114+
function evaluate(a::Taylor1{TaylorN{T}}, dx::AbstractVector{TaylorN{T}}) where {T<:NumberNotSeries}
108115
@assert length(dx) == get_numvars()
109116
suma = Taylor1( zero(a[0]), a.order)
110117
suma.coeffs .= evaluate.(a[:], Ref(dx))

test/aqua.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ using Aqua
1818
for method_ambiguity in ambs
1919
@show method_ambiguity
2020
end
21-
if VERSION < v"1.10.0-DEV"
22-
@test length(ambs) == 0
23-
end
2421
end
2522

2623
@testset "Aqua tests (additional)" begin

0 commit comments

Comments
 (0)