Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix changebasis_I #323

Merged
merged 42 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4c31c75
copy _changebasis_R implementation to _changebasis_I
hyrodium Jun 12, 2023
0dd4979
update _changebasis_I implementation (wip)
hyrodium Jun 12, 2023
4358b5a
update _changebasis_I implementation (wip)
hyrodium Jun 12, 2023
2fe7c4f
update _changebasis_I implementation (wip)
hyrodium Jun 12, 2023
c915d66
update _changebasis_I implementation (wip)
hyrodium Jun 13, 2023
6c7f7c5
update _changebasis_I implementation (wip)
hyrodium Jun 13, 2023
aae6d04
remove flag
hyrodium Jun 13, 2023
695c45e
update type promotion in _changebasis_R
hyrodium Jun 13, 2023
24fd6f5
update _changebasis_I implementation (wip)
hyrodium Jun 14, 2023
252aebd
revert _changebasis_I to pass the current tests
hyrodium Sep 16, 2023
a8d6fed
add more comments on `_changebasis_R`
hyrodium Sep 16, 2023
93237f4
fix comments on `_changebasis_R`
hyrodium Sep 16, 2023
412886d
add more comments on `_changebasis_I_`
hyrodium Sep 16, 2023
9c4a954
minor fix in `_changebasis_I(P::UniformBSplineSpace{0}, P′::UniformBS…
hyrodium Sep 16, 2023
a43c039
add `_ΔAᵖ_R` function and refactor `_changebasis_R`
hyrodium Sep 16, 2023
ee7f6e1
fix typo in comments
hyrodium Sep 16, 2023
701c01d
refactor `_changebasis_R`
hyrodium Sep 16, 2023
e07fae2
refactor `_changebasis_I_`
hyrodium Sep 16, 2023
73470a6
refactor `_changebasis_I_`
hyrodium Sep 16, 2023
1d54d26
refactor `_changebasis_I_`
hyrodium Sep 16, 2023
d81744d
update TODO comments in `_changebasis_I_`
hyrodium Sep 16, 2023
ced051e
refactor `_changebasis_R`
hyrodium Sep 16, 2023
9f45f77
update TODO comments in `_changebasis_I_`
hyrodium Sep 16, 2023
54c8b02
minor refactoring
hyrodium Sep 16, 2023
54f694c
rename `_changebasis_I_*` function
hyrodium Sep 16, 2023
e559ac3
update `_changebasis_I`
hyrodium Sep 16, 2023
545c039
update `_changebasis_I`
hyrodium Sep 16, 2023
9c0a76a
update `_changebasis_I`
hyrodium Sep 16, 2023
dc9e489
update `_changebasis_I`
hyrodium Sep 16, 2023
e235c5e
update `_changebasis_I` namings
hyrodium Sep 17, 2023
1d3cd2c
add `bsplinebasis₋₀I`
hyrodium Sep 17, 2023
64a9d44
update `_changebasis_I` with `bsplinebasis₋₀I`
hyrodium Sep 17, 2023
18f00a4
update `_changebasis_I`
hyrodium Sep 17, 2023
c0c890a
update `_ΔAᵖ_*`
hyrodium Sep 17, 2023
a4ce016
add `_find_j_begin_end_R`
hyrodium Sep 17, 2023
3546313
add `_find_j_begin_end_I`
hyrodium Sep 17, 2023
02c9a22
update tests for new `changebasis_I`
hyrodium Sep 17, 2023
9005960
update `_find_j_begin_end_R`
hyrodium Sep 17, 2023
a32ce52
update `_find_j_begin_end_R`
hyrodium Sep 17, 2023
8942ec4
update `_find_j_begin_end_R`
hyrodium Sep 17, 2023
9ac819e
update comments
hyrodium Sep 17, 2023
652a2e7
update with TODO comments
hyrodium Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/_BSplineBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,65 @@ julia> bsplinebasis.(P,1:5,(1:6)')
)
end

@doc raw"""
``i``-th B-spline basis function.
Modified version (2).
```math
\begin{aligned}
{B}_{(i,p,k)}(t)
&=
\frac{t-k_{i}}{k_{i+p}-k_{i}}{B}_{(i,p-1,k)}(t)
+\frac{k_{i+p+1}-t}{k_{i+p+1}-k_{i+1}}{B}_{(i+1,p-1,k)}(t) \\
{B}_{(i,0,k)}(t)
&=
\begin{cases}
&1\quad (k_{i} \le t<k_{i+1})\\
&1\quad (k_{i} < t = k_{i+1}=k_{l})\\
&0\quad (\text{otherwise})
\end{cases}
\end{aligned}
```

# Examples
```jldoctest
julia> P = BSplineSpace{0}(KnotVector(1:6))
BSplineSpace{0, Int64, KnotVector{Int64}}(KnotVector([1, 2, 3, 4, 5, 6]))

julia> bsplinebasis₋₀I.(P,1:5,(1:6)')
5×6 Matrix{Float64}:
1.0 1.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 0.0 0.0 0.0
0.0 0.0 0.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 1.0 0.0
0.0 0.0 0.0 0.0 0.0 1.0
```
"""
@generated function bsplinebasis₋₀I(P::BSplineSpace{p,T}, i::Integer, t::S) where {p, T, S<:Real}
U = StaticArrays.arithmetic_closure(promote_type(T,S))
ks = [Symbol(:k,i) for i in 1:p+2]
Ks = [Symbol(:K,i) for i in 1:p+1]
Bs = [Symbol(:B,i) for i in 1:p+1]
k_l = Expr(:tuple, ks...)
k_r = Expr(:tuple, :(v[i]), (:(v[i+$j]) for j in 1:p+1)...)
K_l(n) = Expr(:tuple, Ks[1:n]...)
B_l(n) = Expr(:tuple, Bs[1:n]...)
A_r(n) = Expr(:tuple, [:($U(($(ks[i])<t≤$(ks[i+1])) || (v[1]==$(ks[i])==t<$(ks[i+1])))) for i in 1:n]...)
K_r(m,n) = Expr(:tuple, [:(_d(t-$(ks[i]),$(ks[i+m])-$(ks[i]))) for i in 1:n]...)
B_r(n) = Expr(:tuple, [:($(Ks[i])*$(Bs[i])+(1-$(Ks[i+1]))*$(Bs[i+1])) for i in 1:n]...)
exs = Expr[]
for i in 1:p
push!(exs, :($(K_l(p+2-i)) = $(K_r(i,p+2-i))))
push!(exs, :($(B_l(p+1-i)) = $(B_r(p+1-i))))
end
Expr(:block,
:(v = knotvector(P).vector),
:($k_l = $k_r),
:($(B_l(p+1)) = $(A_r(p+1))),
exs...,
:(return B1)
)
end

# bsplinebasis with UniformKnotVector
@inline function bsplinebasis(P::UniformBSplineSpace{p,T,R},i::Integer,t::S) where {p, T, R<:AbstractUnitRange, S<:Real}
U = StaticArrays.arithmetic_closure(promote_type(T,S))
Expand All @@ -194,6 +253,7 @@ end
end
@inline bsplinebasis₋₀(P::UniformBSplineSpace,i::Integer,t::Real) = bsplinebasis(P,i,t)
@inline bsplinebasis₊₀(P::UniformBSplineSpace,i::Integer,t::Real) = bsplinebasis(P,i,t)
@inline bsplinebasis₋₀I(P::UniformBSplineSpace,i::Integer,t::Real) = bsplinebasis(P,i,t)

################################################
#= B-Spline Basis Functions at specific point =#
Expand Down
1 change: 1 addition & 0 deletions src/_BSplineSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Check inclusive relationship between B-spline spaces.
```
"""
function issqsubset(P::BSplineSpace{p}, P′::BSplineSpace{p′}) where {p, p′}
# TODO: fix https://github.com/hyrodium/BasicBSpline.jl/issues/329
k = knotvector(P)
k′ = knotvector(P′)
l = length(k)
Expand Down
Loading