You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I would like to auto-generate functions that create large (roughly 10x10) static matrices. However, the call of SymbolicUtils.Code.create_array seems slow as shown in the MWE below. Some brief tests suggest that the problem might be the elems... in
using StaticArrays
using Symbolics
using BenchmarkTools
functionsymbolics_output(a, b, c, d)
#= /Users/asslaj01/.julia/packages/SymbolicUtils/8d6hE/src/code.jl:373 =##= /Users/asslaj01/.julia/packages/SymbolicUtils/8d6hE/src/code.jl:374 =##= /Users/asslaj01/.julia/packages/SymbolicUtils/8d6hE/src/code.jl:375 =#begin#= /Users/asslaj01/.julia/packages/SymbolicUtils/8d6hE/src/code.jl:468 =#
(SymbolicUtils.Code.create_array)(SArray, nothing, Val{2}(), Val{(8, 8)}(), a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d)
endendfunctionsymbolics_optimized(a, b, c, d)
SMatrix{8,8,Float64,64}(a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d)
end@benchmarksymbolics_output(1.0, 2.0, 3.0, 4.0)
@benchmarksymbolics_optimized(1.0, 2.0, 3.0, 4.0)
Output:
BenchmarkTools.Trial:10000 samples with 8 evaluations.
Range (min … max):3.114 μs …12.461 μs ┊ GC (min … max):0.00%…0.00%
Time (median):3.191 μs ┊ GC (median):0.00%
Time (mean ± σ):3.221 μs ±319.398 ns ┊ GC (mean ± σ):0.00%±0.00%
▄█▆▁
▂▃▅████▅▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▁▂▂▁▁▂▁▂▁▁▁▂▁▁▁▂▂▂▂▂ ▃
3.11 μs Histogram: frequency by time 4.04 μs <
Memory estimate:3.12 KiB, allocs estimate:68.
vs.
BenchmarkTools.Trial:10000 samples with 1000 evaluations.
Range (min … max):5.775 ns …61.289 ns ┊ GC (min … max):0.00%…0.00%
Time (median):5.796 ns ┊ GC (median):0.00%
Time (mean ± σ):5.861 ns ±0.928 ns ┊ GC (mean ± σ):0.00%±0.00%
▄█▃
███▅▃▃▃▃▂▂▂▂▂▂▂▂▂▂▂▁▁▂▁▁▁▁▁▁▂▂▂▁▁▁▂▁▂▁▁▂▂▂▂▂▂▁▁▁▁▁▂▁▁▂▂▂▂▂ ▂
5.78 ns Histogram: frequency by time 6.47 ns <
Memory estimate:0 bytes, allocs estimate:0.
The text was updated successfully, but these errors were encountered:
Does simply removing the ... solve the problem? Or does it create other problems somewhere? (Julia noob here)
using StaticArrays
using Symbolics
using BenchmarkTools
@inline function create_array2(::Type{<:SArray}, ::Nothing, nd::Val, ::Val{dims}, elems...) where dims
SArray{Tuple{dims...}}(elems)
end
function symbolics_output(a, b, c, d)
#= /Users/asslaj01/.julia/packages/SymbolicUtils/8d6hE/src/code.jl:373 =#
#= /Users/asslaj01/.julia/packages/SymbolicUtils/8d6hE/src/code.jl:374 =#
#= /Users/asslaj01/.julia/packages/SymbolicUtils/8d6hE/src/code.jl:375 =#
begin
#= /Users/asslaj01/.julia/packages/SymbolicUtils/8d6hE/src/code.jl:468 =#
(create_array2)(SArray, nothing, Val{2}(), Val{(8, 8)}(), a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d)
end
end
@benchmark symbolics_output(1.0, 2.0, 3.0, 4.0)
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
Range (min … max): 3.917 ns … 17.943 ns ┊ GC (min … max): 0.00% … 0.00%
Time (median): 3.967 ns ┊ GC (median): 0.00%
Time (mean ± σ): 4.010 ns ± 0.371 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
█
▅█▄▂▂▂▂▂▁▂▁▂▂▁▂▂▂▁▁▂▂▂▂▂▂▂▁▂▂▁▁▂▁▂▁▂▂▂▂▂▁▂▂▁▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▂
3.92 ns Histogram: frequency by time 5.78 ns <
Memory estimate: 0 bytes, allocs estimate: 0.
Hi,
I would like to auto-generate functions that create large (roughly
10x10
) static matrices. However, the call ofSymbolicUtils.Code.create_array
seems slow as shown in the MWE below. Some brief tests suggest that the problem might be theelems...
inSymbolicUtils.jl/src/code.jl
Line 565 in 835fb0d
Many thanks for looking into this!!!
MWE:
Output:
vs.
The text was updated successfully, but these errors were encountered: