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 precision of changebasis #306

Merged
merged 3 commits into from
Mar 2, 2023
Merged

Fix precision of changebasis #306

merged 3 commits into from
Mar 2, 2023

Conversation

hyrodium
Copy link
Owner

@hyrodium hyrodium commented Mar 2, 2023

This PR fixes #177 (comment).

Before this PR

julia> using BasicBSpline

julia> p = 3
3

julia> P = BSplineSpace{p}(KnotVector([4,4,4,4,5,6,7,7,7,7]))
BSplineSpace{3, Int64, KnotVector{Int64}}(KnotVector([4, 4, 4, 4, 5, 6, 7, 7, 7, 7]))

julia> P′ = BSplineSpace{p}(KnotVector([4,4,4,4,4.5,5,6,7,7,7,7]))
BSplineSpace{3, Float64, KnotVector{Float64}}(KnotVector([4.0, 4.0, 4.0, 4.0, 4.5, 5.0, 6.0, 7.0, 7.0, 7.0, 7.0]))

julia> changebasis(P,P′)
6×7 Matrix{Float64}:
 1.0   0.5          0.0          0.0       0.0           0.0          0.0
 0.0   0.5          0.75         0.0       0.0           0.0          0.0
 0.0  -5.55112e-17  0.25         0.833333  5.55112e-17   5.55112e-17  0.0
 0.0   4.16334e-17  4.16334e-17  0.166667  1.0          -5.55112e-17  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           0.0          1.0

After this PR

julia> using BasicBSpline

julia> p = 3
3

julia> P = BSplineSpace{p}(KnotVector([4,4,4,4,5,6,7,7,7,7]))
BSplineSpace{3, Int64, KnotVector{Int64}}(KnotVector([4, 4, 4, 4, 5, 6, 7, 7, 7, 7]))

julia> P′ = BSplineSpace{p}(KnotVector([4,4,4,4,4.5,5,6,7,7,7,7]))
BSplineSpace{3, Float64, KnotVector{Float64}}(KnotVector([4.0, 4.0, 4.0, 4.0, 4.5, 5.0, 6.0, 7.0, 7.0, 7.0, 7.0]))

julia> changebasis(P,P′)
6×7 Matrix{Float64}:
 1.0   0.5  0.0   0.0       0.0   0.0  0.0
 0.0   0.5  0.75  0.0       0.0   0.0  0.0
 0.0  -0.0  0.25  0.833333  0.0   0.0  0.0
 0.0   0.0  0.0   0.166667  1.0  -0.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   0.0  1.0

@hyrodium
Copy link
Owner Author

hyrodium commented Mar 2, 2023

The performance is also getting better.
Before this PR

julia> @benchmark changebasis(P,P′)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  10.760 μs   2.393 ms  ┊ GC (min  max):  0.00%  98.54%
 Time  (median):     12.283 μs              ┊ GC (median):     0.00%
 Time  (mean ± σ):   15.404 μs ± 59.374 μs  ┊ GC (mean ± σ):  10.11% ±  2.61%

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

 Memory estimate: 32.36 KiB, allocs estimate: 188.

After this PR

julia> @benchmark changebasis(P,P′)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):   9.328 μs   2.434 ms  ┊ GC (min  max): 0.00%  98.59%
 Time  (median):     10.620 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   13.163 μs ± 52.199 μs  ┊ GC (mean ± σ):  9.60% ±  2.42%

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

 Memory estimate: 27.30 KiB, allocs estimate: 158.

@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

Merging #306 (fed5862) into main (e99cb47) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #306   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files          13       13           
  Lines        1241     1241           
=======================================
  Hits         1222     1222           
  Misses         19       19           
Impacted Files Coverage Δ
src/_ChangeBasis.jl 97.94% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@hyrodium hyrodium merged commit d1be0f0 into main Mar 2, 2023
@hyrodium hyrodium deleted the fix/changebasis_zero_2 branch March 2, 2023 14: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.

changebasis sometimes returns incorrect nonzero element
1 participant