Open imciner2 opened 4 years ago
Note there is no guarantee such functions work for all arrays, including those in Base:
julia> cond(Tridiagonal(randn(5),randn(6),randn(5)))
ERROR: MethodError: no method matching svdvals!(::Tridiagonal{Float64,Array{Float64,1}})
Closest candidates are:
svdvals!(::SymTridiagonal) at /Users/solver/Projects/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/tridiag.jl:350
svdvals!(::StridedArray{T, 2}) where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at /Users/solver/Projects/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/svd.jl:193
svdvals!(::StridedArray{T, 2}, ::StridedArray{T, 2}) where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at /Users/solver/Projects/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/svd.jl:501
...
Stacktrace:
[1] svdvals(::Tridiagonal{Float64,Array{Float64,1}}) at /Users/solver/Projects/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/svd.jl:194
[2] cond(::Tridiagonal{Float64,Array{Float64,1}}, ::Int64) at /Users/solver/Projects/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/dense.jl:1430
[3] cond(::Tridiagonal{Float64,Array{Float64,1}}) at /Users/solver/Projects/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/dense.jl:1429
[4] top-level scope at REPL[3]:1
So while your suggestion is a good one, it isn't required.
That said, I'll be happy to merge a PR, though svd
will require some thought on what the natural block structure is.
When using the generic fallback functions provided by LinearAlgebra,
BlockArray
type matrices don't work properly. I'm not sure what the best way of handling this would be, but I guess we could theoretically generate versions of the linear algebra functions that fail and have them take the block array and do a conversion to a normal array when calling the standard linear algebra function.For example, the
cond
function fails due to a missingbidiagonalize_tall!
function. Of course, explicitly converting the block array to a normal array allows the computation to succeed (since it no longer needs the specialization ofbidiagonalize_tall!
).So far the functions that I have found fail are (but there are probably more):
cond
svd
svdvals
eigen