Skip to content

problem with StaticArrays and \ #487

@tpapp

Description

@tpapp

(I reported this issue at ForwardDiff.jl where I was told it is an issue with StaticArrays, so I am opening one here.)

Using Julia 1.0.0, [f6369f11] ForwardDiff v0.9.0, [90137ffa] StaticArrays v0.8.3, the following MWE

import ForwardDiff
using StaticArrays

function f(M, Tws, μs)
    Twμs = Tws .* μs
    mx = SMatrix{2,2}(M + Tws[2], -Twμs[2], -Twμs[1], M + Tws[1])
    mx \ Twμs
end
M = 1.0
Tws = SVector(2.0, 2.0)
μs = SVector(0.5, 0.5)
f(M, Tws, μs)                   # works
ForwardDiff.jacobian(μs -> f(M, Tws, μs), μs) # gives the error below

gives

julia> ForwardDiff.jacobian(μs -> f(M, Tws, μs), μs)
ERROR: MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{getfield(Main, Symbol("##3#4")),Float64},Float64,2})
Closest candidates are:
  Float64(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:185
  Float64(::T<:Number) where T<:Number at boot.jl:725
  Float64(::Int8) at float.jl:60
  ...
Stacktrace:
 [1] convert(::Type{Float64}, ::ForwardDiff.Dual{ForwardDiff.Tag{getfield(Main, Symbol("##3#4")),Float64},Float64,2}) at ./number.jl:7
 [2] macro expansion at /home/tamas/.julia/packages/StaticArrays/Ze5H3/src/util.jl:11 [inlined]
 [3] convert_ntuple at /home/tamas/.julia/packages/StaticArrays/Ze5H3/src/util.jl:8 [inlined]
 [4] SArray{Tuple{2,2},Float64,2,4}(::Tuple{Float64,ForwardDiff.Dual{ForwardDiff.Tag{getfield(Main, Symbol("##3#4")),Float64},Float64,2},ForwardDiff.Dual{ForwardDiff.Tag{getfield(Main, Symbol("##3#4")),Float64},Float64,2},Float64}) at /home/tamas/.julia/packages/StaticArrays/Ze5H3/src/SArray.jl:28
 [5] convert at /home/tamas/.julia/packages/StaticArrays/Ze5H3/src/convert.jl:8 [inlined]
 [6] det at /home/tamas/.julia/packages/StaticArrays/Ze5H3/src/det.jl:4 [inlined]
 [7] solve(::Size{(2, 2)}, ::Size{(2,)}, ::SArray{Tuple{2,2},Real,2,4}, ::SArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{getfield(Main, Symbol("##3#4")),Float64},Float64,2},1,2}) at /home/tamas/.julia/packages/StaticArrays/Ze5H3/src/solve.jl:8
 [8] \ at /home/tamas/.julia/packages/StaticArrays/Ze5H3/src/solve.jl:1 [inlined]
 [9] f(::Float64, ::SArray{Tuple{2},Float64,1,2}, ::SArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{getfield(Main, Symbol("##3#4")),Float64},Float64,2},1,2}) at ./REPL[11]:4
 [10] (::getfield(Main, Symbol("##3#4")))(::SArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{getfield(Main, Symbol("##3#4")),Float64},Float64,2},1,2}) at ./REPL[16]:1
 [11] static_dual_eval at /home/tamas/.julia/packages/ForwardDiff/hnKaN/src/apiutils.jl:30 [inlined]
 [12] vector_mode_jacobian(::getfield(Main, Symbol("##3#4")), ::SArray{Tuple{2},Float64,1,2} at /home/tamas/.julia/packages/ForwardDiff/hnKaN/src/jacobian.jl:172
 [13] jacobian(::Function, ::SArray{Tuple{2},Float64,1,2}) at /home/tamas/.julia/packages/ForwardDiff/hnKaN/src/jacobian.jl:81
 [14] top-level scope at none:0

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