Skip to content

Commit 153f4ad

Browse files
authored
remove DFunction (#413)
* remove DFunction * remove dynamic
1 parent 7ff2f2b commit 153f4ad

File tree

5 files changed

+54
-49
lines changed

5 files changed

+54
-49
lines changed

src/LinearAlgebra/helper.jl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -628,18 +628,8 @@ end
628628

629629

630630

631-
## Dynamic functions
632-
633-
struct DFunction{F} <: Function
634-
f :: F
635-
end
636-
(f::DFunction)(args...) = f.f(args...)
637-
638-
hasnumargs(f::DFunction, k) = hasnumargs(f.f, k)
639-
631+
# TODO: deprecate
640632
dynamic(f) = f
641-
dynamic(f::Function) = DFunction(f) # Assume f has to compile every time
642-
643633

644634
# Matrix inputs
645635

src/Multivariate/LowRankFun.jl

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,38 @@ end
8585

8686
## Adaptive constructor selector
8787

88-
function LowRankFun(fin::Function,dx::Space,dy::Space;
89-
method::Symbol=:standard,tolerance::Union{Symbol,Tuple{Symbol,Number}}=:relative,
90-
retmax::Bool=false,gridx::Integer=64,gridy::Integer=64,maxrank::Integer=100)
91-
f = dynamic(fin)
88+
function LowRankFun(f::Function, dx::Space, dy::Space;
89+
method::Symbol=:standard,
90+
tolerance::Union{Symbol,Tuple{Symbol,Number}}=:relative,
91+
retmax::Bool=false,
92+
gridx::Integer=64,
93+
gridy::Integer=64,
94+
maxrank::Integer=100,
95+
)
96+
9297
if method == :standard
93-
F,maxabsf=standardLowRankFun(f,dx,dy;tolerance=tolerance,gridx=gridx,gridy=gridy,maxrank=maxrank)
98+
F,maxabsf=standardLowRankFun(f, dx, dy; tolerance, gridx, gridy, maxrank)
9499
elseif method == :Cholesky
95100
@assert domain(dx) == domain(dy)
101+
G,maxabsf = CholeskyLowRankFun(f, dx; tolerance, grid=max(gridx,gridy), maxrank)
96102
if dx == dy
97-
F,maxabsf=CholeskyLowRankFun(f,dx;tolerance=tolerance,grid=max(gridx,gridy),maxrank=maxrank)
103+
F = G
98104
else
99-
G,maxabsf=CholeskyLowRankFun(f,dx;tolerance=tolerance,grid=max(gridx,gridy),maxrank=maxrank)
100-
F=LowRankFun(copy(G.A),map(b->Fun(b,dy),G.B))
105+
F = LowRankFun(copy(G.A), map(b->Fun(b,dy),G.B))
101106
end
102107
end
103108
retmax ? (F,maxabsf) : F
104109
end
105110

106111
## Standard adaptive construction
107112

108-
function standardLowRankFun(f::Function,dx::Space,dy::Space;tolerance::Union{Symbol,Tuple{Symbol,Number}}=:relative,gridx::Integer=64,gridy::Integer=64,maxrank::Integer=100)
113+
function standardLowRankFun(f::Function, dx::Space, dy::Space;
114+
tolerance::Union{Symbol,Tuple{Symbol,Number}}=:relative,
115+
gridx::Integer=64,
116+
gridy::Integer=64,
117+
maxrank::Integer=100
118+
)
119+
109120
xy = checkpoints(dxdy)
110121
T = promote_type(eltype(f(first(xy)...)),prectype(dx),prectype(dy))
111122

@@ -166,7 +177,11 @@ end
166177

167178
## Adaptive Cholesky decomposition, when f is Hermitian positive (negative) definite
168179

169-
function CholeskyLowRankFun(f::Function,dx::Space;tolerance::Union{Symbol,Tuple{Symbol,Number}}=:relative,grid::Integer=64,maxrank::Integer=100)
180+
function CholeskyLowRankFun(f::Function,dx::Space;
181+
tolerance::Union{Symbol,Tuple{Symbol,Number}}=:relative,
182+
grid::Integer=64,
183+
maxrank::Integer=100)
184+
170185
xy = checkpoints(dxdx)
171186
T = promote_type(eltype(f(first(xy)...)),prectype(dx))
172187

@@ -216,20 +231,22 @@ function CholeskyLowRankFun(f::Function,dx::Space;tolerance::Union{Symbol,Tuple{
216231
chop!(a,tol10)
217232
end
218233
@warn "Maximum rank of " * string(maxrank) * " reached"
219-
return LowRankFun(A,B),maxabsf
234+
return LowRankFun(A,B), maxabsf
220235
end
221236

222237

223238
## Construction via TensorSpaces and ProductDomains
224239

225-
LowRankFun(f::Function,S::TensorSpace{SV,DD,RR};kwds...) where {SV,DD<:EuclideanDomain{2},RR} =
226-
LowRankFun(dynamic(f),factor(S,1),factor(S,2);kwds...)
227-
LowRankFun(f::Function,dx::Domain,dy::Domain;kwds...) =
228-
LowRankFun(dynamic(f),Space(dx),Space(dy);kwds...)
229-
LowRankFun(f::Function,d::ProductDomain;kwds...) =
230-
LowRankFun(dynamic(f),factors(d)...;kwds...)
240+
LowRankFun(f::Function, S::TensorSpace{SV,DD,RR}; kwds...) where {SV,DD<:EuclideanDomain{2},RR} =
241+
LowRankFun(f, factor(S,1), factor(S,2); kwds...)
242+
243+
LowRankFun(f::Function, dx::Domain, dy::Domain;kwds...) =
244+
LowRankFun(f, Space(dx), Space(dy); kwds...)
245+
246+
LowRankFun(f::Function, d::ProductDomain; kwds...) =
247+
LowRankFun(f, factors(d)...; kwds...)
231248

232-
LowRankFun(f::Function;kwds...) = LowRankFun(dynamic(f),ChebyshevInterval(),ChebyshevInterval();kwds...)
249+
LowRankFun(f::Function; kwds...) = LowRankFun(f,ChebyshevInterval(),ChebyshevInterval();kwds...)
233250

234251
## Construction from values
235252

src/Multivariate/ProductFun.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ end
115115

116116
## Adaptive construction
117117

118-
function ProductFun(f::Function,sp::AbstractProductSpace{Tuple{S,V}};tol=100eps()) where {S<:UnivariateSpace,V<:UnivariateSpace}
118+
function ProductFun(f::Function, sp::AbstractProductSpace{Tuple{S,V}}; tol=100eps()) where {S<:UnivariateSpace,V<:UnivariateSpace}
119119
for n = 50:100:5000
120-
X = coefficients(ProductFun(dynamic(f),sp,n,n;tol=tol))
120+
X = coefficients(ProductFun(f,sp,n,n;tol=tol))
121121
if size(X,1)<n && size(X,2)<n
122122
return ProductFun(X,sp;tol=tol)
123123
end
@@ -135,18 +135,18 @@ function ProductFun(f::Function,S::AbstractProductSpace,M::Integer,N::Integer;to
135135
vals=T[f(ptsx[k,j],ptsy[k,j]) for k=1:size(ptsx,1), j=1:size(ptsx,2)]
136136
ProductFun(transform!(S,vals),S;tol=tol,chopping=true)
137137
end
138-
ProductFun(f::Function,S::TensorSpace) = ProductFun(LowRankFun(dynamic(f),S))
138+
ProductFun(f::Function,S::TensorSpace) = ProductFun(LowRankFun(f,S))
139139

140-
ProductFun(f,dx::Space,dy::Space)=ProductFun(dynamic(f),TensorSpace(dx,dy))
140+
ProductFun(f,dx::Space,dy::Space)=ProductFun(f,TensorSpace(dx,dy))
141141

142-
ProductFun(f::Function,dx::Space,dy::Space)=ProductFun(dynamic(f),TensorSpace(dx,dy))
142+
ProductFun(f::Function,dx::Space,dy::Space)=ProductFun(f,TensorSpace(dx,dy))
143143

144144
## Domains promoted to Spaces
145145

146-
ProductFun(f::Function,D::Domain,M::Integer,N::Integer) = ProductFun(dynamic(f),Space(D),M,N)
147-
ProductFun(f::Function,d::Domain) = ProductFun(dynamic(f),Space(d))
148-
ProductFun(f::Function, dx::Domain{<:Number}, dy::Domain{<:Number}) = ProductFun(dynamic(f),Space(dx),Space(dy))
149-
ProductFun(f::Function) = ProductFun(dynamic(f),ChebyshevInterval(),ChebyshevInterval())
146+
ProductFun(f::Function,D::Domain,M::Integer,N::Integer) = ProductFun(f,Space(D),M,N)
147+
ProductFun(f::Function,d::Domain) = ProductFun(f,Space(d))
148+
ProductFun(f::Function, dx::Domain{<:Number}, dy::Domain{<:Number}) = ProductFun(f,Space(dx),Space(dy))
149+
ProductFun(f::Function) = ProductFun(f,ChebyshevInterval(),ChebyshevInterval())
150150

151151
## Conversion from other 2D Funs
152152

@@ -196,7 +196,7 @@ end
196196
## For specifying spaces by anonymous function
197197

198198
ProductFun(f::Function,SF::Function,T::Space,M::Integer,N::Integer) =
199-
ProductFun(dynamic(f),typeof(SF(1))[SF(k) for k=1:N],T,M)
199+
ProductFun(f,typeof(SF(1))[SF(k) for k=1:N],T,M)
200200

201201
## Conversion of a constant to a ProductFun
202202

src/constructors.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ end
6868

6969
default_Fun(f,d::Space,n::Integer) = default_Fun(f,d,n,Val(!hasonearg(f)))
7070

71-
Fun(f,d::Space,n::Integer) = default_Fun(dynamic(f),d,n)
71+
Fun(f,d::Space,n::Integer) = default_Fun(f,d,n)
7272

7373
# the following is to avoid ambiguity
7474
# Fun(f::Fun,d) should be equivalent to Fun(x->f(x),d)
7575
Fun(f::Fun,d::Space) = Fun(d,coefficients(f,d))
7676
Fun(f::Fun,::Type{T}) where {T<:Space} = Fun(f,T(domain(f)))
7777

7878

79-
Fun(f,T::Type) = Fun(dynamic(f),T())
80-
Fun(f,T::Type,n::Integer) = Fun(dynamic(f),T(),n)
79+
Fun(f,T::Type) = Fun(f,T())
80+
Fun(f,T::Type,n::Integer) = Fun(f,T(),n)
8181

8282
Fun(f::AbstractVector,d::Domain) = Fun(f,Space(d))
8383
Fun(d::Domain,f::AbstractVector) = Fun(Space(d),f)
8484

8585

86-
Fun(f,d::Domain,n) = Fun(dynamic(f),Space(d),n)
86+
Fun(f,d::Domain,n) = Fun(f,Space(d),n)
8787

8888

8989
# We do zero special since zero exists even when one doesn't
@@ -172,7 +172,7 @@ ones(::Type{T}, S::Space) where {T<:Number} = Fun(x->one(T),S)
172172
function Fun(::typeof(identity), d::Domain)
173173
cd=canonicaldomain(d)
174174
if typeof(d) == typeof(cd)
175-
Fun(dynamic(x->x),d) # fall back to constructor, can't use `identity` as that creates a loop
175+
Fun(x->x, d) # fall back to constructor, can't use `identity` as that creates a loop
176176
else
177177
# this allows support for singularities, that the constructor doesn't
178178
sf=fromcanonical(d,Fun(identity,cd))
@@ -222,7 +222,7 @@ julia> f(0.1) == (0.1)^2
222222
true
223223
```
224224
"""
225-
Fun(f, d::Space) = default_Fun(dynamic(f), d)
225+
Fun(f, d::Space) = default_Fun(f, d)
226226

227227
# this supports expanding a Fun to a larger or smaller domain.
228228
# we take the union and then intersection to get at any singularities

src/hacks.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ julia> f(0.1, 0.2) ≈ 0.3
3636
true
3737
```
3838
"""
39-
function Fun(fin::Function)
40-
f = dynamic(fin)
41-
42-
if hasnumargs(f,1)
39+
function Fun(f::Function)
40+
if hasonearg(f)
4341
# check for tuple
4442
try
4543
f(0)

0 commit comments

Comments
 (0)