Skip to content

Commit c825701

Browse files
authored
blocklengths when empty (#182)
* blocklengths when empty * add tests * Update blockaxis.jl * v0.16.5
1 parent 60b95f0 commit c825701

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
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.4"
3+
version = "0.16.5"
44

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

src/blockaxis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ _blocklengths2blocklasts(blocks) = cumsum(blocks) # extra level to allow changin
6060

6161
_diff(a::AbstractVector) = diff(a)
6262
_diff(a::Tuple) = diff(collect(a))
63-
@inline blocklengths(a::BlockedUnitRange) = [first(a.lasts)-a.first+1; _diff(a.lasts)]
63+
@inline blocklengths(a::BlockedUnitRange) = isempty(a.lasts) ? _diff(a.lasts) : [first(a.lasts)-a.first+1; _diff(a.lasts)]
6464

6565
length(a::BlockedUnitRange) = isempty(a.lasts) ? 0 : Integer(last(a.lasts)-a.first+1)
6666

test/test_blockarrays.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,9 @@ end
555555
@test (a')[:,Block.(1:2)] isa Adjoint
556556
@test transpose(a)[:,Block.(1:2)] isa Transpose
557557
end
558+
559+
@testset "empty blocklengths" begin
560+
A = BlockVector{Float64}(undef,Int[])
561+
@test @inferred(isempty(blocklengths(axes(A,1))))
562+
end
558563
end

0 commit comments

Comments
 (0)