Skip to content

Commit d4e2a4d

Browse files
committed
Generalize for graded arrays
1 parent b261448 commit d4e2a4d

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/factorizations/qr.jl

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@ function MatrixAlgebraKit.initialize_output(
2525
bm, bn = blocksize(A)
2626
bmn = min(bm, bn)
2727

28-
brows = blocklengths(axes(A, 1))
29-
bcols = blocklengths(axes(A, 2))
30-
rlengths = Vector{Int}(undef, bmn)
28+
brows = eachblockaxis(axes(A, 1))
29+
bcols = eachblockaxis(axes(A, 2))
30+
r_axes = similar(brows, bmn)
3131

3232
# fill in values for blocks that are present
3333
bIs = collect(eachblockstoredindex(A))
3434
browIs = Int.(first.(Tuple.(bIs)))
3535
bcolIs = Int.(last.(Tuple.(bIs)))
3636
for bI in eachblockstoredindex(A)
3737
row, col = Int.(Tuple(bI))
38-
nrows = brows[row]
39-
ncols = bcols[col]
40-
rlengths[col] = min(nrows, ncols)
38+
len = minimum(length, (brows[row], bcols[col]))
39+
r_axes[col] = bcols[col][Base.OneTo(len)]
4140
end
4241

4342
# fill in values for blocks that aren't present, pairing them in order of occurence
4443
# this is a convention, which at least gives the expected results for blockdiagonal
4544
emptyrows = setdiff(1:bm, browIs)
4645
emptycols = setdiff(1:bn, bcolIs)
4746
for (row, col) in zip(emptyrows, emptycols)
48-
rlengths[col] = min(brows[row], bcols[col])
47+
len = minimum(length, (brows[row], bcols[col]))
48+
r_axes[col] = bcols[col][Base.OneTo(len)]
4949
end
5050

51-
r_axis = blockedrange(rlengths)
51+
r_axis = mortar_axis(r_axes)
5252
Q = similar(A, axes(A, 1), r_axis)
5353
R = similar(A, r_axis, axes(A, 2))
5454

@@ -73,31 +73,30 @@ function MatrixAlgebraKit.initialize_output(
7373
)
7474
bm, bn = blocksize(A)
7575

76-
brows = blocklengths(axes(A, 1))
77-
rlengths = copy(brows)
76+
brows = eachblockaxis(axes(A, 1))
77+
r_axes = copy(brows)
7878

7979
# fill in values for blocks that are present
8080
bIs = collect(eachblockstoredindex(A))
8181
browIs = Int.(first.(Tuple.(bIs)))
8282
bcolIs = Int.(last.(Tuple.(bIs)))
8383
for bI in eachblockstoredindex(A)
8484
row, col = Int.(Tuple(bI))
85-
nrows = brows[row]
86-
rlengths[col] = nrows
85+
r_axes[col] = brows[row]
8786
end
8887

8988
# fill in values for blocks that aren't present, pairing them in order of occurence
9089
# this is a convention, which at least gives the expected results for blockdiagonal
9190
emptyrows = setdiff(1:bm, browIs)
9291
emptycols = setdiff(1:bn, bcolIs)
9392
for (row, col) in zip(emptyrows, emptycols)
94-
rlengths[col] = brows[row]
93+
r_axes[col] = brows[row]
9594
end
9695
for (i, k) in enumerate((length(emptycols) + 1):length(emptyrows))
97-
rlengths[bn + i] = brows[emptyrows[k]]
96+
r_axes[bn + i] = brows[emptyrows[k]]
9897
end
9998

100-
r_axis = blockedrange(rlengths)
99+
r_axis = mortar_axis(r_axes)
101100
Q = similar(A, axes(A, 1), r_axis)
102101
R = similar(A, r_axis, axes(A, 2))
103102

0 commit comments

Comments
 (0)