@@ -34,17 +34,14 @@ function MatrixAlgebraKit.default_algorithm(
34
34
end
35
35
36
36
function similar_output (
37
- :: typeof (svd_compact!),
38
- A,
39
- s_axis:: AbstractUnitRange ,
40
- alg:: MatrixAlgebraKit.AbstractAlgorithm ,
37
+ :: typeof (svd_compact!), A, S_axes, alg:: MatrixAlgebraKit.AbstractAlgorithm
41
38
)
42
- U = similar (A, axes (A, 1 ), s_axis )
39
+ U = similar (A, axes (A, 1 ), S_axes[ 1 ] )
43
40
T = real (eltype (A))
44
41
# TODO : this should be replaced with a more general similar function that can handle setting
45
42
# the blocktype and element type - something like S = similar(A, BlockType(...))
46
- S = BlockSparseMatrix {T,Diagonal{T,Vector{T}}} (undef, (s_axis, s_axis) )
47
- Vt = similar (A, s_axis , axes (A, 2 ))
43
+ S = BlockSparseMatrix {T,Diagonal{T,Vector{T}}} (undef, S_axes )
44
+ Vt = similar (A, S_axes[ 2 ] , axes (A, 2 ))
48
45
return U, S, Vt
49
46
end
50
47
@@ -56,27 +53,34 @@ function MatrixAlgebraKit.initialize_output(
56
53
57
54
brows = eachblockaxis (axes (A, 1 ))
58
55
bcols = eachblockaxis (axes (A, 2 ))
59
- s_axes = similar (brows, bmn)
56
+ u_axes = similar (brows, bmn)
57
+ v_axes = similar (brows, bmn)
60
58
61
59
# fill in values for blocks that are present
62
60
bIs = collect (eachblockstoredindex (A))
63
61
browIs = Int .(first .(Tuple .(bIs)))
64
62
bcolIs = Int .(last .(Tuple .(bIs)))
65
63
for bI in eachblockstoredindex (A)
66
64
row, col = Int .(Tuple (bI))
67
- s_axes[col] = argmin (length, (brows[row], bcols[col]))
65
+ len = minimum (length, (brows[row], bcols[col]))
66
+ u_axes[col] = brows[row][Base. OneTo (len)]
67
+ v_axes[col] = bcols[col][Base. OneTo (len)]
68
68
end
69
69
70
70
# fill in values for blocks that aren't present, pairing them in order of occurence
71
71
# this is a convention, which at least gives the expected results for blockdiagonal
72
72
emptyrows = setdiff (1 : bm, browIs)
73
73
emptycols = setdiff (1 : bn, bcolIs)
74
74
for (row, col) in zip (emptyrows, emptycols)
75
- s_axes[col] = argmin (length, (brows[row], bcols[col]))
75
+ len = minimum (length, (brows[row], bcols[col]))
76
+ u_axes[col] = brows[row][Base. OneTo (len)]
77
+ v_axes[col] = bcols[col][Base. OneTo (len)]
76
78
end
77
79
78
- s_axis = mortar_axis (s_axes)
79
- U, S, Vt = similar_output (svd_compact!, A, s_axis, alg)
80
+ u_axis = mortar_axis (u_axes)
81
+ v_axis = mortar_axis (v_axes)
82
+ S_axes = (u_axis, v_axis)
83
+ U, S, Vt = similar_output (svd_compact!, A, S_axes, alg)
80
84
81
85
# allocate output
82
86
for bI in eachblockstoredindex (A)
@@ -96,12 +100,12 @@ function MatrixAlgebraKit.initialize_output(
96
100
end
97
101
98
102
function similar_output (
99
- :: typeof (svd_full!), A, s_axis :: AbstractUnitRange , alg:: MatrixAlgebraKit.AbstractAlgorithm
103
+ :: typeof (svd_full!), A, S_axes , alg:: MatrixAlgebraKit.AbstractAlgorithm
100
104
)
101
- U = similar (A, axes (A, 1 ), s_axis )
105
+ U = similar (A, axes (A, 1 ), S_axes[ 1 ] )
102
106
T = real (eltype (A))
103
- S = similar (A, T, (s_axis, axes (A, 2 )) )
104
- Vt = similar (A, axes (A, 2 ) , axes (A, 2 ))
107
+ S = similar (A, T, S_axes )
108
+ Vt = similar (A, S_axes[ 2 ] , axes (A, 2 ))
105
109
return U, S, Vt
106
110
end
107
111
@@ -111,30 +115,31 @@ function MatrixAlgebraKit.initialize_output(
111
115
bm, bn = blocksize (A)
112
116
113
117
brows = eachblockaxis (axes (A, 1 ))
114
- s_axes = similar (brows)
118
+ u_axes = similar (brows)
115
119
116
120
# fill in values for blocks that are present
117
121
bIs = collect (eachblockstoredindex (A))
118
122
browIs = Int .(first .(Tuple .(bIs)))
119
123
bcolIs = Int .(last .(Tuple .(bIs)))
120
124
for bI in eachblockstoredindex (A)
121
125
row, col = Int .(Tuple (bI))
122
- s_axes [col] = brows[row]
126
+ u_axes [col] = brows[row]
123
127
end
124
128
125
129
# fill in values for blocks that aren't present, pairing them in order of occurence
126
130
# this is a convention, which at least gives the expected results for blockdiagonal
127
131
emptyrows = setdiff (1 : bm, browIs)
128
132
emptycols = setdiff (1 : bn, bcolIs)
129
133
for (row, col) in zip (emptyrows, emptycols)
130
- s_axes [col] = brows[row]
134
+ u_axes [col] = brows[row]
131
135
end
132
136
for (i, k) in enumerate ((length (emptycols) + 1 ): length (emptyrows))
133
- s_axes [bn + i] = brows[emptyrows[k]]
137
+ u_axes [bn + i] = brows[emptyrows[k]]
134
138
end
135
139
136
- s_axis = mortar_axis (s_axes)
137
- U, S, Vt = similar_output (svd_full!, A, s_axis, alg)
140
+ u_axis = mortar_axis (u_axes)
141
+ S_axes = (u_axis, axes (A, 2 ))
142
+ U, S, Vt = similar_output (svd_full!, A, S_axes, alg)
138
143
139
144
# allocate output
140
145
for bI in eachblockstoredindex (A)
0 commit comments