Skip to content

Commit 6dcd1f7

Browse files
authored
a[:,Block.(1:0)] is now empty (#305)
1 parent a3261ff commit 6dcd1f7

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Project.toml

+1-1
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.37"
3+
version = "0.16.38"
44

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

src/views.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ function unblock(A, inds, I)
1111
end
1212
# Allow `ones(2)[Block(1)[1:1], Block(1)[1:1]]` which is
1313
# similar to `ones(2)[1:1, 1:1]`.
14-
unblock(A, ::Tuple{}, I) = BlockSlice(first(I),Base.OneTo(1))
14+
# Need to check the length of I in case its empty
15+
unblock(A, ::Tuple{}, I) = BlockSlice(first(I),Base.OneTo(length(I[1])))
1516

1617
to_index(::Block) = throw(ArgumentError("Block must be converted by to_indices(...)"))
1718
to_index(::BlockIndex) = throw(ArgumentError("BlockIndex must be converted by to_indices(...)"))

test/test_blockarrays.jl

+8
Original file line numberDiff line numberDiff line change
@@ -700,4 +700,12 @@ end
700700
c = resize!(b,Block(0))
701701
@test isempty(c)
702702
end
703+
704+
@testset "empty indexing of vectors" begin
705+
a = mortar([1:3, 2:6])
706+
@test size(a[:,Block.(1:0)]) == size(PseudoBlockVector(a)[:,Block.(1:0)]) == (8,0)
707+
@test size(a[:,Block.(1:1)]) == size(PseudoBlockVector(a)[:,Block.(1:1)]) == size(a[:,Block(1)]) == (8,1)
708+
@test_throws BoundsError a[:,Block.(1:2)]
709+
@test size(a[:,1]) == (8,)
710+
end
703711
end

0 commit comments

Comments
 (0)