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

Reduce type flexibility in BsplineManifold #355

Merged
merged 14 commits into from
Dec 16, 2023

Conversation

hyrodium
Copy link
Owner

This PR fixes #353.

@hyrodium hyrodium force-pushed the feature/reduce_type_flexibility_in_BSplineManifold branch from ba7d7e3 to 6677acc Compare December 16, 2023 06:34
Copy link

codecov bot commented Dec 16, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (ae5ba38) 93.84% compared to head (d9b7342) 93.79%.

Files Patch % Lines
src/_Refinement.jl 72.22% 5 Missing ⚠️
src/_RationalBSplineManifold.jl 71.42% 4 Missing ⚠️
src/_BSplineManifold.jl 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #355      +/-   ##
==========================================
- Coverage   93.84%   93.79%   -0.06%     
==========================================
  Files          14       14              
  Lines        1642     1660      +18     
==========================================
+ Hits         1541     1557      +16     
- Misses        101      103       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hyrodium
Copy link
Owner Author

Before this PR

julia> using BasicBSpline

julia> P1 = BSplineSpace{2, Int}(knotvector"3 113")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 1, 1, 3, 4, 5, 5, 5]))

julia> P2 = BSplineSpace{2, Rational{Int}}(knotvector"3 113")
BSplineSpace{2, Rational{Int64}, KnotVector{Rational{Int64}}}(KnotVector(Rational{Int64}[1//1, 1//1, 1//1, 3//1, 4//1, 5//1, 5//1, 5//1]))

julia> a = rand(dim(P1), dim(P2))
5×5 Matrix{Float64}:
 0.741979   0.263108  0.316128   0.372952  0.421981
 0.486815   0.67646   0.328703   0.451822  0.340635
 0.0072873  0.962419  0.128144   0.163797  0.621682
 0.605695   0.600226  0.0666295  0.745873  0.0474121
 0.546628   0.018101  0.305919   0.290262  0.884664

julia> bsplinespaces(BSplineManifold(a, P1, P2))[1]
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 1, 1, 3, 4, 5, 5, 5]))

julia> bsplinespaces(BSplineManifold(a, P1, P2))[2]
BSplineSpace{2, Rational{Int64}, KnotVector{Rational{Int64}}}(KnotVector(Rational{Int64}[1//1, 1//1, 1//1, 3//1, 4//1, 5//1, 5//1, 5//1]))

After this PR

julia> using BasicBSpline

julia> P1 = BSplineSpace{2, Int}(knotvector"3 113")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 1, 1, 3, 4, 5, 5, 5]))

julia> P2 = BSplineSpace{2, Rational{Int}}(knotvector"3 113")
BSplineSpace{2, Rational{Int64}, KnotVector{Rational{Int64}}}(KnotVector(Rational{Int64}[1//1, 1//1, 1//1, 3//1, 4//1, 5//1, 5//1, 5//1]))

julia> a = rand(dim(P1), dim(P2))
5×5 Matrix{Float64}:
 0.933547    0.324843  0.977758   0.182171  0.55386
 0.404299    0.911178  0.0584839  0.615514  0.264623
 0.00691595  0.896858  0.102844   0.553428  0.226851
 0.846493    0.987066  0.476708   0.99308   0.129281
 0.301458    0.242925  0.420328   0.224337  0.957864

julia> bsplinespaces(BSplineManifold(a, P1, P2))[1]
BSplineSpace{2, Rational{Int64}, KnotVector{Rational{Int64}}}(KnotVector(Rational{Int64}[1//1, 1//1, 1//1, 3//1, 4//1, 5//1, 5//1, 5//1]))

julia> bsplinespaces(BSplineManifold(a, P1, P2))[2]
BSplineSpace{2, Rational{Int64}, KnotVector{Rational{Int64}}}(KnotVector(Rational{Int64}[1//1, 1//1, 1//1, 3//1, 4//1, 5//1, 5//1, 5//1]))

@hyrodium
Copy link
Owner Author

Sometimes type promotions may fail because

julia> AbstractKnotVector{Int}(UniformKnotVector(1:5))
ERROR: MethodError: no method matching AbstractKnotVector{Int64}(::UniformKnotVector{Int64, UnitRange{Int64}})

Closest candidates are:
  AbstractKnotVector{S}(::KnotVector{T}) where {S, T}
   @ BasicBSpline ~/.julia/dev/BasicBSpline/src/_KnotVector.jl:93

Stacktrace:
 [1] top-level scope
   @ REPL[9]:1

One can just modify the arguments manually not to require type promotions (_promote_knottype).

@hyrodium
Copy link
Owner Author

RationalBSplineManifold was also updated.

@hyrodium hyrodium merged commit 3899682 into main Dec 16, 2023
11 of 13 checks passed
@hyrodium hyrodium deleted the feature/reduce_type_flexibility_in_BSplineManifold branch December 17, 2023 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove flexibility of BSplineManifold
1 participant