Skip to content

Type instability in jacobian! filling JacobianResult when using StaticArrays #639

Closed
@mapclyps

Description

@mapclyps

Running the following code

using ForwardDiff
using StaticArrays

f(x)=SA[x[1]^2+x[2]^2, x[2]^2+x[3]^2]

x=SA[1.0,2,3]

y=f(x)

imdr=DiffResults.JacobianResult(y,x)

@code_warntype ForwardDiff.jacobian!(imdr,f,x) 

shows up as not type stable for me in Julia 1.8.5.
Maybe also related is this older topic on discourse https://discourse.julialang.org/t/am-i-using-diffresults-jl-correctly/35894

I think it is coming from

result = DiffResults.value!(d -> value(T,d), result, ydual)

Replacing the anonymous function d -> value(T,d) with Base.Fix1(value,T) fixes it for me.
I can make a PR in case this is the desired solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions