JuliaArrays / JuliaArrays/BlockArrays.jl

BlockArray errors with generic linear algebra functions

Open
#131 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
254
Forks
39
PR merge metrics
No merged PRs in 30d

Description

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 missing bidiagonalize_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 of bidiagonalize_tall!).

julia> D = BlockArray( randn(4,4), [2, 2], [2, 2] )                                                                                                                                                                                                       
2×2-blocked 4×4 BlockArray{Float64,2}:
  0.923874   -0.0829803  │  0.286211   0.46231 
  0.195939    0.14953    │  1.8477    -0.321445
 ────────────────────────┼─────────────────────
 -0.0989605  -1.26688    │  1.42871   -0.659864
  0.403813   -0.86728    │  0.72237   -0.621602

julia> cond( D )                                                                                                                                                                                                                                          
ERROR: MethodError: no method matching bidiagonalize_tall!(::BlockArray{Float64,2,Array{Array{Float64,2},2},Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}})
Closest candidates are:
  bidiagonalize_tall!(::Array{T,2}) where T at /home/imcinerney/.julia/packages/GenericSVD/cT5Cu/src/bidiagonalize.jl:51
  bidiagonalize_tall!(::Array{T,2}, ::Bidiagonal) where T at /home/imcinerney/.julia/packages/GenericSVD/cT5Cu/src/bidiagonalize.jl:19
  bidiagonalize_tall!(::Adjoint{T2,Array{T,2}}) where {T, T2} at /home/imcinerney/.julia/packages/GenericSVD/cT5Cu/src/bidiagonalize.jl:47
Stacktrace:
 [1] generic_svdvals!(::BlockArray{Float64,2,Array{Array{Float64,2},2},Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}}; sorted::Bool) at /home/imcinerney/.julia/packages/GenericSVD/cT5Cu/src/GenericSVD.jl:57
 [2] generic_svdvals!(::BlockArray{Float64,2,Array{Array{Float64,2},2},Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}}) at /home/imcinerney/.julia/packages/GenericSVD/cT5Cu/src/GenericSVD.jl:53
 [3] svdvals!(::BlockArray{Float64,2,Array{Array{Float64,2},2},Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}}) at /home/imcinerney/.julia/packages/GenericSVD/cT5Cu/src/GenericSVD.jl:21
 [4] svdvals(::BlockArray{Float64,2,Array{Array{Float64,2},2},Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}}) at /home/imcinerney/dev/julia/main/1.4/usr/share/julia/stdlib/v1.4/LinearAlgebra/src/svd.jl:194
 [5] cond(::BlockArray{Float64,2,Array{Array{Float64,2},2},Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}}, ::Int64) at /home/imcinerney/dev/julia/main/1.4/usr/share/julia/stdlib/v1.4/LinearAlgebra/src/dense.jl:1419
 [6] cond(::BlockArray{Float64,2,Array{Array{Float64,2},2},Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}}) at /home/imcinerney/dev/julia/main/1.4/usr/share/julia/stdlib/v1.4/LinearAlgebra/src/dense.jl:1418
 [7] top-level scope at REPL[15]:1
 [8] eval(::Module, ::Any) at ./boot.jl:331
 [9] eval_user_input(::Any, ::REPL.REPLBackend) at /home/imcinerney/dev/julia/main/1.4/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [10] run_backend(::REPL.REPLBackend) at /home/imcinerney/.julia/packages/Revise/XFtoQ/src/Revise.jl:1162
 [11] top-level scope at REPL[1]:0

julia> cond( Array( D ) )                                                                                                                                                                                                                                 
8.508044778284596

So far the functions that I have found fail are (but there are probably more):

  • cond
  • svd
  • svdvals
  • eigen

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The failure enters through LinearAlgebra.cond and GenericSVD.generic_svdvals! in GenericSVD.jl at line 57; svd, svdvals, and eigen are also reported. Reproduce the BlockArray example and compare it with Array(D); done means these generic functions work on BlockArray without requiring an explicit caller-side conversion.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.