JuliaArrays / JuliaArrays/BlockArrays.jl

BlockArray to Sparse quite slow

Open
#78 8 comments 1 reaction 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

Hi,

I noticed the following is quite slow

using LinearAlgebra, SparseArrays, BlockArrays

M = 30
N = 500
J = BlockArray(spzeros(M * N, M * N), N * ones(Int64,M),  N * ones(Int64,M))

for ii=2:M
    setblock!(J, sprand(N,N,1/N), ii, ii)
    setblock!(J, sprand(N,N,1/N), ii,ii-1)
end

J1 = @time sparse(J) #5seconds

whereas

function createSP(J::BlockArray)
    nl, nc = size(J.blocks)
    N = size(J[Block(1,1)])[1]
    res = spzeros(N,N*nc)
    for i=1:nl
        line = J[Block(i,1)]
        for j=2:nc
            line = hcat(line,J[Block(i,j)])
        end
        res = vcat(res,line)
    end
    return res[N+1:end,:]
end

Jb = @time createSP(J)

takes 0.23s.

  1. Am I missing a point?
  2. Any chance to put createSP in your package?

Thank you,

Best regards

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 reproduction in the issue and profile or inspect the sparse(J) conversion for the BlockArray example. Compare its behavior and output with createSP(J), then determine whether the conversion should be optimized or whether a helper belongs in the package. Done means a documented performance improvement or a clear resolution of the proposed helper, backed by the reproduction.

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.