Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 10, 2024
1 parent 442cba8 commit 2016b3f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/MultivariateBases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ include("hermite.jl")
include("laguerre.jl")
include("legendre.jl")
include("chebyshev.jl")
include("lagrange.jl")
include("quotient.jl")

function algebra(
Expand Down
21 changes: 14 additions & 7 deletions src/chebyshev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ function SA.coeffs!(
return res
end

function transformation_to(
source::SubBasis{Chebyshev},
target::SubBasis{Monomial},
)
A = zeros(Float64, length(target), length(source))
for (i, cheby) in enumerate(source)
A[:, i] = SA.coeffs(algebra_element(cheby), target)
end
return A
end

function SA.coeffs(
cfs,
source::SubBasis{Monomial},
Expand All @@ -97,17 +108,13 @@ function SA.coeffs(
sub = explicit_basis_covering(target, source)
# Need to make A square so that it's UpperTriangular
extended = SubBasis{Monomial}(sub.monomials)
A = zeros(Float64, length(extended), length(sub))
for (i, cheby) in enumerate(sub)
A[:, i] = SA.coeffs(algebra_element(cheby), extended)
end
ext = SA.coeffs(algebra_element(cfs, source), extended)
return SA.SparseCoefficients(
sub.monomials,
#LinearAlgebra.UpperTriangular(A) \ ext, # Julia v1.6 converts `A` to the eltype of the `result` which is bad for JuMP
#transformation_to(sub, extended) \ ext, # Julia v1.6 converts the matrix to the eltype of the `result` which is bad for JuMP
LinearAlgebra.ldiv!(
zeros(_promote_coef(eltype(ext), Chebyshev), size(A, 2)),
LinearAlgebra.UpperTriangular(A),
zeros(_promote_coef(eltype(ext), Chebyshev), length(sub)),
transformation_to(sub, extended),
ext,
),
)
Expand Down
61 changes: 58 additions & 3 deletions src/lagrange.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,65 @@
struct ImplicitLagrangeBasis
# Inspired by `Hypatia.jl/src/PolyUtils/realinterp.jl`

export BoxSampling

abstract type AbstractNodes{T,V} end

mutable struct BoxSampling{T,V} <: AbstractNodes{T,V}
lower::V
upper::V
sample_factor::Int
orthogonalize::Bool
function BoxSampling(lower, upper; sample_factor = 0, orthogonalize = false)
@assert length(lower) == length(upper)
l = float.(lower)
u = float.(upper)
V = promote_type(typeof(l), typeof(u))
return new{eltype(V),V}(l, u, sample_factor, orthogonalize)
end
end

struct LagrangePolynomial{T,V<:AbstractVector{T}}
function sample(s::BoxSampling, n::Integer) where {T}
samples = rand(T, length(s.lower), n) .- inv(T(2))
shift = (dom.u .+ dom.l) .* inv(T(2))
for i in 1:n
for j in eachindex(s.lower)
samples[j, i] = samples[j, i] * (dom.u[j] - dom.l[j]) + shift[j]
end
end
return samples
end

struct LagrangePolynomial{T,V}
point::V
end

struct LagrangeBasis{T,P<:AbstractVector{T},V<:AbstractVector{P}}
struct ImplicitLagrangeBasis{T,V,N<:AbstractNodes{T,V}} <:
SA.ImplicitBasis{LagrangePolynomial{T,V},V}
sampling::AbstractNodes{T,V}
function ImplicitLagrangeBasis(nodes::AbstractNodes{T,V}) where {T,V}
return new{T,V,typeof(nodes)}(nodes)
end
end
struct LagrangeBasis{T,P,V<:AbstractVector{P}} <:
SA.ExplicitBasis{LagrangePolynomial{T,V},Int}
points::V
end

Base.length(basis::LagrangeBasis) = length(basis.points)

function transformation_to(basis::SubBasis, lag::LagrangeBasis{T}) where {T}
V = Matrix{T}(undef, length(lag), length(basis))
for
end

function sample(s::AbstractNodes, basis::SubBasis)
samples = sample(s, length(basis) * s.sample_factor)
return eachcol(samples)
end

function explicit_basis_covering(
implicit::ImplicitLagrangeBasis,
basis::SubBasis,
)
return LagrangeBasis(sample(implicit.sampling, length(basis)))
end
15 changes: 15 additions & 0 deletions src/orthogonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ d_k p_k(x_i) = (a_k x_i + b_k) p_{k-1}(x_i) + c_k p_{k-2}(x_i)
"""
function reccurence_deno_coef end

function univariate_eval!(
values::Vector,
value,
::Type{B},
) where {B}
if 1 in eachindex(values)
values[1] = one(value)
end
if 2 in eachindex(values)
values[1] = one(value)
end
for d in 2:(length(values) - 1)
end
end

"""
univariate_orthogonal_basis(
B::Type{<:AbstractMultipleOrthogonal},
Expand Down

0 comments on commit 2016b3f

Please sign in to comment.