Skip to content

Commit

Permalink
Fix \ for LanczosPolynomials with empty caches (#198)
Browse files Browse the repository at this point in the history
* Use emptymaximum

* General indices

* Syntax
  • Loading branch information
DanielVandH authored Jul 20, 2024
1 parent 53244ac commit cc668ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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 <solver@mac.com>"]
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

2 comments on commit cc668ce

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/111418

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.4 -m "<description of version>" cc668ce8e617ba72f29b04bd2e64ef40418924ac
git push origin v0.13.4

Please sign in to comment.