JuliaArrays / JuliaArrays/BlockArrays.jl

\ Operator with SparseMatrixCSC blocks calls dense Solver

Open
#157 1 comment 2 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

Thanks for the nice package.
Recently, I noticed that if the blocks are of type SparseMatrixCSC a dense solver is called. Is this intended or known?
MWE:

julia> using BlockArrays

julia> using SparseArrays

julia> blocktest = BlockArray(sprand(4, 5, 0.7), [1,3], [2,3])
2×2-blocked 4×5 BlockArray{Float64,2,Array{SparseMatrixCSC{Float64,Int64},2},Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}}:
 0.0  0.16344    │  0.331454  0.0       0.0
 ────────────────┼──────────────────────────────
 0.0  0.0121386  │  0.411176  0.399074  0.267498
 0.0  0.321397   │  0.602725  0.0       0.105105
 0.0  0.402935   │  0.383906  0.897609  0.477092

julia> b = ones(4)
4-element Array{Float64,1}:
 1.0
 1.0
 1.0
 1.0

julia> @which blocktest \ b
\(A::ArrayLayouts.LayoutArray{T,2} where T, x::AbstractArray{T,1} where T) in ArrayLayouts at /home/max/.julia/packages/ArrayLayouts/9PQtL/src/ldiv.jl:145

julia> sparsetest = sprand(4,5,0.7)
4×5 SparseMatrixCSC{Float64,Int64} with 14 stored entries:
  [1, 1]  =  0.00801114
  [2, 1]  =  0.806908
  [1, 2]  =  0.565691
  [2, 2]  =  0.120568
  [4, 2]  =  0.934967
  [1, 3]  =  0.0708214
  [2, 3]  =  0.287633
  [3, 3]  =  0.0779688
  [4, 3]  =  0.867172
  [3, 4]  =  0.681556
  [4, 4]  =  0.873379
  [1, 5]  =  0.425396
  [2, 5]  =  0.836935
  [4, 5]  =  0.944869

julia> @which sparsetest \ b
\(A::SparseArrays.AbstractSparseMatrixCSC, B::Union{AbstractArray{T,1}, AbstractArray{T,2}} where T) in SparseArrays at /usr/share/julia/stdlib/v1.5/SparseArrays/src/linalg.jl:1460

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

Start with the Julia MWE and compare the displayed dispatch locations in ArrayLayouts/src/ldiv.jl:145 and SparseArrays/src/linalg.jl:1460. Trace how a BlockArray containing SparseMatrixCSC blocks selects its solver, then verify the intended behavior with a focused regression test for the shown operator and vector.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.