Skip to content

Commit f57169b

Browse files
committed
Fix indexing with adjoints of block vectors
1 parent 02f4cb5 commit f57169b

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.16.12"
3+
version = "0.16.13"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/abstractblockarray.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ end
106106
@inbounds _i = i[idx]
107107
Block(_i) in n[k] || return false
108108
end
109+
for idx = N+1:length(i)
110+
isone(i[idx]) || return false
111+
end
109112
return true
110113
end
111114

src/views.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,26 @@ _block_reindex(b::Slice, i::Block{1}) = i
148148

149149

150150

151-
function Base.view(A::Adjoint{<:Any,<:BlockArray}, b::Block{2})
151+
function Base.view(A::Adjoint{<:Any,<:BlockMatrix}, b::Block{2})
152152
k, j = b.n
153153
view(parent(A), Block(j), Block(k))'
154154
end
155-
function Base.view(A::Transpose{<:Any,<:BlockArray}, b::Block{2})
155+
function Base.view(A::Transpose{<:Any,<:BlockMatrix}, b::Block{2})
156156
k, j = b.n
157157
transpose(view(parent(A), Block(j), Block(k)))
158158
end
159159

160+
function Base.view(A::Adjoint{<:Any,<:BlockVector}, b::Block{2})
161+
@boundscheck blockcheckbounds(A, b)
162+
k, j = b.n
163+
view(parent(A), Block(j))'
164+
end
165+
function Base.view(A::Transpose{<:Any,<:BlockVector}, b::Block{2})
166+
@boundscheck blockcheckbounds(A, b)
167+
k, j = b.n
168+
transpose(view(parent(A), Block(j)))
169+
end
170+
160171
Base.view(A::AdjOrTrans{<:Any,<:BlockArray}, K::Block{1}, J::Block{1}) = view(A, Block(Int(K), Int(J)))
161172

162173
@propagate_inbounds getindex(v::LinearAlgebra.AdjOrTransAbsVec, ::Colon, is::AbstractArray{<:Block{1}}) = LinearAlgebra.wrapperop(v)(v.parent[is])

test/test_blockviews.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,18 @@ bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
291291
v = bview(a,Block(1))
292292
@test view(a, parentindices(v)...) 7:9
293293
end
294+
295+
@testset "BlockVector' view" begin
296+
v = BlockArray(randn(3),1:2)
297+
@test view(v',Block(1,2)) === view(v,Block(2))'
298+
@test view(transpose(v),Block(1,2)) === transpose(view(v,Block(2)))
299+
300+
@test_throws BlockBoundsError v'[Block(2,2)]
301+
@test_throws BlockBoundsError transpose(v)[Block(2,2)]
302+
end
303+
304+
@testset "array indexing past ndims" begin
305+
v = BlockArray(randn(3),1:2)
306+
@test_broken @test_throws BlockBoundsError v[Block(1,2)]
307+
end
294308
end

0 commit comments

Comments
 (0)