ForwardDiff.jl icon indicating copy to clipboard operation
ForwardDiff.jl copied to clipboard

missing method AD'ing through a QR decomposition

Open tpapp opened this issue 7 years ago • 1 comments

Could not reduce this to a MWE yet, but I get this error message when using ForwardDiff.jacobian on a problem that uses the QR decomposition for least squares.

ERROR: MethodError: no method matching A_ldiv_B!(::Base.LinAlg.QRCompactWY{ForwardDiff.Dual{ForwardDiff.Tag{IndirectLikelihood.##3#4{IndirectLikelihood.IndirectLikelihoodProblem{SinglesModel{Float64},AuxModel,SinglesData{Float64,Float64}}},Float64},Float64,4},Array{ForwardDiff.Dual{ForwardDiff.Tag{IndirectLikelihood.##3#4{IndirectLikelihood.IndirectLikelihoodProblem{SinglesModel{Float64},AuxModel,SinglesData{Float64,Float64}}},Float64},Float64,4},2}}, ::Array{ForwardDiff.Dual{ForwardDiff.Tag{IndirectLikelihood.##3#4{IndirectLikelihood.IndirectLikelihoodProblem{SinglesModel{Float64},AuxModel,SinglesData{Float64,Float64}}},Float64},Float64,4},2})
Closest candidates are:
  A_ldiv_B!(::Base.LinAlg.QR{T,S} where S<:(AbstractArray{T,2} where T), ::Union{Base.ReshapedArray{T,2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T,2}, SubArray{T,2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}) where T at linalg/qr.jl:730
  A_ldiv_B!(::Base.LinAlg.QRPivoted, ::Union{Base.ReshapedArray{T,2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T,2}, SubArray{T,2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray} where T) at linalg/qr.jl:782
  A_ldiv_B!(::Base.LinAlg.LQ{T,S} where S<:(AbstractArray{T,2} where T), ::Union{Union{Base.ReshapedArray{T,1,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T,1}, SubArray{T,1,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}, Union{Base.ReshapedArray{T,2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T,2}, SubArray{T,2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}}) where T at linalg/lq.jl:234
  ...
Stacktrace:
 [1] \(::Base.LinAlg.QRCompactWY{Float64,Array{Float64,2}}, ::Array{ForwardDiff.Dual{ForwardDiff.Tag{IndirectLikelihood.##3#4{IndirectLikelihood.IndirectLikelihoodProblem{SinglesModel{Float64},AuxModel,SinglesData{Float64,Float64}}},Float64},Float64,4},2}) at ./linalg/qr.jl:819

Importantly, in the X \ Y the Y is a matrix, not a vector (multiple independent variables).

Using Julia v0.6.1, tried both ForwardDiff master and 0.7.0. A workaround would also help.

tpapp avatar Dec 15 '17 10:12 tpapp

I realized that I can just use qrfact(X, Val{true}) (ie pivoting) and that works. So perhaps this issue should be revisited after Julia v0.7 comes out, since https://github.com/JuliaLang/julia/pull/24969 changed a lot of the internals.

tpapp avatar Dec 15 '17 11:12 tpapp