Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 10, 2024
1 parent d5a88ee commit e605773
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
36 changes: 29 additions & 7 deletions src/lagrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ struct ImplicitLagrangeBasis{T,P,N<:AbstractNodes{T,P},V} <:
SA.ImplicitBasis{LagrangePolynomial{T,P,V},Pair{V,P}}
variables::V
nodes::AbstractNodes{T,P}
function ImplicitLagrangeBasis(variables, nodes::AbstractNodes{T,P}) where {T,P}
function ImplicitLagrangeBasis(
variables,
nodes::AbstractNodes{T,P},
) where {T,P}
return new{T,P,typeof(nodes),typeof(variables)}(variables, nodes)
end
end
Expand All @@ -48,7 +51,10 @@ struct LagrangeBasis{T,P,U<:AbstractVector{P},V} <:
points::U
function LagrangeBasis(variables, points::AbstractVector)
P = eltype(points)
return new{eltype(P),P,typeof(points),typeof(variables)}(variables, points)
return new{eltype(P),P,typeof(points),typeof(variables)}(
variables,
points,
)
end
end

Expand All @@ -59,16 +65,26 @@ function Base.getindex(basis::LagrangeBasis, I::AbstractVector{<:Integer})
return LagrangeBasis(basis.variables, basis.points[I])
end

function explicit_basis_type(::Type{<:ImplicitLagrangeBasis{T,_P,N,V}}) where {T,_P,N,V}
function explicit_basis_type(
::Type{<:ImplicitLagrangeBasis{T,_P,N,V}},
) where {T,_P,N,V}
points = eachcol(ones(T, 1, 1))
P = eltype(points)
return LagrangeBasis{eltype(P),P,typeof(points),V}
end

function eval_basis!(univariate_buffer, result, basis::SubBasis{B}, variables, values) where {B}
function eval_basis!(
univariate_buffer,
result,
basis::SubBasis{B},
variables,
values,
) where {B}
for v in MP.variables(basis)
if !(v in variables)
error("Cannot evaluate `$basis` as its variable `$v` is not part of the variables `$variables` of the `LagrangeBasis`")
error(
"Cannot evaluate `$basis` as its variable `$v` is not part of the variables `$variables` of the `LagrangeBasis`",
)
end
end
for i in eachindex(values)
Expand All @@ -79,7 +95,7 @@ function eval_basis!(univariate_buffer, result, basis::SubBasis{B}, variables, v
result[i] = one(eltype(result))
for j in eachindex(values)
d = MP.degree(basis.monomials[i], variables[j])
result[i] = MA.operate!!(*, result[i], univariate_buffer[d + 1, j])
result[i] = MA.operate!!(*, result[i], univariate_buffer[d+1, j])
end
end
return result
Expand All @@ -91,7 +107,13 @@ function transformation_to(basis::SubBasis, lag::LagrangeBasis{T}) where {T}
univariate_buffer = Matrix{T}(undef, length(basis), MP.nvariables(lag))
V = Matrix{T}(undef, length(lag), length(basis))
for i in eachindex(lag)
eval_basis!(univariate_buffer, view(V, i, :), basis, MP.variables(lag), lag.points[i])
eval_basis!(
univariate_buffer,
view(V, i, :),
basis,
MP.variables(lag),
lag.points[i],
)
end
return V
end
Expand Down
17 changes: 9 additions & 8 deletions src/orthogonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,15 @@ function recurrence_eval(
) / d
end

function univariate_eval!(
::Type{B},
values::AbstractVector,
value,
) where {B}
function univariate_eval!(::Type{B}, values::AbstractVector, value) where {B}
if 1 in eachindex(values)
values[1] = one(value)
end
if 2 in eachindex(values)
values[2] = degree_one_univariate_polynomial(B, value)
end
for d in 2:(length(values) - 1)
values[d + 1] = recurrence_eval(B, view(values, 1:d), value, d)
for d in 2:(length(values)-1)
values[d+1] = recurrence_eval(B, view(values, 1:d), value, d)
end
return values
end
Expand All @@ -111,7 +107,12 @@ function univariate_orthogonal_basis(
)
return univariate_eval!(
B,
Vector{MP.polynomial_type(Polynomial{B,MP.monomial_type(variable)}, Int)}(undef, degree + 1),
Vector{
MP.polynomial_type(Polynomial{B,MP.monomial_type(variable)}, Int),
}(
undef,
degree + 1,
),
variable,
)
end
Expand Down

0 comments on commit e605773

Please sign in to comment.