@@ -3,10 +3,16 @@ SVD on blockmatrices:
33Interpret the matrix as a linear map acting on vector spaces with a direct sum structure, which is reflected in the structure of U and V.
44In the generic case, the SVD does not preserve this structure, and can mix up the blocks, so S becomes a single block.
55(Implementation-wise, also most efficiently done by first mapping to a `BlockedArray`)
6+ In the case of `BlockDiagonal` however, the structure is preserved and carried over to the structure of `S`.
67=#
78
89LinearAlgebra. eigencopy_oftype (A:: AbstractBlockMatrix , S) = BlockedArray (Array {S} (A), blocksizes (A, 1 ), blocksizes (A, 2 ))
910
11+ function LinearAlgebra. eigencopy_oftype (A:: BlockDiagonal , S)
12+ diag = map (Base. Fix2 (LinearAlgebra. eigencopy_oftype, S), A. blocks. diag)
13+ return BlockDiagonal (diag)
14+ end
15+
1016function LinearAlgebra. svd! (A:: BlockedMatrix ; full:: Bool = false , alg:: LinearAlgebra.Algorithm = default_svd_alg (A))
1117 USV = svd! (parent (A); full, alg)
1218
@@ -19,3 +25,11 @@ function LinearAlgebra.svd!(A::BlockedMatrix; full::Bool=false, alg::LinearAlgeb
1925 vt = BlockedArray (USV. Vt, bsz2, bsz3)
2026 return SVD (u, s, vt)
2127end
28+
29+ function LinearAlgebra. svd! (A:: BlockDiagonal ; full:: Bool = false , alg:: LinearAlgebra.Algorithm = default_svd_alg (A))
30+ USVs = map (a -> svd! (a; full, alg), A. blocks. diag)
31+ Us = map (Base. Fix2 (getproperty, :U ), USVs)
32+ Ss = map (Base. Fix2 (getproperty, :S ), USVs)
33+ Vts = map (Base. Fix2 (getproperty, :Vt ), USVs)
34+ return SVD (BlockDiagonal (Us), mortar (Ss), BlockDiagonal (Vts))
35+ end
0 commit comments