jlchan/FluxDiffUtils.jl

Type instability in `hadamard_jacobian` from construction of block matrix

Closed this issue · 2 comments

cgt3 commented

Line 75 of hadamard_jacobian.jl causes the function hadamard_jacobian(A_list, product_type...) to be type unstable. The instability can be recreated with the following snippet of code:

    function makeBlockJ(U)
        Nfields = length(U)
        n = length(U[1])
        Z = spzeros(n,n)
        J = SMatrix{Nfields,Nfields}( [Z for i in 1:Nfields, j in 1:Nfields])
    end
    @code_warntype makeBlockJ(U)

Added hadamard_jacobian with Nfields as Val{T} type. Does this fix things?

You may have to manually add the most recent commit 1ba950d

cgt3 commented

Yes, it is now type stable