@@ -89,13 +89,23 @@ function MatrixAlgebraKit.initialize_output(
89
89
return U, S, Vt
90
90
end
91
91
92
+ function similar_output (
93
+ :: typeof (svd_full!), A, s_axis:: AbstractUnitRange , alg:: MatrixAlgebraKit.AbstractAlgorithm
94
+ )
95
+ U = similar (A, axes (A, 1 ), s_axis)
96
+ T = real (eltype (A))
97
+ S = similar (A, T, (s_axis, axes (A, 2 )))
98
+ Vt = similar (A, axes (A, 2 ), axes (A, 2 ))
99
+ return U, S, Vt
100
+ end
101
+
92
102
function MatrixAlgebraKit. initialize_output (
93
103
:: typeof (svd_full!), A:: AbstractBlockSparseMatrix , alg:: BlockPermutedDiagonalAlgorithm
94
104
)
95
105
bm, bn = blocksize (A)
96
106
97
- brows = blocklengths (axes (A, 1 ))
98
- slengths = copy (brows)
107
+ brows = eachblockaxis (axes (A, 1 ))
108
+ s_axes = copy (brows)
99
109
100
110
# fill in values for blocks that are present
101
111
bIs = collect (eachblockstoredindex (A))
@@ -104,25 +114,22 @@ function MatrixAlgebraKit.initialize_output(
104
114
for bI in eachblockstoredindex (A)
105
115
row, col = Int .(Tuple (bI))
106
116
nrows = brows[row]
107
- slengths [col] = nrows
117
+ s_axes [col] = nrows
108
118
end
109
119
110
120
# fill in values for blocks that aren't present, pairing them in order of occurence
111
121
# this is a convention, which at least gives the expected results for blockdiagonal
112
122
emptyrows = setdiff (1 : bm, browIs)
113
123
emptycols = setdiff (1 : bn, bcolIs)
114
124
for (row, col) in zip (emptyrows, emptycols)
115
- slengths [col] = brows[row]
125
+ s_axes [col] = brows[row]
116
126
end
117
127
for (i, k) in enumerate ((length (emptycols) + 1 ): length (emptyrows))
118
- slengths [bn + i] = brows[emptyrows[k]]
128
+ s_axes [bn + i] = brows[emptyrows[k]]
119
129
end
120
130
121
- s_axis = blockedrange (slengths)
122
- U = similar (A, axes (A, 1 ), s_axis)
123
- Tr = real (eltype (A))
124
- S = similar (A, Tr, (s_axis, axes (A, 2 )))
125
- Vt = similar (A, axes (A, 2 ), axes (A, 2 ))
131
+ s_axis = mortar_axis (s_axes)
132
+ U, S, Vt = similar_output (svd_full!, A, s_axis, alg)
126
133
127
134
# allocate output
128
135
for bI in eachblockstoredindex (A)
0 commit comments