Skip to content

Commit dbe2bb5

Browse files
authored
improve inference in LowRankFun (#225)
1 parent 0b12c85 commit dbe2bb5

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
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.17"
3+
version = "0.7.18"
44

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

src/Multivariate/LowRankFun.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@ function standardLowRankFun(f::Function,dx::Space,dy::Space;tolerance::Union{Sym
107107
ptsx,ptsy=points(dx,gridx),points(dy,gridy)
108108
X = zeros(T,gridx,gridy)
109109
maxabsf,r=findapproxmax!(f,X,ptsx,ptsy,gridx,gridy)
110-
if maxabsf < eps(zero(T))/eps(T) return LowRankFun([Fun(dx,[zero(T)])],[Fun(dy,[zero(T)])]),maxabsf end
111-
a,b=Fun(x->f(x,r[2]),dx),Fun(y->f(r[1],y),dy)
110+
if maxabsf < eps(zero(T))/eps(T)
111+
return LowRankFun([Fun(dx,[zero(T)])],[Fun(dy,[zero(T)])]), maxabsf
112+
end
113+
114+
a,b=let r1=r[1], r2=r[2] # avoid boxing r
115+
Fun(x->f(x,r2),dx),Fun(y->f(r1,y),dy)
116+
end
112117

113118
# If necessary, we resize the grid to be at least as large as the
114119
# lengths of the first row and column Funs and we recompute the values of X.
@@ -117,7 +122,9 @@ function standardLowRankFun(f::Function,dx::Space,dy::Space;tolerance::Union{Sym
117122
ptsx,ptsy=points(dx,gridx),points(dy,gridy)
118123
X = zeros(T,gridx,gridy)
119124
maxabsf,r=findapproxmax!(f,X,ptsx,ptsy,gridx,gridy)
120-
a,b=Fun(x->f(x,r[2]),dx),Fun(y->f(r[1],y),dy)
125+
a,b=let r1=r[1], r2=r[2]
126+
Fun(x->f(x,r2),dx),Fun(y->f(r1,y),dy)
127+
end
121128
end
122129

123130
A,B=typeof(a)[],typeof(b)[]
@@ -161,8 +168,12 @@ function CholeskyLowRankFun(f::Function,dx::Space;tolerance::Union{Symbol,Tuple{
161168
pts=points(dx,grid)
162169
X = zeros(T,grid)
163170
maxabsf,r=findcholeskyapproxmax!(f,X,pts,grid)
164-
if maxabsf < eps(zero(T))/eps(T) return LowRankFun([Fun(dx,[zero(T)])],[Fun(dx,[zero(T)])]),maxabsf end
165-
a=Fun(x->f(x,r),dx)
171+
if maxabsf < eps(zero(T))/eps(T)
172+
return LowRankFun([Fun(dx,[zero(T)])],[Fun(dx,[zero(T)])]), maxabsf
173+
end
174+
a=let r=r # avoid boxing r
175+
Fun(x->f(x,r),dx)
176+
end
166177

167178
# If necessary, we resize the grid to be at least as large as the
168179
# ncoefficients of the first row/column Fun and we recompute the values of X.
@@ -171,7 +182,9 @@ function CholeskyLowRankFun(f::Function,dx::Space;tolerance::Union{Symbol,Tuple{
171182
pts=points(dx,grid)
172183
X = zeros(T,grid)
173184
maxabsf,r=findcholeskyapproxmax!(f,X,pts,grid)
174-
a=Fun(x->f(x,r),dx)
185+
a=let r=r
186+
Fun(x->f(x,r),dx)
187+
end
175188
end
176189

177190
A,B=typeof(a)[],typeof(a)[]

0 commit comments

Comments
 (0)