Skip to content

Commit 8895033

Browse files
authored
reintroduce literal_pow for Fun (#205)
1 parent c3cad8f commit 8895033

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
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.6"
3+
version = "0.7.7"
44

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

src/Fun.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,17 @@ function intpow(f::Fun,k::Integer)
376376
end
377377

378378
^(f::Fun, k::Integer) = intpow(f,k)
379+
# Ideally, constant propagation in intpow would handle literal exponentiation,
380+
# but currently inference doesn't succeed for f * f for arbitrary domains.
381+
# We specialize literal exponentiation here,
382+
# letting downstream users specialize f * f for custom domains
383+
# With f * f type-inferred, the type of f^2 would also be inferred.
384+
# This is a stopgap measure that might not be necessary in the future.
385+
Base.literal_pow(::typeof(^), f::Fun, ::Val{0}) = ones(cfstype(f), space(f))
386+
Base.literal_pow(::typeof(^), f::Fun, ::Val{1}) = f
387+
Base.literal_pow(::typeof(^), f::Fun, ::Val{2}) = f * f
388+
Base.literal_pow(::typeof(^), f::Fun, ::Val{3}) = f * f * f
389+
Base.literal_pow(::typeof(^), f::Fun, ::Val{4}) = f * f * f * f
379390

380391
inv(f::Fun) = 1/f
381392

0 commit comments

Comments
 (0)