Skip to content

Commit 9437c3f

Browse files
authored
Solve invalidations (#344)
* Comment code leading to an ambiguity * Solve some invalidations * Solve problem with docstrings of _populate_dicts! * Solve ambiguities when IA is loaded, with tests * Bump patch version * Bring back a conditional test
1 parent 9a16131 commit 9437c3f

File tree

9 files changed

+130
-97
lines changed

9 files changed

+130
-97
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
test:
17-
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.julia-threads }} thread(s) - ${{ github.event_name }}
17+
name: Julia ${{ matrix.julia-version }} - ${{ matrix.os }} - ${{ matrix.julia-threads }} thread(s) - ${{ github.event_name }}
1818
runs-on: ${{ matrix.os }}
1919
if: "!contains(github.event.head_commit.message, 'skip ci')"
2020
env:

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.15.3"
4+
version = "0.15.4"
55

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

docs/src/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ _dict_unary_ops
9797
_dict_binary_calls
9898
_dict_unary_calls
9999
_dict_binary_ops
100+
_populate_dicts!
100101
@isonethread
101102
```
102103

ext/TaylorSeriesIAExt.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ isdefined(Base, :get_extension) ? (using IntervalArithmetic) : (using ..Interval
1010

1111
# Method used for Taylor1{Interval{T}}^n
1212
for T in (:Taylor1, :TaylorN)
13-
@eval function ^(a::$T{Interval{S}}, n::Integer) where {S<:Real}
14-
n == 0 && return one(a)
15-
n == 1 && return copy(a)
16-
n == 2 && return square(a)
17-
n < 0 && return a^float(n)
18-
return power_by_squaring(a, n)
13+
@eval begin
14+
function ^(a::$T{Interval{S}}, n::Integer) where {S<:Real}
15+
n == 0 && return one(a)
16+
n == 1 && return copy(a)
17+
n == 2 && return square(a)
18+
n < 0 && return a^float(n)
19+
return power_by_squaring(a, n)
20+
end
21+
^(a::$T{Interval{S}}, r::Rational) where {S<:Real} = a^float(r)
1922
end
2023
end
2124

src/conversion.jl

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,26 @@ function convert(::Type{Taylor1{TaylorN{T}}}, s::TaylorN{Taylor1{T}}) where {T<:
127127
return Taylor1(vT)
128128
end
129129

130-
function convert(::Type{Array{TaylorN{Taylor1{T}},N}},
131-
s::Array{Taylor1{TaylorN{T}},N}) where {T<:NumberNotSeries,N}
132-
133-
v = Array{TaylorN{Taylor1{T}}}(undef, size(s))
134-
@simd for ind in eachindex(s)
135-
@inbounds v[ind] = convert(TaylorN{Taylor1{T}}, s[ind])
136-
end
137-
return v
138-
end
139-
140-
function convert(::Type{Array{Taylor1{TaylorN{T}},N}},
141-
s::Array{TaylorN{Taylor1{T}},N}) where {T<:NumberNotSeries,N}
142-
143-
v = Array{Taylor1{TaylorN{T}}}(undef, size(s))
144-
@simd for ind in eachindex(s)
145-
@inbounds v[ind] = convert(Taylor1{TaylorN{T}}, s[ind])
146-
end
147-
return v
148-
end
130+
# iss 339: this triggers some invalidations
131+
# function convert(::Type{Array{TaylorN{Taylor1{T}},N}},
132+
# s::Array{Taylor1{TaylorN{T}},N}) where {T<:NumberNotSeries,N}
133+
#
134+
# v = Array{TaylorN{Taylor1{T}}}(undef, size(s))
135+
# @simd for ind in eachindex(s)
136+
# @inbounds v[ind] = convert(TaylorN{Taylor1{T}}, s[ind])
137+
# end
138+
# return v
139+
# end
140+
#
141+
# function convert(::Type{Array{Taylor1{TaylorN{T}}}},
142+
# s::Array{TaylorN{Taylor1{T}}}) where {T<:NumberNotSeries}
143+
#
144+
# v = Array{Taylor1{TaylorN{T}}}(undef, size(s))
145+
# @simd for ind in eachindex(s)
146+
# @inbounds v[ind] = convert(Taylor1{TaylorN{T}}, s[ind])
147+
# end
148+
# return v
149+
# end
149150

150151

151152

@@ -197,11 +198,13 @@ promote_rule(::Type{TaylorN{T}}, ::Type{S}) where {T<:Number,S<:Number} =
197198
TaylorN{promote_type(T,S)}
198199

199200

200-
# Order may matter
201-
promote_rule(::Type{S}, ::Type{T}) where {S<:NumberNotSeries,T<:AbstractSeries} =
202-
promote_rule(T,S)
203-
# disambiguation with Base
204-
promote_rule(::Type{Bool}, ::Type{T}) where {T<:AbstractSeries} = promote_rule(T, Bool)
201+
# iss 339: this triggers some invalidations
202+
# # Order may matter
203+
# promote_rule(::Type{S}, ::Type{T}) where {S<:NumberNotSeries, T<:AbstractSeries} =
204+
# promote_rule(T,S)
205+
#
206+
# # disambiguation with Base
207+
# promote_rule(::Type{Bool}, ::Type{T}) where {T<:AbstractSeries} = promote_rule(T, Bool)
205208

206209
promote_rule(::Type{S}, ::Type{T}) where
207210
{S<:AbstractIrrational,T<:AbstractSeries} = promote_rule(T,S)

src/dictmutfunct.jl

Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct _InternalMutFuncs
2929
end
3030

3131
# Constructor
32-
function _InternalMutFuncs( namef::Vector )
32+
function _InternalMutFuncs( namef::Tuple )
3333
if length(namef) == 3
3434
return _InternalMutFuncs( namef[1], namef[2], namef[3], Expr(:nothing) )
3535
else
@@ -56,11 +56,11 @@ of `:_res`.
5656
5757
"""
5858
const _dict_binary_ops = Dict(
59-
:+ => [:add!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 + _arg2)],
60-
:- => [:subst!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 - _arg2)],
61-
:* => [:mul!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 * _arg2)],
62-
:/ => [:div!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 / _arg2)],
63-
:^ => [:pow!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 ^ float(_arg2))],
59+
:+ => (:add!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 + _arg2)),
60+
:- => (:subst!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 - _arg2)),
61+
:* => (:mul!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 * _arg2)),
62+
:/ => (:div!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 / _arg2)),
63+
:^ => (:pow!, (:_res, :_arg1, :_arg2, :_k), :(_res = _arg1 ^ float(_arg2))),
6464
);
6565

6666
"""
@@ -83,50 +83,50 @@ added as the last entry of the vector.
8383
8484
"""
8585
const _dict_unary_ops = Dict(
86-
:+ => [:add!, (:_res, :_arg1, :_k), :(_res = + _arg1)],
87-
:- => [:subst!, (:_res, :_arg1, :_k), :(_res = - _arg1)],
88-
:sqr => [:sqr!, (:_res, :_arg1, :_k), :(_res = sqr(_arg1))],
89-
:sqrt => [:sqrt!, (:_res, :_arg1, :_k), :(_res = sqrt(_arg1))],
90-
:exp => [:exp!, (:_res, :_arg1, :_k), :(_res = exp(_arg1))],
91-
:expm1 => [:expm1!, (:_res, :_arg1, :_k), :(_res = expm1(_arg1))],
92-
:log => [:log!, (:_res, :_arg1, :_k), :(_res = log(_arg1))],
93-
:log1p => [:log1p!, (:_res, :_arg1, :_k), :(_res = log1p(_arg1))],
94-
:identity => [:identity!, (:_res, :_arg1, :_k), :(_res = identity(_arg1))],
95-
:zero => [:zero!, (:_res, :_arg1, :_k), :(_res = zero(_arg1))],
96-
:one => [:one!, (:_res, :_arg1, :_k), :(_res = one(_arg1))],
97-
:abs => [:abs!, (:_res, :_arg1, :_k), :(_res = abs(_arg1))],
98-
:abs2 => [:abs2!, (:_res, :_arg1, :_k), :(_res = abs2(_arg1))],
99-
:deg2rad => [:deg2rad!, (:_res, :_arg1, :_k), :(_res = deg2rad(_arg1))],
100-
:rad2deg => [:rad2deg!, (:_res, :_arg1, :_k), :(_res = rad2deg(_arg1))],
86+
:+ => (:add!, (:_res, :_arg1, :_k), :(_res = + _arg1)),
87+
:- => (:subst!, (:_res, :_arg1, :_k), :(_res = - _arg1)),
88+
:sqr => (:sqr!, (:_res, :_arg1, :_k), :(_res = sqr(_arg1))),
89+
:sqrt => (:sqrt!, (:_res, :_arg1, :_k), :(_res = sqrt(_arg1))),
90+
:exp => (:exp!, (:_res, :_arg1, :_k), :(_res = exp(_arg1))),
91+
:expm1 => (:expm1!, (:_res, :_arg1, :_k), :(_res = expm1(_arg1))),
92+
:log => (:log!, (:_res, :_arg1, :_k), :(_res = log(_arg1))),
93+
:log1p => (:log1p!, (:_res, :_arg1, :_k), :(_res = log1p(_arg1))),
94+
:identity => (:identity!, (:_res, :_arg1, :_k), :(_res = identity(_arg1))),
95+
:zero => (:zero!, (:_res, :_arg1, :_k), :(_res = zero(_arg1))),
96+
:one => (:one!, (:_res, :_arg1, :_k), :(_res = one(_arg1))),
97+
:abs => (:abs!, (:_res, :_arg1, :_k), :(_res = abs(_arg1))),
98+
:abs2 => (:abs2!, (:_res, :_arg1, :_k), :(_res = abs2(_arg1))),
99+
:deg2rad => (:deg2rad!, (:_res, :_arg1, :_k), :(_res = deg2rad(_arg1))),
100+
:rad2deg => (:rad2deg!, (:_res, :_arg1, :_k), :(_res = rad2deg(_arg1))),
101101
#
102-
:sin => [:sincos!, (:_res, :_aux, :_arg1, :_k), :(_res = sin(_arg1)),
103-
:(_aux = cos(_arg1))],
104-
:cos => [:sincos!, (:_aux, :_res, :_arg1, :_k), :(_res = cos(_arg1)),
105-
:(_aux = sin(_arg1))],
106-
:sinpi => [:sincospi!, (:_res, :_aux, :_arg1, :_k), :(_res = sinpi(_arg1)),
107-
:(_aux = cospi(_arg1))],
108-
:cospi => [:sincospi!, (:_aux, :_res, :_arg1, :_k), :(_res = cospi(_arg1)),
109-
:(_aux = sinpi(_arg1))],
110-
:tan => [:tan!, (:_res, :_arg1, :_aux, :_k), :(_res = tan(_arg1)),
111-
:(_aux = tan(_arg1)^2)],
112-
:asin => [:asin!, (:_res, :_arg1, :_aux, :_k), :(_res = asin(_arg1)),
113-
:(_aux = sqrt(1 - _arg1^2))],
114-
:acos => [:acos!, (:_res, :_arg1, :_aux, :_k), :(_res = acos(_arg1)),
115-
:(_aux = sqrt(1 - _arg1^2))],
116-
:atan => [:atan!, (:_res, :_arg1, :_aux, :_k), :(_res = atan(_arg1)),
117-
:(_aux = 1 + _arg1^2)],
118-
:sinh => [:sinhcosh!, (:_res, :_aux, :_arg1, :_k), :(_res = sinh(_arg1)),
119-
:(_aux = cosh(_arg1))],
120-
:cosh => [:sinhcosh!, (:_aux, :_res, :_arg1, :_k), :(_res = cosh(_arg1)),
121-
:(_aux = sinh(_arg1))],
122-
:tanh => [:tanh!, (:_res, :_arg1, :_aux, :_k), :(_res = tanh(_arg1)),
123-
:(_aux = tanh(_arg1)^2)],
124-
:asinh => [:asinh!, (:_res, :_arg1, :_aux, :_k), :(_res = asinh(_arg1)),
125-
:(_aux = sqrt(_arg1^2 + 1))],
126-
:acosh => [:acosh!, (:_res, :_arg1, :_aux, :_k), :(_res = acosh(_arg1)),
127-
:(_aux = sqrt(_arg1^2 - 1))],
128-
:atanh => [:atanh!, (:_res, :_arg1, :_aux, :_k), :(_res = atanh(_arg1)),
129-
:(_aux = 1 - _arg1^2)],
102+
:sin => (:sincos!, (:_res, :_aux, :_arg1, :_k), :(_res = sin(_arg1)),
103+
:(_aux = cos(_arg1))),
104+
:cos => (:sincos!, (:_aux, :_res, :_arg1, :_k), :(_res = cos(_arg1)),
105+
:(_aux = sin(_arg1))),
106+
:sinpi => (:sincospi!, (:_res, :_aux, :_arg1, :_k), :(_res = sinpi(_arg1)),
107+
:(_aux = cospi(_arg1))),
108+
:cospi => (:sincospi!, (:_aux, :_res, :_arg1, :_k), :(_res = cospi(_arg1)),
109+
:(_aux = sinpi(_arg1))),
110+
:tan => (:tan!, (:_res, :_arg1, :_aux, :_k), :(_res = tan(_arg1)),
111+
:(_aux = tan(_arg1)^2)),
112+
:asin => (:asin!, (:_res, :_arg1, :_aux, :_k), :(_res = asin(_arg1)),
113+
:(_aux = sqrt(1 - _arg1^2))),
114+
:acos => (:acos!, (:_res, :_arg1, :_aux, :_k), :(_res = acos(_arg1)),
115+
:(_aux = sqrt(1 - _arg1^2))),
116+
:atan => (:atan!, (:_res, :_arg1, :_aux, :_k), :(_res = atan(_arg1)),
117+
:(_aux = 1 + _arg1^2)),
118+
:sinh => (:sinhcosh!, (:_res, :_aux, :_arg1, :_k), :(_res = sinh(_arg1)),
119+
:(_aux = cosh(_arg1))),
120+
:cosh => (:sinhcosh!, (:_aux, :_res, :_arg1, :_k), :(_res = cosh(_arg1)),
121+
:(_aux = sinh(_arg1))),
122+
:tanh => (:tanh!, (:_res, :_arg1, :_aux, :_k), :(_res = tanh(_arg1)),
123+
:(_aux = tanh(_arg1)^2)),
124+
:asinh => (:asinh!, (:_res, :_arg1, :_aux, :_k), :(_res = asinh(_arg1)),
125+
:(_aux = sqrt(_arg1^2 + 1))),
126+
:acosh => (:acosh!, (:_res, :_arg1, :_aux, :_k), :(_res = acosh(_arg1)),
127+
:(_aux = sqrt(_arg1^2 - 1))),
128+
:atanh => (:atanh!, (:_res, :_arg1, :_aux, :_k), :(_res = atanh(_arg1)),
129+
:(_aux = 1 - _arg1^2)),
130130
);
131131

132132

@@ -146,8 +146,32 @@ _internalmutfunc_call( fn :: _InternalMutFuncs ) = (
146146
Expr( :call, Meta.parse("TaylorSeries.$(fn.namef)"), fn.argsf... ), fn.defexpr, fn.auxexpr )
147147

148148

149+
"""
150+
`_populate_dicts!()`
149151
152+
Function that populates the internal dictionaries [`_dict_unary_calls`](@ref) and
153+
[`_dict_binary_calls`](@ref)
150154
"""
155+
function _populate_dicts!()
156+
#Populates the constant vector `_dict_unary_calls`.
157+
_dict_unary_calls = Dict{Symbol, NTuple{3,Expr}}()
158+
for kk in keys(_dict_unary_ops)
159+
res = _internalmutfunc_call( _InternalMutFuncs(_dict_unary_ops[kk]) )
160+
push!(_dict_unary_calls, kk => res )
161+
end
162+
163+
#Populates the constant vector `_dict_binary_calls`.
164+
_dict_binary_calls = Dict{Symbol, NTuple{3,Expr}}()
165+
for kk in keys(_dict_binary_ops)
166+
res = _internalmutfunc_call( _InternalMutFuncs(_dict_binary_ops[kk]) )
167+
push!(_dict_binary_calls, kk => res )
168+
end
169+
return _dict_unary_calls, _dict_binary_calls
170+
end
171+
172+
const _dict_unary_calls, _dict_binary_calls = _populate_dicts!()
173+
174+
@doc """
151175
`_dict_unary_calls::Dict{Symbol, NTuple{2,Expr}}`
152176
153177
Dictionary with the expressions that define the
@@ -158,16 +182,16 @@ internal mutating functions.
158182
159183
Evaluating the entries generates expressions that represent
160184
the actual calls to the internal mutating functions.
161-
"""
162-
const _dict_unary_calls = Dict{Symbol, NTuple{3,Expr}}()
185+
""" _dict_unary_calls
186+
# const _dict_unary_calls = Dict{Symbol, NTuple{3,Expr}}()
163187

164-
#Populates the constant vector `_dict_unary_calls`.
165-
for kk in keys(_dict_unary_ops)
166-
res = _internalmutfunc_call( _InternalMutFuncs(_dict_unary_ops[kk]) )
167-
push!(_dict_unary_calls, kk => res )
168-
end
188+
# #Populates the constant vector `_dict_unary_calls`.
189+
# for kk in keys(_dict_unary_ops)
190+
# res = _internalmutfunc_call( _InternalMutFuncs(_dict_unary_ops[kk]) )
191+
# push!(_dict_unary_calls, kk => res )
192+
# end
169193

170-
"""
194+
@doc """
171195
`_dict_binary_calls::Dict{Symbol, NTuple{2,Expr}}`
172196
173197
Dictionary with the expressions that define the
@@ -178,10 +202,6 @@ internal mutating functions.
178202
179203
Evaluating the entries generates symbols that represent
180204
the actual calls to the internal mutating functions.
181-
"""
182-
const _dict_binary_calls = Dict{Symbol, NTuple{3,Expr}}()
183-
#Populates the constant vector `_dict_binary_calls`.
184-
for kk in keys(_dict_binary_ops)
185-
res = _internalmutfunc_call( _InternalMutFuncs(_dict_binary_ops[kk]) )
186-
push!(_dict_binary_calls, kk => res )
187-
end
205+
""" _dict_binary_calls
206+
# const _dict_binary_calls = Dict{Symbol, NTuple{3,Expr}}()
207+

src/power.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ for T in (:Taylor1, :TaylorN)
4747
return power_by_squaring(a, n)
4848
end
4949

50-
@eval ^(a::$T, x::Rational) = a^(x.num/x.den)
50+
@eval ^(a::$T, x::S) where {S<:Rational} = a^(x.num/x.den)
5151

5252
@eval ^(a::$T, b::$T) = exp( b*log(a) )
5353

test/aqua.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ using Aqua
1515
pkg_match(pkgname, pkdir::Nothing) = false
1616
pkg_match(pkgname, pkdir::AbstractString) = occursin(pkgname, pkdir)
1717
filter!(x -> pkg_match("TaylorSeries", pkgdir(last(x).module)), ambs)
18+
for method_ambiguity in ambs
19+
@show method_ambiguity
20+
end
1821
if VERSION < v"1.10.0-DEV"
1922
@test length(ambs) == 0
2023
end
@@ -27,6 +30,7 @@ end
2730
Aqua.test_piracies(TaylorSeries)
2831
Aqua.test_unbound_args(TaylorSeries)
2932
Aqua.test_project_extras(TaylorSeries)
33+
Aqua.test_persistent_tasks(TaylorSeries)
3034
end
3135

3236
nothing

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ for file in testfiles
1919
VERSION < v"1.1" && file == "intervals.jl" && continue
2020
include(file)
2121
end
22+
# After `using intervalArithmetic` new ambiguities may arise
23+
include("aqua.jl")

0 commit comments

Comments
 (0)