Skip to content

Commit

Permalink
Avoid field access in try_to_blockdiagonal
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Nov 11, 2024
1 parent 8201967 commit 1dc822f
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ end

# Cast to block-diagonal implementation if permuted-blockdiagonal
function try_to_blockdiagonal_perm(A)
keys = map(Base.Fix2(getproperty, :n), collect(block_stored_indices(A)))
I = first.(keys)
inds = map(x -> Int.(Tuple(x)), vec(collect(block_stored_indices(A))))
I = first.(inds)
allunique(I) || return nothing

J = last.(keys)
J = last.(inds)
p = sortperm(J)
Jsorted = J[p]
allunique(Jsorted) || return nothing

return I[p], Jsorted
end

Expand All @@ -35,12 +33,10 @@ function try_to_blockdiagonal(A::AbstractBlockSparseMatrix)
perm = try_to_blockdiagonal_perm(A)
isnothing(perm) && return perm
I, J = perm
diagblocks = blocks(A)[tuple.(invperm(I), J)]
diagblocks = blocks(A)[CartesianIndex.(invperm(I), J)]
return BlockDiagonal(diagblocks), perm
end

# TODO: block_stored_indices(BlockDiagonal) yields all indices

# SVD implementation
function eigencopy_oftype(A::BlockDiagonal, S)
diag = map(Base.Fix2(eigencopy_oftype, S), A.blocks.diag)
Expand Down

0 comments on commit 1dc822f

Please sign in to comment.