Skip to content

Commit c775e52

Browse files
authored
Fix views involving BlockIndex{N} (#478)
Fixes #442.
1 parent 562fb53 commit c775e52

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/views.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ to_index(::BlockRange) = throw(ArgumentError("BlockRange must be converted by to
5353

5454
# In 0.7, we need to override to_indices to avoid calling linearindices
5555
@inline to_indices(A, I::Tuple{BlockIndexRange, Vararg{Any}}) = to_indices(A, axes(A), I)
56+
@inline to_indices(A, I::Tuple{BlockIndex, Vararg{Any}}) = to_indices(A, axes(A), I)
5657
@inline to_indices(A, I::Tuple{Block, Vararg{Any}}) = to_indices(A, axes(A), I)
5758
@inline to_indices(A, I::Tuple{BlockRange, Vararg{Any}}) = to_indices(A, axes(A), I)
5859
@inline to_indices(A, I::Tuple{AbstractVector{<:Block{1}}, Vararg{Any}}) = to_indices(A, axes(A), I)

test/test_blockarrays.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,9 +961,12 @@ end
961961
@testset "Blockindex" begin
962962
a = BlockedArray(randn(3), [1,2])
963963
@test a[Block(1)[1]] == a[1]
964+
@test view(a, Block(1)[1]) view(a, 1)
964965
@test a[Block(1)[1:1]] == a[1:1]
965966
A = BlockedArray(randn(3,3), [1,2], [1,2])
966967
@test A[Block(1)[1], Block(1)[1]] == A[Block(1,1)[1,1]] == A[1,1]
968+
# Regression test for #442
969+
@test view(A, Block(1)[1], Block(1)[1]) view(A, Block(1,1)[1,1]) view(A, 1, 1)
967970
@test A[Block(1)[1:1], Block(1)[1:1]] == A[Block(1,1)[1:1,1:1]] == A[1:1,1:1]
968971
@test A[Block(1)[1:1], Block(1)[1]] == BlockArray(A)[Block(1)[1:1], Block(1)[1]] == A[1:1,1]
969972
@test A[Block(1)[1], Block(1)[1:1]] == BlockArray(A)[Block(1)[1], Block(1)[1:1]] == A[1,1:1]

0 commit comments

Comments
 (0)