Why is qr! not available for a view?

I tried to use qr! on a view of a dense matrix, but apparently there is no method for that:

  LoadError: MethodError: no method matching qr!(::SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true})                                                
  Closest candidates are:                                                                                                                                                                   
    qr!(::StridedMatrix{var"#s882"} where var"#s882"<:Union{Float32, Float64, ComplexF32, ComplexF64}, ::LinearAlgebra.NoPivot; blocksize) at C:\Users\pkonl\SublimeJulia_1.8\assets\julia-1.8.2\share\julia\stdlib\v1.8\LinearAlgebra\src\qr.jl:292                                                                                                                                    
    qr!(::StridedMatrix{var"#s885"} where var"#s885"<:Union{Float32, Float64, ComplexF32, ComplexF64}, ::LinearAlgebra.ColumnNorm) at C:\Users\pkonl\SublimeJulia_1.8\assets\julia-1.8.2\share\julia\stdlib\v1.8\LinearAlgebra\src\qr.jl:294                                                                                                                                            
    qr!(::AbstractMatrix) at C:\Users\pkonl\SublimeJulia_1.8\assets\julia-1.8.2\share\julia\stdlib\v1.8\LinearAlgebra\src\qr.jl:340                                                         

Is that something that I could rectify?

I’m not an expert on reading subarray types, but it looks to me like you accidentally passed in a 1D view, or something like that. The following works fine in my REPL:

julia> A = randn(10,10);
julia> B = view(A, 1:9, 1:9);
julia> Bf = qr!(B);

The reason I mention the 1D view is because the typeof of my view is

julia> typeof(B)
SubArray{Float64, 2, Matrix{Float64}, Tuple{UnitRange{Int64}, UnitRange{Int64}}, false}

which is different from what your method error gave.

Or am I misunderstanding some part of your post?

You are right, I had a mistake there passing the array. It was received as a vector.

1 Like