Skip to content

Commit da3296b

Browse files
committed
reorganize allocation of identities
1 parent 857f8c0 commit da3296b

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/abstractblocksparsearray/abstractblocksparsematrix.jl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ function _allocate_svd_output(A::AbstractBlockSparseMatrix, full::Bool, ::Algori
5454
S = similar(A, real(eltype(A)), s_axis)
5555
Vt = similar(A, s_axis, axes(A, 2))
5656

57+
# also fill in identities for blocks that aren't present
58+
for (row, col) in zip(emptyrows, emptycols)
59+
copyto!(@view!(U[Block(row, col)]), LinearAlgebra.I)
60+
copyto!(@view!(Vt[Block(col, col)]), LinearAlgebra.I)
61+
end
62+
5763
return U, S, Vt
5864
end
5965

@@ -74,19 +80,5 @@ function svd!(
7480
Vt[bcol, bcol] = bUSV.Vt
7581
end
7682

77-
# fill in values for blocks that aren't present, pairing them in order of occurence
78-
block_inds_S = eachblockstoredindex(S)
79-
i = findfirst((block_inds_S), blockaxes(S, 1))
80-
bIs = collect(eachblockstoredindex(U))
81-
browIs = Int.(first.(Tuple.(bIs)))
82-
emptyrows = findall((browIs), 1:blocksize(U, 1))
83-
j = 0
84-
while !isnothing(i)
85-
copyto!(@view!(Vt[Block(i, i)]), LinearAlgebra.I)
86-
j += 1
87-
copyto!(@view!(U[Block(emptyrows[j], i)]), LinearAlgebra.I)
88-
i = findnext((block_inds_S), blockaxes(S, 1), i + 1)
89-
end
90-
9183
return SVD(U, S, Vt)
9284
end

0 commit comments

Comments
 (0)