Skip to content

Fix \ for LanczosPolynomials with empty caches #198

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 3 commits into from
Jul 20, 2024
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,7 +1,7 @@
name = "ClassicalOrthogonalPolynomials"
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
authors = ["Sheehan Olver <[email protected]>"]
version = "0.13.3"
version = "0.13.4"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
6 changes: 4 additions & 2 deletions src/lanczos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ Base.BroadcastStyle(::Type{<:LanczosConversion}) = LazyArrays.LazyArrayStyle{2}(

struct LanczosConversionLayout <: AbstractLazyLayout end

_emptymaximum(arr) = isempty(arr) ? convert(eltype(arr), firstindex(arr)-1) : maximum(arr)

LazyArrays.simplifiable(::Mul{LanczosConversionLayout,<:AbstractPaddedLayout}) = Val(true)
function copy(M::Mul{LanczosConversionLayout,<:AbstractPaddedLayout})
resizedata!(M.A.data, maximum(colsupport(M.B)))
resizedata!(M.A.data, _emptymaximum(colsupport(M.B)))
M.A.data.R * M.B
end

function copy(M::Ldiv{LanczosConversionLayout,<:AbstractPaddedLayout})
resizedata!(M.A.data, maximum(colsupport(M.B)))
resizedata!(M.A.data, _emptymaximum(colsupport(M.B)))
M.A.data.R \ M.B
end

Expand Down
14 changes: 13 additions & 1 deletion test/test_lanczos.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ClassicalOrthogonalPolynomials, BandedMatrices, ArrayLayouts, QuasiArrays, ContinuumArrays, InfiniteArrays, Test
import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedColumns, orthogonalityweight, golubwelsch, LanczosData
import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedColumns, orthogonalityweight, golubwelsch, LanczosData, _emptymaximum, LanczosConversion

@testset "Lanczos" begin
@testset "Legendre" begin
Expand Down Expand Up @@ -304,3 +304,15 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, PaddedColumns, or
@test Q[0.5,1:3] ≈ [1, 1.369306393762913, 0.6469364618834543]
end
end

@testset "#197" begin
@test _emptymaximum(1:5) == 5
@test _emptymaximum(1:0) == 0
x = Inclusion(ChebyshevInterval())
f = exp.(x)
QQ = LanczosPolynomial(f)
R = LanczosConversion(QQ.data)
v = cache(Zeros(∞))
@test (R \ v)[1:500] == zeros(500)
@test (R * v)[1:500] == zeros(500)
end
Loading