|
| 1 | +# We cannot use `@precompile_all_calls` from SnoopPrecompile.jl |
| 2 | +# directly on code since the internal buffers are not set up during |
| 3 | +# precompilation: |
| 4 | +# ``` |
| 5 | +# ERROR: LoadError: BoundsError: attempt to access 0-element Vector{Vector{Int}} at index [1] |
| 6 | +# Stacktrace: |
| 7 | +# [1] getindex |
| 8 | +# @ ./array.jl:924 [inlined] |
| 9 | +# [2] canonical_representation! |
| 10 | +# ... |
| 11 | +# ``` |
| 12 | +# |
| 13 | +# @precompile_all_calls begin |
| 14 | +# t = rootedtree([1, 2, 3, 2]) |
| 15 | +# butcher_representation(t) |
| 16 | +# order(t) |
| 17 | +# for (forest, subtree) in SplittingIterator(t) |
| 18 | +# end |
| 19 | +# for (forest, skeleton) in PartitionIterator(t) |
| 20 | +# end |
| 21 | +# |
| 22 | +# A = [0 0 0 0; 1//2 0 0 0; 0 1//2 0 0; 0 0 1 0] |
| 23 | +# b = [1 // 6, 1 // 3, 1 // 3, 1 // 6] |
| 24 | +# rk = RungeKuttaMethod(A, b) |
| 25 | +# for t in RootedTreeIterator(2) |
| 26 | +# residual_order_condition(t, rk) |
| 27 | +# end |
| 28 | +# |
| 29 | +# As = [ |
| 30 | +# [0 0; 1//2 1//2], |
| 31 | +# [1//2 0; 1//2 0], |
| 32 | +# ] |
| 33 | +# bs = [ |
| 34 | +# [1 // 2, 1 // 2], |
| 35 | +# [1 // 2, 1 // 2], |
| 36 | +# ] |
| 37 | +# ark = AdditiveRungeKuttaMethod(As, bs) |
| 38 | +# for t in BicoloredRootedTreeIterator(2) |
| 39 | +# residual_order_condition(t, ark) |
| 40 | +# end |
| 41 | +# |
| 42 | +# γ = [0.395 0 0 0; |
| 43 | +# -0.767672395484 0.395 0 0; |
| 44 | +# -0.851675323742 0.522967289188 0.395 0; |
| 45 | +# 0.288463109545 0.880214273381e-1 -0.337389840627 0.395] |
| 46 | +# A = [0 0 0 0; |
| 47 | +# 0.438 0 0 0; |
| 48 | +# 0.796920457938 0.730795420615e-1 0 0; |
| 49 | +# 0.796920457938 0.730795420615e-1 0 0] |
| 50 | +# b = [0.199293275701, 0.482645235674, 0.680614886256e-1, 0.25] |
| 51 | +# ros = RosenbrockMethod(γ, A, b) |
| 52 | +# for t in RootedTreeIterator(2) |
| 53 | +# residual_order_condition(t, ros) |
| 54 | +# end |
| 55 | +# end |
| 56 | +# |
| 57 | +# Thus, we use the older tools from SnoopCompile.jl to generate precompile |
| 58 | +# statements. This is based on the following code: |
| 59 | +# ```julia |
| 60 | +# julia> using SnoopCompile, ProfileView; tinf = @snoopi_deep begin |
| 61 | +# |
| 62 | +# using RootedTrees |
| 63 | +# |
| 64 | +# t = rootedtree([1, 2, 3, 2]) |
| 65 | +# butcher_representation(t) |
| 66 | +# order(t) |
| 67 | +# for (forest, subtree) in SplittingIterator(t) end |
| 68 | +# for (forest, skeleton) in PartitionIterator(t) end |
| 69 | +# |
| 70 | +# A = [0 0 0 0; 1//2 0 0 0; 0 1//2 0 0; 0 0 1 0] |
| 71 | +# b = [1//6, 1//3, 1//3, 1//6] |
| 72 | +# rk = RungeKuttaMethod(A, b) |
| 73 | +# for t in RootedTreeIterator(2) |
| 74 | +# residual_order_condition(t, rk) |
| 75 | +# end |
| 76 | +# |
| 77 | +# As = [ |
| 78 | +# [0 0; 1//2 1//2], |
| 79 | +# [1//2 0; 1//2 0] |
| 80 | +# ] |
| 81 | +# bs = [ |
| 82 | +# [1//2, 1//2], |
| 83 | +# [1//2, 1//2] |
| 84 | +# ] |
| 85 | +# ark = AdditiveRungeKuttaMethod(As, bs) |
| 86 | +# for t in BicoloredRootedTreeIterator(2) |
| 87 | +# residual_order_condition(t, ark) |
| 88 | +# end |
| 89 | +# |
| 90 | +# γ = [0.395 0 0 0; |
| 91 | +# -0.767672395484 0.395 0 0; |
| 92 | +# -0.851675323742 0.522967289188 0.395 0; |
| 93 | +# 0.288463109545 0.880214273381e-1 -.337389840627 0.395] |
| 94 | +# A = [0 0 0 0; |
| 95 | +# 0.438 0 0 0; |
| 96 | +# 0.796920457938 0.730795420615e-1 0 0; |
| 97 | +# 0.796920457938 0.730795420615e-1 0 0] |
| 98 | +# b = [0.199293275701, 0.482645235674, 0.680614886256e-1, 0.25] |
| 99 | +# ros = RosenbrockMethod(γ, A, b) |
| 100 | +# for t in RootedTreeIterator(2) |
| 101 | +# residual_order_condition(t, ros) |
| 102 | +# end |
| 103 | +# |
| 104 | +# end |
| 105 | +# InferenceTimingNode: 1.929538/2.721058 on Core.Compiler.Timings.ROOT() with 52 direct children |
| 106 | +# |
| 107 | +# julia> ttot, pcs = SnoopCompile.parcel(tinf); |
| 108 | +# |
| 109 | +# julia> ttot |
| 110 | +# 0.791520612 |
| 111 | +# |
| 112 | +# julia> SnoopCompile.write("/tmp/precompiles_RootedTrees", pcs, has_bodyfunction = true) |
| 113 | +# Base.Threads: precompiled 0.0049499190000000005 out of 0.0049499190000000005 |
| 114 | +# Base: precompiled 0.066721417 out of 0.068838787 |
| 115 | +# RootedTrees: precompiled 0.716612635 out of 0.7169763830000001 |
| 116 | +# ``` |
| 117 | +# See https://timholy.github.io/SnoopCompile.jl/dev/snoopi_deep_parcel/ |
| 118 | + |
| 119 | +function _precompile_() |
| 120 | + ccall(:jl_generating_output, Cint, ()) == 1 || return nothing |
| 121 | + |
| 122 | + Base.precompile(Tuple{typeof(residual_order_condition), |
| 123 | + RootedTree{Int64, Vector{Int64}}, |
| 124 | + RungeKuttaMethod{Rational{Int64}, Matrix{Rational{Int64}}, |
| 125 | + Vector{Rational{Int64}}}}) # time: 0.18134941 |
| 126 | + Base.precompile(Tuple{typeof(residual_order_condition), |
| 127 | + BicoloredRootedTree{Int64, Vector{Int64}, Vector{Bool}}, |
| 128 | + AdditiveRungeKuttaMethod{Rational{Int64}, |
| 129 | + Vector{ |
| 130 | + RungeKuttaMethod{Rational{Int64}, |
| 131 | + Matrix{ |
| 132 | + Rational{ |
| 133 | + Int64 |
| 134 | + } |
| 135 | + }, |
| 136 | + Vector{ |
| 137 | + Rational{ |
| 138 | + Int64 |
| 139 | + } |
| 140 | + }}}}}) # time: 0.16824293 |
| 141 | + Base.precompile(Tuple{typeof(rootedtree), Vector{Int64}}) # time: 0.087751105 |
| 142 | + Base.precompile(Tuple{typeof(residual_order_condition), |
| 143 | + RootedTree{Int64, Vector{Int64}}, |
| 144 | + RosenbrockMethod{Float64, Matrix{Float64}, Vector{Float64}}}) # time: 0.07817012 |
| 145 | + Base.precompile(Tuple{Type{RungeKuttaMethod}, Matrix{Rational{Int64}}, |
| 146 | + Vector{Rational{Int64}}}) # time: 0.075997345 |
| 147 | + Base.precompile(Tuple{Type{AdditiveRungeKuttaMethod}, Vector{Matrix{Rational{Int64}}}, |
| 148 | + Vector{Vector{Rational{Int64}}}}) # time: 0.05049169 |
| 149 | + Base.precompile(Tuple{typeof(iterate), |
| 150 | + SplittingIterator{RootedTree{Int64, Vector{Int64}}}}) # time: 0.044273302 |
| 151 | + Base.precompile(Tuple{Type{RosenbrockMethod}, Matrix{Float64}, Matrix{Float64}, |
| 152 | + Vector{Float64}}) # time: 0.016924093 |
| 153 | + Base.precompile(Tuple{typeof(butcher_representation), RootedTree{Int64, Vector{Int64}}}) # time: 0.014338499 |
| 154 | + Base.precompile(Tuple{typeof(iterate), BicoloredRootedTreeIterator{Int64}, |
| 155 | + Tuple{Bool, Int64}}) # time: 0.014068822 |
| 156 | + Base.precompile(Tuple{typeof(symmetry), |
| 157 | + BicoloredRootedTree{Int64, Vector{Int64}, Vector{Bool}}}) # time: 0.008579416 |
| 158 | + Base.precompile(Tuple{typeof(symmetry), RootedTree{Int64, Vector{Int64}}}) # time: 0.007220166 |
| 159 | + Base.precompile(Tuple{typeof(iterate), |
| 160 | + PartitionIterator{RootedTree{Int64, Vector{Int64}}, |
| 161 | + RootedTree{Int64, Vector{Int64}}}}) # time: 0.006673861 |
| 162 | + Base.precompile(Tuple{Type{BicoloredRootedTreeIterator}, Int64}) # time: 0.003071257 |
| 163 | + Base.precompile(Tuple{Type{PartitionIterator}, RootedTree{Int64, Vector{Int64}}}) # time: 0.002802794 |
| 164 | + Base.precompile(Tuple{typeof(iterate), RootedTreeIterator{Int64}, Bool}) # time: 0.002423941 |
| 165 | + Base.precompile(Tuple{Type{RootedTreeIterator}, Int64}) # time: 0.002368873 |
| 166 | + Base.precompile(Tuple{typeof(iterate), RootedTreeIterator{Int64}}) # time: 0.002200462 |
| 167 | + Base.precompile(Tuple{typeof(iterate), BicoloredRootedTreeIterator{Int64}}) # time: 0.001368852 |
| 168 | +end |
| 169 | + |
| 170 | +_precompile_() |
0 commit comments