Skip to content

Commit

Permalink
reorganize allocation of identities
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Jan 14, 2025
1 parent 857f8c0 commit da3296b
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/abstractblocksparsearray/abstractblocksparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ function _allocate_svd_output(A::AbstractBlockSparseMatrix, full::Bool, ::Algori
S = similar(A, real(eltype(A)), s_axis)
Vt = similar(A, s_axis, axes(A, 2))

Check warning on line 55 in src/abstractblocksparsearray/abstractblocksparsematrix.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractblocksparsearray/abstractblocksparsematrix.jl#L52-L55

Added lines #L52 - L55 were not covered by tests

# also fill in identities for blocks that aren't present
for (row, col) in zip(emptyrows, emptycols)
copyto!(@view!(U[Block(row, col)]), LinearAlgebra.I)
copyto!(@view!(Vt[Block(col, col)]), LinearAlgebra.I)
end

Check warning on line 61 in src/abstractblocksparsearray/abstractblocksparsematrix.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractblocksparsearray/abstractblocksparsematrix.jl#L58-L61

Added lines #L58 - L61 were not covered by tests

return U, S, Vt

Check warning on line 63 in src/abstractblocksparsearray/abstractblocksparsematrix.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractblocksparsearray/abstractblocksparsematrix.jl#L63

Added line #L63 was not covered by tests
end

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

Check warning on line 81 in src/abstractblocksparsearray/abstractblocksparsematrix.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractblocksparsearray/abstractblocksparsematrix.jl#L73-L81

Added lines #L73 - L81 were not covered by tests

# fill in values for blocks that aren't present, pairing them in order of occurence
block_inds_S = eachblockstoredindex(S)
i = findfirst((block_inds_S), blockaxes(S, 1))
bIs = collect(eachblockstoredindex(U))
browIs = Int.(first.(Tuple.(bIs)))
emptyrows = findall((browIs), 1:blocksize(U, 1))
j = 0
while !isnothing(i)
copyto!(@view!(Vt[Block(i, i)]), LinearAlgebra.I)
j += 1
copyto!(@view!(U[Block(emptyrows[j], i)]), LinearAlgebra.I)
i = findnext((block_inds_S), blockaxes(S, 1), i + 1)
end

return SVD(U, S, Vt)

Check warning on line 83 in src/abstractblocksparsearray/abstractblocksparsematrix.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractblocksparsearray/abstractblocksparsematrix.jl#L83

Added line #L83 was not covered by tests
end

0 comments on commit da3296b

Please sign in to comment.