Skip to content

static splat dispatch in default_Fun #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.7.14"
version = "0.7.15"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
2 changes: 1 addition & 1 deletion src/Multivariate/LowRankFun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export LowRankFun

"""
LowRankFun
LowRankFun(f, space::TensorSpace)

Return an approximation to a bivariate function in low rank form.

Expand Down
13 changes: 2 additions & 11 deletions src/Operators/general/PartialInverseOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ of `O` and `PartialInverseOperator(O)`.
```jldoctest
julia> C = Conversion(Chebyshev(), Ultraspherical(1));

julia> bandwidths(C)
(0, 2)

julia> P = PartialInverseOperator(C);

julia> bandwidths(P)
(0, 2)
julia> P = PartialInverseOperator(C); # default bandwidth = (0,2)

julia> P * C
TimesOperator : Chebyshev() → Chebyshev()
Expand All @@ -37,10 +31,7 @@ TimesOperator : Chebyshev() → Chebyshev()
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0 ⋱
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋱

julia> P = PartialInverseOperator(C, (0, 4));

julia> bandwidths(P)
(0, 4)
julia> P = PartialInverseOperator(C, (0, 4)); # increase the upper bandwidth

julia> P * C
TimesOperator : Chebyshev() → Chebyshev()
Expand Down
18 changes: 9 additions & 9 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ end

# default_Fun is the default constructor, based on evaluation and transforms
# last argument is whether to splat or not
default_Fun(T::Type,f,d::Space,pts::AbstractArray,::Type{Val{true}}) =
default_Fun(T::Type,f,d::Space,pts::AbstractArray, shouldsplat::Val{true}) =
Fun(d,transform(d,T[f(x...) for x in pts]))

default_Fun(T::Type,f,d::Space,pts::AbstractArray,::Type{Val{false}}) =
default_Fun(T::Type,f,d::Space,pts::AbstractArray, shouldsplat::Val{false}) =
Fun(d,transform(d,broadcast!(f, similar(pts, T), pts)))


function default_Fun(f,d::Space,n::Integer,::Type{Val{false}})
function default_Fun(f,d::Space,n::Integer, shouldsplat::Val{false})
pts=points(d, n)
f1=f(pts[1])
if isa(f1,AbstractArray) && size(d) ≠ size(f1)
Expand All @@ -54,10 +54,10 @@ function default_Fun(f,d::Space,n::Integer,::Type{Val{false}})

# we need 3 eltype calls for the case Interval(Point([1.,1.]))
Tprom=choosefuncfstype(typeof(f1),prectype(domain(d)))
default_Fun(Tprom,f,d,pts,Val{false})
default_Fun(Tprom,f,d,pts,Val(false))
end

function default_Fun(f,d::Space,n::Integer,::Type{Val{true}})
function default_Fun(f,d::Space,n::Integer, shouldsplat::Val{true})
pts=points(d, n)
f1=f(pts[1]...)
if isa(f1,AbstractArray) && size(d) ≠ size(f1)
Expand All @@ -66,10 +66,10 @@ function default_Fun(f,d::Space,n::Integer,::Type{Val{true}})

# we need 3 eltype calls for the case Interval(Point([1.,1.]))
Tprom=choosefuncfstype(typeof(f1),prectype(domain(d)))
default_Fun(Tprom,f,d,pts,Val{true})
default_Fun(Tprom,f,d,pts,Val(true))
end

default_Fun(f,d::Space,n::Integer) = default_Fun(f,d,n,Val{!hasnumargs(f,1)})
default_Fun(f,d::Space,n::Integer) = default_Fun(f,d,n,Val(!hasnumargs(f,1)))

Fun(f,d::Space,n::Integer) = default_Fun(dynamic(f),d,n)

Expand Down Expand Up @@ -117,10 +117,10 @@ function _default_Fun(f, d::Space)

for logn = 4:20
#cf = Fun(f, d, 2^logn + 1)
cf = default_Fun(f, d, 2^logn)
cf = default_Fun(f, d, 2^logn, Val(false))
maxabsc = maximum(abs,cf.coefficients)
if maxabsc == 0 && maxabsfr == 0
return(zeros(d))
return zeros(d)
end

b = block(d,length(cf.coefficients))
Expand Down