mmikhasenko / ThreeBodyDecays.jl

Builder of the three-body decay model using cascade approach
https://mmikhasenko.github.io/ThreeBodyDecays.jl/
MIT License
2 stars 0 forks source link

Make types less parametric, more concrete #19

Closed mmikhasenko closed 7 months ago

mmikhasenko commented 7 months ago

When object are combined in an array, it's better when their parametric types are the same, so I probably should not make type parameters these types that vary between chains (Recoupling, Lineshape)

This works better,

@with_kw struct ChainΛb2Λγ <: AbstractDecayChain
    Xlineshape::AbstractLineShape
    two_j::Int
    HRk::Recoupling
    Hij::Recoupling
end

Reason:

I am finding that Julia does not do inference of the complex parametric types well.

Does julia give up nesting types when reaching certain depth? - I cannot reproduce it with basic types, but I noticed that my customary type information is lost

MWE

using StaticArrays
# Here is my customary parametric tyoe
abstract type AbstractDecayChain end
struct Chain{T<:Real} <: AbstractDecayChain
    a::T
end
ch = SVector(Chain(1), Chain(2.0), Chain(1//2))

typeof(ch)  # SVector{3, Chain}} 

N = length(ch)

# fully inferred
x = 1:N .=> zip((string.(1:N) .=> zip(1:N, Float64.(1:N))), 1:N)  # Vector{Pair{Int64, Tuple{Pair{String, Tuple{Int64, Float64}}, Int64}}}

# parametric type is dropped
y = 1:N .=> zip((string.(1:N) .=> zip(1:N, Float64.(1:N))), ch)  # Vector{Pair{Int64}}

y isa Vector{Pair{Int64, T} where T} # true
mmikhasenko commented 7 months ago

Already fixed

mmikhasenko commented 7 months ago

Well, the lineshape remain parametric in the module. No AbstractLineShape