Skip to content

Commit 8266129

Browse files
JeffFesslerdkarrasch
authored andcommitted
Fix index in BlockMap adjoint/transpose multiply (#59)
1 parent a024a4d commit 8266129

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/blockmap.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,19 @@ function At_mul_B!(y::AbstractVector, A::BlockMap, x::AbstractVector)
244244
@boundscheck (n == length(y) && m == length(x)) || throw(DimensionMismatch("At_mul_B!"))
245245
maps, rows, xinds, yinds = A.maps, A.rows, A.rowranges, A.colranges
246246
mapind = 0
247-
# first block row (rowind = 1), fill all of y
247+
# first block row (rowind = 1) of A, meaning first block column of A', fill all of y
248248
@views @inbounds begin
249249
xcol = x[xinds[1]]
250250
for colind in 1:rows[1]
251251
mapind +=1
252-
A_mul_B!(y[yinds[colind]], transpose(maps[mapind]), xcol)
252+
A_mul_B!(y[yinds[mapind]], transpose(maps[mapind]), xcol)
253253
end
254-
# subsequent block rows, add results to corresponding parts of y
254+
# subsequent block rows of A, add results to corresponding parts of y
255255
for rowind in 2:length(rows)
256256
xcol = x[xinds[rowind]]
257257
for colind in 1:rows[rowind]
258258
mapind +=1
259-
mul!(y[yinds[colind]], transpose(maps[mapind]), xcol, true, true)
259+
mul!(y[yinds[mapind]], transpose(maps[mapind]), xcol, true, true)
260260
end
261261
end
262262
end
@@ -268,19 +268,19 @@ function Ac_mul_B!(y::AbstractVector, A::BlockMap, x::AbstractVector)
268268
@boundscheck (n == length(y) && m == length(x)) || throw(DimensionMismatch("At_mul_B!"))
269269
maps, rows, xinds, yinds = A.maps, A.rows, A.rowranges, A.colranges
270270
mapind = 0
271-
# first block row (rowind = 1), fill all of y
271+
# first block row (rowind = 1) of A, fill all of y
272272
@views @inbounds begin
273273
xcol = x[xinds[1]]
274274
for colind in 1:rows[1]
275275
mapind +=1
276-
A_mul_B!(y[yinds[colind]], adjoint(maps[mapind]), xcol)
276+
A_mul_B!(y[yinds[mapind]], adjoint(maps[mapind]), xcol)
277277
end
278-
# subsequent block rows, add results to corresponding parts of y
278+
# subsequent block rows of A, add results to corresponding parts of y
279279
for rowind in 2:length(rows)
280280
xcol = x[xinds[rowind]]
281281
for colind in 1:rows[rowind]
282282
mapind +=1
283-
mul!(y[yinds[colind]], adjoint(maps[mapind]), xcol, true, true)
283+
mul!(y[yinds[mapind]], adjoint(maps[mapind]), xcol, true, true)
284284
end
285285
end
286286
end

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,16 @@ end
546546
@test_throws DimensionMismatch A = [I A21; A12 I]
547547
@test_throws DimensionMismatch A = [A12 A12; A21 A21]
548548
@test_throws DimensionMismatch A = [A12 A21; A12 A21]
549+
550+
# basic test of "misaligned" blocks
551+
M = ones(elty, 3, 2) # non-square
552+
A = LinearMap(M)
553+
B = [I A; A I]
554+
C = [I M; M I]
555+
@test B isa LinearMaps.BlockMap{elty}
556+
@test Matrix(B) == C
557+
@test Matrix(transpose(B)) == transpose(C)
558+
@test Matrix(adjoint(B)) == C'
549559
end
550560
end
551561
@testset "adjoint/transpose" begin

0 commit comments

Comments
 (0)