Commit 294b3be6 authored by Juan Ignacio Polanco's avatar Juan Ignacio Polanco

Define BSpline type (similar to Spline)

parent d1fe6ded
......@@ -15,7 +15,7 @@ module BasisSplines
export Collocation
export BSplineBasis, Spline
export BSplineBasis, Spline, BSpline
export knots, order, coefficients
export augment_knots
export evaluate_bspline, evaluate_bspline!
......
......@@ -60,6 +60,45 @@ Returns order of B-splines.
order(::Type{<:BSplineBasis{k}}) where {k} = k
order(b::BSplineBasis) = order(typeof(b))
"""
BSpline{B <: BSplineBasis}
Describes a single B-spline in the given basis.
---
BSpline(basis::BSplineBasis, i::Int, [T = Float64])
Construct i-th B-spline in the given basis.
The constructed BSpline can be evaluated as `b(x)`, returning a value of type
`T`.
"""
struct BSpline{Basis <: BSplineBasis, T}
basis :: Basis
i :: Int
function BSpline(b::BSplineBasis, i, ::Type{T} = Float64) where {T}
Basis = typeof(b)
new{Basis, T}(b, i)
end
end
basis(b::BSpline) = b.basis
knots(b::BSpline) = knots(basis(b))
order(b::BSpline) = order(basis(b))
Base.eltype(::Type{BSpline{B,T}}) where {B,T} = T
"""
(b::BSpline)(x, [Ndiff = Val(0)])
Evaluate B-spline at coordinate `x`.
To evaluate a derivative, pass the `Ndiff` parameter with the wanted
differentiation order.
"""
(b::BSpline)(x, Ndiff=Val(0)) =
evaluate_bspline(basis(b), b.i, x, eltype(b), Ndiff=Ndiff)
"""
evaluate_bspline(
B::BSplineBasis, i::Integer, x, [T=Float64];
......
......@@ -11,7 +11,7 @@ Construct a spline from a B-spline basis and a vector of B-spline coefficients.
"""
struct Spline{k, # B-spline order
Basis <: BSplineBasis,
T <: AbstractFloat,
T, # type of coefficient (e.g. Float64, ComplexF64)
CoefVector <: AbstractVector{T}}
basis :: Basis
coefs :: CoefVector
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment