Skip to content

Commit 3351bfc

Browse files
jishnubclaude
andauthored
Fix a second round of unreachable methods (#696)
A JET pass over the merged master turned up more methods that could not run: a garbled expression in the product of two LowRankOperators, a field access on the wrong object in BandedMatrix(::SubOperator), and an exception type that was moved out of Base. The LowRankFun constructors now report unsupported arguments instead of failing with an UndefVarError. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 541dfcf commit 3351bfc

5 files changed

Lines changed: 47 additions & 14 deletions

File tree

src/Multivariate/LowRankFun.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ function LowRankFun(f::Function, dx::Space, dy::Space;
104104
else
105105
F = LowRankFun(copy(G.A), map(b->Fun(b,dy),G.B))
106106
end
107+
else
108+
throw(ArgumentError("unsupported method \$method, expected :standard or :Cholesky"))
107109
end
108110
retmax ? (F,maxabsf) : F
109111
end
@@ -145,10 +147,12 @@ function standardLowRankFun(f::Function, dx::Space, dy::Space;
145147
end
146148

147149
A,B=typeof(a)[],typeof(b)[]
148-
if tolerance == :relative
149-
tol = 100maxabsf*eps(T)
150-
elseif tolerance[1] == :absolute
151-
tol = 100*tolerance[2]*eps(T)
150+
tol = if tolerance == :relative
151+
100maxabsf*eps(T)
152+
elseif tolerance isa Tuple && tolerance[1] == :absolute
153+
100*tolerance[2]*eps(T)
154+
else
155+
throw(ArgumentError("unsupported tolerance \$tolerance, expected :relative or (:absolute, tol)"))
152156
end
153157
tol10 = tol/10
154158
Avals,Bvals = zeros(T,gridx),zeros(T,gridy)
@@ -209,10 +213,12 @@ function CholeskyLowRankFun(f::Function,dx::Space;
209213
end
210214

211215
A,B=typeof(a)[],typeof(a)[]
212-
if tolerance == :relative
213-
tol = 100maxabsf*eps(T)
214-
elseif tolerance[1] == :absolute
215-
tol = 100*tolerance[2]*eps(T)
216+
tol = if tolerance == :relative
217+
100maxabsf*eps(T)
218+
elseif tolerance isa Tuple && tolerance[1] == :absolute
219+
100*tolerance[2]*eps(T)
220+
else
221+
throw(ArgumentError("unsupported tolerance \$tolerance, expected :relative or (:absolute, tol)"))
216222
end
217223
tol10 = tol/10
218224
Avals = zeros(T,grid)

src/Operators/almostbanded/LowRankOperator.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ rank(L::LowRankOperator) = length(L.U)
7171
*(L::LowRankOperator,f::Fun) = sum(map((u,v)->u*(v*f),L.U,L.V))
7272

7373

74-
*(A::LowRankOperator,B::LowRankOperator) = LowRankOperator(transpose(A.V*B.transpose(U))*A.U,B.V)
74+
# (A*B)*f == A*(B*f) == sum(A*B.U[k] * (B.V[k]*f) for k in eachindex(B.U)),
75+
# as B.V[k]*f is a constant
76+
*(A::LowRankOperator,B::LowRankOperator) = LowRankOperator(map(u->A*u, B.U), B.V)
7577
# avoid ambiguity
7678
for TYP in (:TimesOperator,:PlusOperator,:Conversion,:Operator)
7779
@eval *(L::LowRankOperator,B::$TYP) = LowRankOperator(L.U,map(v->v*B,L.V))

src/Operators/general/FiniteOperator.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ function getindex(F::FiniteOperator,k::Integer)
5050
end
5151

5252
function BandedMatrix(S::SubOperator{T,FiniteOperator{AT,T}}) where {AT<:BandedMatrix,T}
53-
kr,jr=parentindices(S)
54-
if last(kr[1]) size(S.matrix,1) &&
55-
last(jr[2]) size(S.matrix,2)
56-
matrix[kr,jr]
53+
kr,jr = parentindices(S)
54+
M = parent(S).matrix
55+
if last(kr) size(M,1) && last(jr) size(M,2)
56+
M[kr,jr]
5757
else
5858
default_copy(S)
5959
end

src/specialfunctions.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ function airy(k::Number,f::Fun)
291291
end
292292
end
293293

294-
besselh(ν,k::Integer,f::Fun) = k == 1 ? hankelh1(ν,f) : k == 2 ? hankelh2(ν,f) : throw(Base.Math.AmosException(1))
294+
besselh(ν,k::Integer,f::Fun) = k == 1 ? hankelh1(ν,f) : k == 2 ? hankelh2(ν,f) :
295+
throw(ArgumentError("k must be 1 or 2, received \$k"))
295296

296297
for jy in (:j, :y)
297298
bjy = Symbol(:bessel, jy)

test/runtests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,4 +867,28 @@ end
867867
f = Fun(ApproxFunBase.SequenceSpace(), [3.0, 4.0])
868868
@test f[CartesianIndex()] == f[1] == 3.0
869869
end
870+
871+
@testset "product of LowRankOperators" begin
872+
H = ApproxFunBase.HeavisideSpace([-1.0, 0.0, 1.0])
873+
A = ApproxFunBase.LowRankOperator(Fun(H, [1.0, 2.0]), Evaluation(H, -0.5))
874+
B = ApproxFunBase.LowRankOperator(Fun(H, [3.0, -1.0]), Evaluation(H, 0.5))
875+
AB = A*B
876+
@test AB isa ApproxFunBase.LowRankOperator
877+
@test rank(AB) == rank(B)
878+
f = Fun(H, [2.0, 5.0])
879+
@test coefficients(AB*f) coefficients(A*(B*f))
880+
end
881+
882+
@testset "BandedMatrix of a FiniteOperator view" begin
883+
M = BandedMatrix(0 => Float64[1, 2, 3], 1 => Float64[4, 5])
884+
F = ApproxFunBase.FiniteOperator(M)
885+
@test BandedMatrix(view(F, 1:2, 1:2)) == M[1:2, 1:2]
886+
@test BandedMatrix(view(F, 2:3, 2:3)) == M[2:3, 2:3]
887+
end
888+
889+
@testset "argument errors" begin
890+
@test_throws ArgumentError besselh(0, 3, Fun(1.0))
891+
@test_throws ArgumentError LowRankFun((x,y) -> x*y, PointSpace(1:3), PointSpace(1:3),
892+
method = :neither)
893+
end
870894
end

0 commit comments

Comments
 (0)