-
Notifications
You must be signed in to change notification settings - Fork 3
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
Faster _changebasis_sim
#242
Conversation
Getting faster with julia> using BasicBSpline
julia> using BenchmarkTools
julia> p = 3
3
julia> P1 = BSplineSpace{p}(KnotVector(1:8))
BSplineSpace{3, Int64}(KnotVector([1, 2, 3, 4, 5, 6, 7, 8]))
julia> P2 = BSplineSpace{p}(KnotVector(2,3,3,4,5,6,7,8))
BSplineSpace{3, Int64}(KnotVector([2, 3, 3, 4, 5, 6, 7, 8]))
julia> changebasis(P1,P2)
4×4 Matrix{Float64}:
0.666667 0.0 -4.93432e-17 0.0
0.333333 1.0 -2.22045e-16 -5.55112e-17
3.70074e-17 0.0 1.0 -2.22045e-16
0.0 0.0 0.0 1.0
julia> @benchmark BasicBSpline._changebasis_sim(P1,P2)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 9.919 μs … 5.473 ms ┊ GC (min … max): 0.00% … 99.17%
Time (median): 10.450 μs ┊ GC (median): 0.00%
Time (mean ± σ): 11.455 μs ± 54.631 μs ┊ GC (mean ± σ): 4.74% ± 0.99%
▁▇█▅▁
▂█████▇▅▄▃▂▂▂▃▃▃▂▂▃▂▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
9.92 μs Histogram: frequency by time 16.2 μs <
Memory estimate: 6.78 KiB, allocs estimate: 143. |
23.798 μs → 1.319 μs 🎉 18x faster 🎉 🎉 🎉 julia> @benchmark BasicBSpline._changebasis_sim(P1,P2)
BenchmarkTools.Trial: 10000 samples with 10 evaluations.
Range (min … max): 988.800 ns … 376.767 μs ┊ GC (min … max): 0.00% … 99.21%
Time (median): 1.097 μs ┊ GC (median): 0.00%
Time (mean ± σ): 1.319 μs ± 6.258 μs ┊ GC (mean ± σ): 8.18% ± 1.72%
▆▇██▇▆▅▅▃▂▂▂▂▂▂▂▂▂▂▃▃▃▂▂▂▂▁▂▂▁▁▁▁ ▁ ▂
███████████████████████████████████▇█▇█▇█▇▇▆▇▇▆▇▇▇▇███▇▇▇▄▆▅▄ █
989 ns Histogram: log(frequency) by time 2.26 μs <
Memory estimate: 1.97 KiB, allocs estimate: 25. |
The test failures are related to the following issues around StaticArrays.jl. 0×0 matrix divisionjulia> using StaticArrays
julia> n = SMatrix{0,0,Float64}()
0×0 SMatrix{0, 0, Float64, 0} with indices SOneTo(0)×SOneTo(0)
julia> n \ n
0×0 SMatrix{0, 0, Float64, 0} with indices SOneTo(0)×SOneTo(0)
julia> n / n
ERROR: MethodError: one(::Type{Union{}}) is ambiguous. Candidates:
one(::Union{Type{T}, T}) where T<:AbstractString in Base at strings/basic.jl:262
one(::Union{Type{P}, P}) where P<:Dates.Period in Dates at /home/hyrodium/julia/julia-1.7.3/share/julia/stdlib/v1.7/Dates/src/periods.jl:54
one(::Type{SM}) where SM<:(Union{LinearAlgebra.Adjoint{T, <:Union{StaticArray{Tuple{var"#s2"}, T, 1} where var"#s2", StaticArray{Tuple{var"#s3", var"#s4"}, T, 2} where {var"#s3", var"#s4"}}}, LinearAlgebra.Diagonal{T, <:StaticArray{Tuple{var"#s13"}, T, 1} where var"#s13"}, LinearAlgebra.Hermitian{T, <:StaticArray{Tuple{var"#s10", var"#s11"}, T, 2} where {var"#s10", var"#s11"}}, LinearAlgebra.LowerTriangular{T, <:StaticArray{Tuple{var"#s18", var"#s19"}, T, 2} where {var"#s18", var"#s19"}}, LinearAlgebra.Symmetric{T, <:StaticArray{Tuple{var"#s7", var"#s8"}, T, 2} where {var"#s7", var"#s8"}}, LinearAlgebra.Transpose{T, <:Union{StaticArray{Tuple{var"#s2"}, T, 1} where var"#s2", StaticArray{Tuple{var"#s3", var"#s4"}, T, 2} where {var"#s3", var"#s4"}}}, LinearAlgebra.UnitLowerTriangular{T, <:StaticArray{Tuple{var"#s24", var"#s25"}, T, 2} where {var"#s24", var"#s25"}}, LinearAlgebra.UnitUpperTriangular{T, <:StaticArray{Tuple{var"#s21", var"#s22"}, T, 2} where {var"#s21", var"#s22"}}, LinearAlgebra.UpperTriangular{T, <:StaticArray{Tuple{var"#s15", var"#s16"}, T, 2} where {var"#s15", var"#s16"}}, StaticArray{Tuple{var"#s1", var"#s3"}, T, 2} where {var"#s1", var"#s3"}} where T) in StaticArrays at /home/hyrodium/.julia/dev/StaticArrays/src/linalg.jl:108
one(::Type{<:AbstractIrrational}) in Base at irrationals.jl:154
one(::Type{T}) where T<:Number in Base at number.jl:334
Possible fix, define
one(::Type{Union{}})
Stacktrace:
[1] __lu(A::SMatrix{0, 0, Union{}, 0}, #unused#::Val{true})
@ StaticArrays ~/.julia/dev/StaticArrays/src/lu.jl:112
[2] macro expansion
@ ~/.julia/dev/StaticArrays/src/lu.jl:85 [inlined]
[3] _lu(A::SMatrix{0, 0, Union{}, 0}, pivot::Val{true}, check::Bool)
@ StaticArrays ~/.julia/dev/StaticArrays/src/lu.jl:77
[4] lu(A::SMatrix{0, 0, Union{}, 0}, pivot::Val{true}; check::Bool)
@ StaticArrays ~/.julia/dev/StaticArrays/src/lu.jl:50
[5] lu(A::SMatrix{0, 0, Union{}, 0}; check::Bool)
@ StaticArrays ~/.julia/dev/StaticArrays/src/lu.jl:54
[6] lu(A::SMatrix{0, 0, Union{}, 0})
@ StaticArrays ~/.julia/dev/StaticArrays/src/lu.jl:54
[7] macro expansion
@ ~/.julia/dev/StaticArrays/src/solve.jl:55 [inlined]
[8] _solve
@ ~/.julia/dev/StaticArrays/src/solve.jl:45 [inlined]
[9] \
@ ~/.julia/dev/StaticArrays/src/solve.jl:1 [inlined]
[10] /(A::SMatrix{0, 0, Float64, 0}, B::SMatrix{0, 0, Float64, 0})
@ LinearAlgebra ~/julia/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/generic.jl:1152
[11] top-level scope
@ REPL[4]:1 This is already reported in JuliaArrays/StaticArrays.jl#1066. Matrix division with
|
Maybe, I'll fix this in a few weeks. (x-ref: JuliaArrays/StaticArrays.jl#1069) |
Codecov Report
@@ Coverage Diff @@
## master #242 +/- ##
==========================================
+ Coverage 98.68% 98.70% +0.01%
==========================================
Files 15 15
Lines 1372 1388 +16
==========================================
+ Hits 1354 1370 +16
Misses 18 18
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
On the current master
With this PR