-
Notifications
You must be signed in to change notification settings - Fork 35
Open
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) #5secondswhereas
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
briochemc
Metadata
Metadata
Assignees
Labels
No labels