@@ -20,14 +20,21 @@ function MatrixAlgebraKit.default_svd_algorithm(
2020 return BlockPermutedDiagonalAlgorithm (alg)
2121end
2222
23+ # TODO : Put this in a common location or package,
24+ # maybe `TypeParameterAccessors.jl`?
25+ # Also define `imagtype`, `complextype`, etc.
26+ realtype (a:: AbstractArray ) = realtype (typeof (a))
27+ function realtype (A:: Type{<:AbstractArray} )
28+ return Base. promote_op (real, A)
29+ end
30+
31+ using DiagonalArrays: diagonaltype
2332function similar_output (
2433 :: typeof (svd_compact!), A, S_axes, alg:: MatrixAlgebraKit.AbstractAlgorithm
2534)
2635 U = similar (A, axes (A, 1 ), S_axes[1 ])
2736 T = real (eltype (A))
28- # TODO : this should be replaced with a more general similar function that can handle setting
29- # the blocktype and element type - something like S = similar(A, BlockType(...))
30- S = BlockSparseMatrix {T,Diagonal{T,Vector{T}}} (undef, S_axes)
37+ S = similar (A, BlockType (diagonaltype (realtype (blocktype (A)))), S_axes)
3138 Vt = similar (A, S_axes[2 ], axes (A, 2 ))
3239 return U, S, Vt
3340end
@@ -49,9 +56,9 @@ function MatrixAlgebraKit.initialize_output(
4956 bcolIs = Int .(last .(Tuple .(bIs)))
5057 for bI in eachblockstoredindex (A)
5158 row, col = Int .(Tuple (bI))
52- len = minimum (length, (brows[row], bcols[col]))
53- u_axes[col] = brows[row][Base . OneTo (len)]
54- v_axes[col] = bcols[col][Base . OneTo (len)]
59+ b = argmin (length, (brows[row], bcols[col]))
60+ u_axes[col] = b
61+ v_axes[col] = b
5562 end
5663
5764 # fill in values for blocks that aren't present, pairing them in order of occurence
0 commit comments