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

Add SubKnotVector #320

Merged
merged 10 commits into from
Jun 10, 2023
Merged

Add SubKnotVector #320

merged 10 commits into from
Jun 10, 2023

Conversation

hyrodium
Copy link
Owner

This PR adds SubKnotVector and methods of Base.view for performance.

@codecov
Copy link

codecov bot commented Jun 10, 2023

Codecov Report

Merging #320 (5c1ef01) into main (b472612) will increase coverage by 2.15%.
The diff coverage is 97.56%.

@@            Coverage Diff             @@
##             main     #320      +/-   ##
==========================================
+ Coverage   96.00%   98.15%   +2.15%     
==========================================
  Files          13       13              
  Lines        1300     1300              
==========================================
+ Hits         1248     1276      +28     
+ Misses         52       24      -28     
Impacted Files Coverage Δ
src/BasicBSpline.jl 100.00% <ø> (ø)
src/_KnotVector.jl 95.33% <93.75%> (-0.42%) ⬇️
src/_BSplineSpace.jl 97.84% <100.00%> (+0.36%) ⬆️
src/_ChangeBasis.jl 97.30% <100.00%> (+11.19%) ⬆️

@hyrodium
Copy link
Owner Author

The performance regression (#317) problem is partially resolved but is still insufficient.

julia> using BasicBSpline, BenchmarkTools

julia> P1 = BSplineSpace{2}(KnotVector(0:8));

julia> P2 = BSplineSpace{2}(KnotVector(0:0.5:8));

julia> changebasis(P1, P2)
6×14 SparseArrays.SparseMatrixCSC{Float64, Int64} with 24 stored entries:
 0.25  0.75  0.75  0.25                                                 
           0.25  0.75  0.75  0.25                                       
                     0.25  0.75  0.75  0.25                             
                               0.25  0.75  0.75  0.25                   
                                         0.25  0.75  0.75  0.25         
                                                   0.25  0.75  0.75  0.25

julia> @benchmark changebasis(P1, P2)
BenchmarkTools.Trial: 10000 samples with 4 evaluations.
 Range (min  max):  7.580 μs  761.908 μs  ┊ GC (min  max): 0.00%  96.26%
 Time  (median):     7.925 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   9.771 μs ±  12.493 μs  ┊ GC (mean ± σ):  2.40% ±  1.92%

  ██▄    ▂▅▃▁▁▂▃▃▃▂▂▂▁▁▁▂▂▂▂▂▂▂▁▁▁▁                           ▂
  ███▇▆█▇███████████████████████████▇█▇▇▇▇▆▆▅▆▄▅▅▅▆▅▃▄▅▆▄▅▅▄▅ █
  7.58 μs      Histogram: log(frequency) by time      20.8 μs <

 Memory estimate: 4.86 KiB, allocs estimate: 34.

julia> P1 = BSplineSpace{2}(KnotVector(0:80));

julia> P2 = BSplineSpace{2}(KnotVector(0:0.5:80));

julia> changebasis(P1, P2)
78×158 SparseArrays.SparseMatrixCSC{Float64, Int64} with 312 stored entries:
⎡⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠶⣤⣀⠀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠒⎦

julia> @benchmark changebasis(P1, P2)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  219.837 μs   1.466 ms  ┊ GC (min  max): 0.00%  81.20%
 Time  (median):     225.216 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   227.603 μs ± 37.103 μs  ┊ GC (mean ± σ):  0.48% ±  2.55%

           ▂█▂                                                  
  ▁▃▅▅▄▃▃▃▅███▅▃▃▃▃▃▃▃▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  220 μs          Histogram: frequency by time          250 μs <

 Memory estimate: 49.92 KiB, allocs estimate: 42.

@hyrodium
Copy link
Owner Author

The performance on issubset is much imprroved.

Before this PR

julia> using BasicBSpline, BenchmarkTools

julia> P = BSplineSpace{0}(knotvector"  1 2 1 1")
BSplineSpace{0, Int64, KnotVector{Int64}}(KnotVector([3, 5, 5, 7, 9]))

julia> P′= BSplineSpace{2}(knotvector"1 3 4 3 3 1")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 9, 9, 9, 11]))

julia> P  P′
true

julia> @benchmark P  P′
BenchmarkTools.Trial: 10000 samples with 201 evaluations.
 Range (min  max):  384.657 ns   14.072 μs  ┊ GC (min  max): 0.00%  93.94%
 Time  (median):     420.149 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   481.209 ns ± 732.955 ns  ┊ GC (mean ± σ):  8.62% ±  5.50%

     ▂▄▆▇██▇▆▅▄▃▂▂▁▁▁ ▂▃▄▅▅▅▄▃▂▁                                ▃
  ▂▅▇█████████████████████████████▇▇▇▇▇██████▇▇▇▆▅▇▆▆▆▆▇▆▅▄▅▆▄▅ █
  385 ns        Histogram: log(frequency) by time        625 ns <

 Memory estimate: 832 bytes, allocs estimate: 8.

After this PR

julia> using BasicBSpline, BenchmarkTools

julia> P = BSplineSpace{0}(knotvector"  1 2 1 1")
BSplineSpace{0, Int64, KnotVector{Int64}}(KnotVector([3, 5, 5, 7, 9]))

julia> P′= BSplineSpace{2}(knotvector"1 3 4 3 3 1")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 9, 9, 9, 11]))

julia> P  P′
true

julia> @benchmark P  P′
BenchmarkTools.Trial: 10000 samples with 994 evaluations.
 Range (min  max):  31.729 ns  175.514 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     33.020 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   36.166 ns ±   7.525 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▂█▇▁ ▄▇ ▁▂▂▄▁                  ▁▂▁                           ▂
  ████▄██▆█████▇▆▇▆▅▆▆▅▅▃▄▄▄▄▅▅▅▆████▆▆▇▇▇▇▇▇▇▇▇▇█▇▅▇▇▇▆▅▆▆▅▆▅ █
  31.7 ns       Histogram: log(frequency) by time      63.8 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

@hyrodium hyrodium merged commit f4d53c9 into main Jun 10, 2023
10 of 13 checks passed
@hyrodium hyrodium mentioned this pull request Jun 10, 2023
@hyrodium hyrodium deleted the feature/SubKnotVector branch June 22, 2023 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant