Skip to content

Commit 7d7c6db

Browse files
authored
improve inference in literal exponentiation (#202)
* improve inference in literal exponentiation * don't use space in + * domainscompatible for ChebyshevInterval
1 parent 0776be3 commit 7d7c6db

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.7.3"
3+
version = "0.7.4"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Domain.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ domainscompatible(a,b) = domainscompatible(domain(a),domain(b))
6565
domainscompatible(a::Domain,b::Domain) = isambiguous(a) || isambiguous(b) ||
6666
isapprox(a,b)
6767

68+
domainscompatible(::ChebyshevInterval, ::ChebyshevInterval) = true
69+
6870
##TODO: Should fromcanonical be fromcanonical!?
6971

7072
#TODO consider moving these

src/Fun.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ end
356356

357357
function intpow(f::Fun,k::Integer)
358358
if k == 0
359-
ones(space(f))
359+
ones(cfstype(f), space(f))
360360
elseif k==1
361361
f
362362
else
363-
t = reduce(*, fill(f, abs(k)))
363+
t = foldl(*, fill(f, abs(k)))
364364
if k > 0
365365
return t
366366
else
@@ -370,12 +370,6 @@ function intpow(f::Fun,k::Integer)
370370
end
371371

372372
^(f::Fun, k::Integer) = intpow(f,k)
373-
# some common cases
374-
Base.literal_pow(::typeof(^), x::Fun, ::Val{0}) = ones(cfstype(x), space(x))
375-
Base.literal_pow(::typeof(^), x::Fun, ::Val{1}) = x
376-
Base.literal_pow(::typeof(^), x::Fun, ::Val{2}) = x * x
377-
Base.literal_pow(::typeof(^), x::Fun, ::Val{3}) = x * x * x
378-
Base.literal_pow(::typeof(^), x::Fun, ::Val{4}) = x * x * x * x
379373

380374
inv(f::Fun) = 1/f
381375

src/Multivariate/TensorSpace.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ Space(sp::ProductDomain) = TensorSpace(sp)
252252
setdomain(sp::TensorSpace, d::ProductDomain) = TensorSpace(setdomain.(factors(sp), factors(d)))
253253

254254
*(A::Space, B::Space) = AB
255-
^(A::Space, p::Integer) = p == 1 ? A : A*A^(p-1)
255+
function ^(A::Space, p::Integer)
256+
p >= 1 || throw(ArgumentError("exponent must be >= 1, received $p"))
257+
p == 1 ? A : foldl(*, ntuple(_ -> A, p))
258+
end
256259

257260

258261
## TODO: generalize

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ end
104104
@test Segment(1,2) .^ 2 Segment(1,4)
105105
@test sqrt.(Segment(1,2)) Segment(1,sqrt(2))
106106

107+
@testset "ChebyshevInterval" begin
108+
@test @inferred ApproxFunBase.domainscompatible(ChebyshevInterval{Float64}(), ChebyshevInterval{Float32}())
109+
@test @inferred ApproxFunBase.domainscompatible(ChebyshevInterval{Float64}(), ChebyshevInterval{BigFloat}())
110+
end
111+
107112
@testset "union" begin
108113
a = ApproxFunBase.EmptyDomain()
109114
b = ApproxFunBase.AnyDomain()

0 commit comments

Comments
 (0)