Skip to content

Commit 565a6f7

Browse files
committed
Add note about more general similar
1 parent c2e4227 commit 565a6f7

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/factorizations/svd.jl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ function MatrixAlgebraKit.default_svd_algorithm(A::AbstractBlockSparseMatrix; kw
1818
return BlockPermutedDiagonalAlgorithm(alg)
1919
end
2020

21-
#=
22-
Note: here I'm being generic about the matrix type, which effectively means that I'm making
23-
some assumptions about the output type of the algorithm, ie that this will return
24-
Matrix{T},Diagonal{real(T)},Matrix{T}. In principle this is not guaranteed, although it
25-
should cover most cases. The alternative is to be more specific about the matrix type and
26-
replace the `similar` calls with explicit `BlockSparseArray` constructor calls. In that case
27-
I can simply call `initialize_output` on the input blocks, and take whatever is returned.
28-
We should probably discuss which way to go.
29-
=#
21+
# TODO: this should be replaced with a more general similar function that can handle setting
22+
# the blocktype and element type - something like S = similar(A, BlockType(...))
23+
function _similar_S(A::AbstractBlockSparseMatrix, s_axis)
24+
T = real(eltype(A))
25+
return BlockSparseArray{T,2,Diagonal{T,Vector{T}}}(undef, (s_axis, s_axis))
26+
end
3027

3128
function MatrixAlgebraKit.initialize_output(
3229
::typeof(svd_compact!),
@@ -61,8 +58,7 @@ function MatrixAlgebraKit.initialize_output(
6158

6259
s_axis = blockedrange(slengths)
6360
U = similar(A, axes(A, 1), s_axis)
64-
Tr = real(eltype(A))
65-
S = BlockSparseArray{Tr,2,Diagonal{Tr,Vector{Tr}}}(undef, (s_axis, s_axis))
61+
S = _similar_S(A, s_axis)
6662
Vt = similar(A, s_axis, axes(A, 2))
6763

6864
# allocate output

0 commit comments

Comments
 (0)