Skip to content

Commit

Permalink
Fixe constant for ConvertedOrthogonalPolynomial (#226)
Browse files Browse the repository at this point in the history
* Introduce GramMatrixPolynomial

* Fixes to ConvertedOP

* Update choleskyQR.jl

* make ConvertedOP normalized again

* Update Project.toml

* Update choleskyQR.jl

* Update test_choleskyQR.jl
  • Loading branch information
dlfivefifty authored Jan 26, 2025
1 parent 8be0b52 commit 83dac49
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 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 <[email protected]>"]
version = "0.14.2"
version = "0.14.3"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
13 changes: 10 additions & 3 deletions src/choleskyQR.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Represent an Orthogonal polynomial which has a conversion operator from P, that is, Q = P * inv(U).
Represents orthonormal polynomials defined via a conversion operator from P, that is, Q = P * inv(U).
"""
struct ConvertedOrthogonalPolynomial{T, WW<:AbstractQuasiVector{T}, XX, UU, PP} <: OrthonormalPolynomial{T}
weight::WW
Expand All @@ -8,15 +8,22 @@ struct ConvertedOrthogonalPolynomial{T, WW<:AbstractQuasiVector{T}, XX, UU, PP}
P::PP
end

_p0(Q::ConvertedOrthogonalPolynomial) = _p0(Q.P)
_p0(Q::ConvertedOrthogonalPolynomial) = _p0(Q.P)/Q.U[1,1]

axes(Q::ConvertedOrthogonalPolynomial) = axes(Q.P)


struct ConvertedOPLayout <: AbstractNormalizedOPLayout end
MemoryLayout(::Type{<:ConvertedOrthogonalPolynomial}) = ConvertedOPLayout()




jacobimatrix(Q::ConvertedOrthogonalPolynomial) = Q.X
orthogonalityweight(Q::ConvertedOrthogonalPolynomial) = Q.weight


# transform to P * U if needed for differentiation, etc.
# transform to P * inv(U) if needed for differentiation, etc.
arguments(::ApplyLayout{typeof(*)}, Q::ConvertedOrthogonalPolynomial) = Q.P, ApplyArray(inv, Q.U)

OrthogonalPolynomial(w::AbstractQuasiVector) = OrthogonalPolynomial(w, orthogonalpolynomial(singularities(w)))
Expand Down
1 change: 0 additions & 1 deletion src/normalized.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ isnormalized(_) = false
represents OPs that are of the form P * R where P is another family of OPs and R is upper-triangular.
"""
abstract type AbstractNormalizedOPLayout <: AbstractOPLayout end
struct ConvertedOPLayout <: AbstractNormalizedOPLayout end
struct NormalizedOPLayout{LAY<:AbstractBasisLayout} <: AbstractNormalizedOPLayout end

MemoryLayout(::Type{<:Normalized{<:Any, OPs}}) where OPs = NormalizedOPLayout{typeof(MemoryLayout(OPs))}()
Expand Down
8 changes: 5 additions & 3 deletions test/test_choleskyQR.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Test, ClassicalOrthogonalPolynomials, BandedMatrices, LinearAlgebra, LazyArrays, ContinuumArrays, LazyBandedMatrices, InfiniteLinearAlgebra
import ClassicalOrthogonalPolynomials: cholesky_jacobimatrix, qr_jacobimatrix, orthogonalpolynomial
import ClassicalOrthogonalPolynomials: cholesky_jacobimatrix, qr_jacobimatrix, orthogonalpolynomial, _p0
import LazyArrays: AbstractCachedMatrix, resizedata!

@testset "CholeskyQR" begin
Expand Down Expand Up @@ -228,9 +228,8 @@ import LazyArrays: AbstractCachedMatrix, resizedata!
@test Q ==
@test== Q

@test Q[0.1,1] 1/sqrt(2)
@test Q[0.1,1] _p0(Q) 1/sqrt(2)
@test Q[0.1,1:10] Q̃[0.1,1:10]
# AWESOME, thanks TSGUT!!
@test Q[0.1,10_000] Q̃[0.1,10_000]

R = P \ Q
Expand All @@ -247,6 +246,9 @@ import LazyArrays: AbstractCachedMatrix, resizedata!
@testset "Chebyshev" begin
U = ChebyshevU()
Q = orthogonalpolynomial(x -> (1+x^2)*sqrt(1-x^2), U)
x = axes(U,1)

@test Q[0.1,1] _p0(Q) 1/sqrt(sum(expand(Weighted(U),x -> (1+x^2)*sqrt(1-x^2))))
@test bandwidths(Q\U) == (0,2)

= OrthogonalPolynomial(x -> (1+x^2)*sqrt(1-x^2), U)
Expand Down
10 changes: 10 additions & 0 deletions test/test_gram.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using ClassicalOrthogonalPolynomials, FastTransforms

P = Legendre()
x = axes(P,1)
w = @.(1-x^2)

μ = P'w
X = jacobimatrix(P)
n = 20
@test GramMatrix(μ[1:2n], X[1:2n,1:2n]) (P' * (w .* P))[1:n,1:n]

2 comments on commit 83dac49

@dlfivefifty
Copy link
Member Author

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/123752

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.14.3 -m "<description of version>" 83dac497061d69cd09d87bbbe8722ca1e0df0e65
git push origin v0.14.3

Please sign in to comment.