-
Notifications
You must be signed in to change notification settings - Fork 109
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
Inference improvement. #472
Conversation
Codecov Report
@@ Coverage Diff @@
## master #472 +/- ##
==========================================
- Coverage 85.41% 76.37% -9.04%
==========================================
Files 26 26
Lines 1741 1418 -323
==========================================
- Hits 1487 1083 -404
- Misses 254 335 +81
Continue to review full report at Codecov.
|
The inference problem of using Interpolations
nx = 5
A = zeros(Float64, nx, nx, nx, nx, nx, nx, nx)
itp = interpolate(A, BSpline(Quadratic(Reflect(OnCell()))))
@code_warntype Interpolations.hessian(itp, 1., 1., 1., 1., 1., 1., 1.) shows MethodInstance for Interpolations.hessian(::Interpolations.BSplineInterpolation{Float64, 7, OffsetArrays.OffsetArray{Float64, 7, Array{Float64, 7}}, BSpline{Quadratic{Reflect{OnCell}}}, NTuple{7, Base.OneTo{Int64}}}, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64)
from hessian(itp::Interpolations.BSplineInterpolation{T, N, TCoefs, IT, Axs} where {TCoefs<:AbstractArray, IT<:Union{NoInterp, Tuple{Vararg{Union{NoInterp, BSpline}}}, BSpline}, Axs<:Tuple{Vararg{AbstractUnitRange, N}}}, x::Vararg{Number, N}) where {T, N} in Interpolations at c:\Users\MYJ\Documents\GitHub\Interpolations.jl\src\b-splines\indexing.jl:37
Static Parameters
T = Float64
N = 7
Arguments
#self#::Core.Const(Interpolations.hessian)
itp::Interpolations.BSplineInterpolation{Float64, 7, OffsetArrays.OffsetArray{Float64, 7, Array{Float64, 7}}, BSpline{Quadratic{Reflect{OnCell}}}, NTuple{7, Base.OneTo{Int64}}}
x::NTuple{7, Float64}
Locals
#15::Interpolations.var"#15#16"{Interpolations.BSplineInterpolation{Float64, 7, OffsetArrays.OffsetArray{Float64, 7, Array{Float64, 7}}, BSpline{Quadratic{Reflect{OnCell}}}, NTuple{7, Base.OneTo{Int64}}}}
wis::NTuple{28, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}}
Body::StaticArrays.SMatrix{7, 7, Float64, 49}
1 ─ nothing
│ Core.NewvarNode(:(#15))
│ Core.NewvarNode(:(wis))
└── goto #5 if not $(Expr(:boundscheck))
2 ─ %5 = Core.tuple(Interpolations.Bool, itp)::Core.PartialStruct(Tuple{DataType, Interpolations.BSplineInterpolation{Float64, 7, OffsetArrays.OffsetArray{Float64, 7, Array{Float64, 7}}, BSpline{Quadratic{Reflect{OnCell}}}, NTuple{7, Base.OneTo{Int64}}}}, Any[Type{Bool}, Interpolations.BSplineInterpolation{Float64, 7, OffsetArrays.OffsetArray{Float64, 7, Array{Float64, 7}}, BSpline{Quadratic{Reflect{OnCell}}}, NTuple{7, Base.OneTo{Int64}}}])
│ %6 = Core._apply_iterate(Base.iterate, Interpolations.checkbounds, %5, x)::Bool
└── goto #4 if not %6
3 ─ goto #5
4 ─ %9 = Base.throw_boundserror::Core.Const(Base.throw_boundserror)
└── (%9)(itp, x)
5 ┄ %11 = Core.tuple(Interpolations.value_weights, Interpolations.gradient_weights, Interpolations.hessian_weights)::Core.Const((Interpolations.value_weights, Interpolations.gradient_weights, Interpolations.hessian_weights))
│ %12 = Core.tuple(%11)::Core.Const(((Interpolations.value_weights, Interpolations.gradient_weights, Interpolations.hessian_weights),))
│ %13 = Interpolations.itpinfo(itp)::Tuple{NTuple{7, BSpline{Quadratic{Reflect{OnCell}}}}, NTuple{7, Base.OneTo{Int64}}}
│ %14 = Core.tuple(x)::Tuple{NTuple{7, Float64}}
│ (wis = Core._apply_iterate(Base.iterate, Interpolations.weightedindexes, %12, %13, %14))
│ %16 = Interpolations.:(var"#15#16")::Core.Const(Interpolations.var"#15#16")
│ %17 = Core.typeof(itp)::Core.Const(Interpolations.BSplineInterpolation{Float64, 7, OffsetArrays.OffsetArray{Float64, 7, Array{Float64, 7}}, BSpline{Quadratic{Reflect{OnCell}}}, NTuple{7, Base.OneTo{Int64}}})
│ %18 = Core.apply_type(%16, %17)::Core.Const(Interpolations.var"#15#16"{Interpolations.BSplineInterpolation{Float64, 7, OffsetArrays.OffsetArray{Float64, 7,
Array{Float64, 7}}, BSpline{Quadratic{Reflect{OnCell}}}, NTuple{7, Base.OneTo{Int64}}}})
│ (#15 = %new(%18, itp))
│ %20 = #15::Interpolations.var"#15#16"{Interpolations.BSplineInterpolation{Float64, 7, OffsetArrays.OffsetArray{Float64, 7, Array{Float64, 7}}, BSpline{Quadratic{Reflect{OnCell}}}, NTuple{7, Base.OneTo{Int64}}}}
│ %21 = Interpolations.map(%20, wis::Core.PartialStruct(NTuple{28, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}}, Any[Core.PartialStruct(NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Any[Core.PartialStruct(Interpolations.WeightedAdjIndex{3, Float64}, Any[Int64, Core.Const((1.0, -2.0, 1.0))]), Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}]), NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Core.PartialStruct(NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Any[Interpolations.WeightedAdjIndex{3, Float64}, Core.PartialStruct(Interpolations.WeightedAdjIndex{3, Float64}, Any[Int64, Core.Const((1.0, -2.0, 1.0))]), Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3,
Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}]), NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Core.PartialStruct(NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Any[Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Core.PartialStruct(Interpolations.WeightedAdjIndex{3, Float64}, Any[Int64, Core.Const((1.0, -2.0, 1.0))]), Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}]), NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Core.PartialStruct(NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Any[Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Core.PartialStruct(Interpolations.WeightedAdjIndex{3, Float64}, Any[Int64, Core.Const((1.0, -2.0, 1.0))]), Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}]), NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Core.PartialStruct(NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Any[Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Core.PartialStruct(Interpolations.WeightedAdjIndex{3, Float64}, Any[Int64, Core.Const((1.0, -2.0, 1.0))]), Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}]), NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Core.PartialStruct(NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Any[Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Core.PartialStruct(Interpolations.WeightedAdjIndex{3, Float64}, Any[Int64, Core.Const((1.0, -2.0, 1.0))]), Interpolations.WeightedAdjIndex{3, Float64}]), NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Core.PartialStruct(NTuple{7, Interpolations.WeightedAdjIndex{3, Float64}}, Any[Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Interpolations.WeightedAdjIndex{3, Float64}, Core.PartialStruct(Interpolations.WeightedAdjIndex{3, Float64}, Any[Int64, Core.Const((1.0, -2.0, 1.0))])])]))::NTuple{28, Float64}
│ %22 = Interpolations.symmatrix(%21)::StaticArrays.SMatrix{7, 7, Float64, 49}
└── return %22 I think it should be enough for most cases.
|
fix ambiguity Update indexing.jl add more type annotation
add test only do extreme test when we have julia `power` `^` was llvm based, thus `symmatrix` for 4x4, 5x5, etc is not stable until 1.7. Update runtests.jl
Is this now good to merge? |
I think it should be sufficient for most usage. (In fact the kernal for coefficient calulation for 7d case is really huge. (IIRC over 10000 line in code typed) |
Bump? |
Hi, do you plan on merging this PR soon? I make heavy use of 3D hessians in my code and this fixes type stability. |
Thanks for the reminder, @touste. Are you using this branch in production? |
Yes I was using this branch without any issue for a while, although I won't go so far as to say my code is "production" :-D |
The test seems to be failing as merged into master? |
Previous test was done on 1.7.0. I'll take a look today. |
Fix inference on `symmatrix` (patch for #472)
Fix #469. test added. (I only test it on master)