Skip to content

Add array conversions for AbstractQ #1462

@dlfivefifty

Description

@dlfivefifty

I think all of these should work:

julia> Q = qr(randn(10,5)).Q;

julia> Matrix(Q); # fine

julia> Array(Q); # fine

julia> AbstractMatrix(Q);
ERROR: MethodError: no method matching (AbstractMatrix)(::LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}})
The type `AbstractMatrix` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  (AbstractMatrix)(::Hessenberg)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/hessenberg.jl:497
  (AbstractMatrix)(::QRPivoted)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/qr.jl:454
  (AbstractMatrix)(::Eigen)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/eigen.jl:674
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[9]:1

julia> convert(AbstractMatrix, Q);
ERROR: MethodError: no method matching (AbstractMatrix)(::LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}})
The type `AbstractMatrix` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  (AbstractMatrix)(::Hessenberg)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/hessenberg.jl:497
  (AbstractMatrix)(::QRPivoted)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/qr.jl:454
  (AbstractMatrix)(::Eigen)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/eigen.jl:674
  ...

Stacktrace:
 [1] convert(::Type{AbstractMatrix}, Q::LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}})
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/abstractq.jl:49
 [2] top-level scope
   @ REPL[10]:1

julia> AbstractArray(Q);
ERROR: MethodError: no method matching AbstractArray(::LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}})
The type `AbstractArray` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  AbstractArray(::Hessenberg)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/hessenberg.jl:494
  AbstractArray(::QRPivoted)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/qr.jl:455
  AbstractArray(::Eigen)
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/eigen.jl:675
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[12]:1

julia> AbstractMatrix{Float64}(Q);
ERROR: MethodError: no method matching AbstractMatrix{Float64}(::LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}})
The type `AbstractMatrix{Float64}` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  AbstractMatrix{T}(::Bidiagonal{T, V} where V<:AbstractVector{T}) where T
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/bidiag.jl:232
  AbstractMatrix{T}(::Bidiagonal) where T
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/bidiag.jl:231
  AbstractMatrix{T}(::Tridiagonal{T, V} where V<:AbstractVector{T}) where T
   @ LinearAlgebra ~/Projects/julia-1.11/usr/share/julia/stdlib/v1.11/LinearAlgebra/src/tridiag.jl:803
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[13]:1

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