Skip to content

Commit

Permalink
Specialize literal_pow for Fun (#115)
Browse files Browse the repository at this point in the history
* specialize literal_pow for Fun

* better inference in f^0

* version bump to v0.6.11
  • Loading branch information
jishnub authored Aug 16, 2022
1 parent 7453b41 commit 327cdb8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunBase"
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
version = "0.6.10"
version = "0.6.11"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
6 changes: 6 additions & 0 deletions src/Fun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ function intpow(f::Fun,k::Integer)
end

^(f::Fun, k::Integer) = intpow(f,k)
# some common cases
Base.literal_pow(::typeof(^), x::Fun, ::Val{0}) = ones(cfstype(x), space(x))
Base.literal_pow(::typeof(^), x::Fun, ::Val{1}) = x
Base.literal_pow(::typeof(^), x::Fun, ::Val{2}) = x * x
Base.literal_pow(::typeof(^), x::Fun, ::Val{3}) = x * x * x
Base.literal_pow(::typeof(^), x::Fun, ::Val{4}) = x * x * x * x

inv(f::Fun) = 1/f

Expand Down
17 changes: 17 additions & 0 deletions test/SpacesTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ using ApproxFunOrthogonalPolynomials
M2 = M + M
infty = ApproxFunBase.InfiniteCardinal{0}()
@test (@inferred size(M2)) == (infty, infty)

@testset "literal pow" begin
local f = Fun(PointSpace(1:3), Float64[1:3;])
@test (@inferred (x -> x^0)(f)) == ApproxFunBase.intpow(f,0)
@test (@inferred (x -> x^1)(f)) == ApproxFunBase.intpow(f,1)
@test (@inferred (x -> x^2)(f)) == ApproxFunBase.intpow(f,2)
@test (@inferred (x -> x^3)(f)) == ApproxFunBase.intpow(f,3)
@test (@inferred (x -> x^4)(f)) == ApproxFunBase.intpow(f,4)

local f = Fun(PointSpace(Float32[1:3;]), Float32[1:3;])
g = @inferred (x -> x^0)(f)
@test eltype(coefficients(g)) == Float32
g = @inferred (x -> x^1)(f)
@test eltype(coefficients(g)) == Float32
g = @inferred (x -> x^2)(f)
@test eltype(coefficients(g)) == Float32
end
end

@testset "Derivative operator for HeavisideSpace" begin
Expand Down

2 comments on commit 327cdb8

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/66327

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.11 -m "<description of version>" 327cdb8a8b631219c3faa562da9c1b2046b6a68f
git push origin v0.6.11

Please sign in to comment.