JuliaArrays / JuliaArrays/BlockArrays.jl
BlockArray to Sparse quite slow
Open
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.
- Am I missing a point?
- Any chance to put
createSPin your package?
Thank you,
Best regards
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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