Skip to content

Commit 819b9bd

Browse files
committed
to_blockdiagonal now returns blocks
1 parent 4d48132 commit 819b9bd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blockdiagonalarray.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function try_to_blockdiagonal_perm(A)
2020
p = sortperm(J)
2121
Jsorted = J[p]
2222
allunique(Jsorted) || return nothing
23-
return I[p], Jsorted
23+
return Block.(I[p], Jsorted)
2424
end
2525

2626
"""
@@ -32,8 +32,11 @@ returns nothing, otherwise returns both the blockdiagonal `B` as well as the per
3232
function try_to_blockdiagonal(A::AbstractBlockSparseMatrix)
3333
perm = try_to_blockdiagonal_perm(A)
3434
isnothing(perm) && return perm
35-
I, J = perm
36-
diagblocks = blocks(A)[CartesianIndex.(invperm(I), J)]
35+
I = first.(Tuple.(perm))
36+
J = last.(Tuple.(perm))
37+
diagblocks = map(invperm(I), J) do i, j
38+
return A[Block(i, j)]
39+
end
3740
return BlockDiagonal(diagblocks), perm
3841
end
3942

0 commit comments

Comments
 (0)