Skip to content

Commit

Permalink
a[:,Block.(1:0)] is now empty (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Aug 23, 2023
1 parent a3261ff commit 6dcd1f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockArrays"
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
version = "0.16.37"
version = "0.16.38"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
3 changes: 2 additions & 1 deletion src/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function unblock(A, inds, I)
end
# Allow `ones(2)[Block(1)[1:1], Block(1)[1:1]]` which is
# similar to `ones(2)[1:1, 1:1]`.
unblock(A, ::Tuple{}, I) = BlockSlice(first(I),Base.OneTo(1))
# Need to check the length of I in case its empty
unblock(A, ::Tuple{}, I) = BlockSlice(first(I),Base.OneTo(length(I[1])))

to_index(::Block) = throw(ArgumentError("Block must be converted by to_indices(...)"))
to_index(::BlockIndex) = throw(ArgumentError("BlockIndex must be converted by to_indices(...)"))
Expand Down
8 changes: 8 additions & 0 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,12 @@ end
c = resize!(b,Block(0))
@test isempty(c)
end

@testset "empty indexing of vectors" begin
a = mortar([1:3, 2:6])
@test size(a[:,Block.(1:0)]) == size(PseudoBlockVector(a)[:,Block.(1:0)]) == (8,0)
@test size(a[:,Block.(1:1)]) == size(PseudoBlockVector(a)[:,Block.(1:1)]) == size(a[:,Block(1)]) == (8,1)
@test_throws BoundsError a[:,Block.(1:2)]
@test size(a[:,1]) == (8,)
end
end

2 comments on commit 6dcd1f7

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90169

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.16.38 -m "<description of version>" 6dcd1f708d3a672fc99d71b31a557a6fa9ccb8ae
git push origin v0.16.38

Please sign in to comment.