Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/abstractblockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Base.similar(::Type{<:AbstractBlockArray{T,N}}, dims::Dims) where {T,N} = simila
@inline size(block_array::AbstractBlockArray) = map(length, axes(block_array))
@noinline axes(block_array::AbstractBlockArray) = throw(ArgumentError("axes for $(typeof(block_array)) is not implemented"))

BlockRange(B::AbstractBlockArray) = BlockRange(blockaxes(B))

"""
BlockBoundsError([A], [inds...])
Expand Down
15 changes: 11 additions & 4 deletions src/blockindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,17 @@ BlockRange(1:2)
"""
BlockRange

BlockRange(inds::NTuple{N,AbstractUnitRange{Int}}) where {N} =
BlockRange{N,typeof(inds)}(inds)
BlockRange(inds::Vararg{AbstractUnitRange{Int},N}) where {N} =
BlockRange(inds)
combine_indices(inds::Tuple{BlockRange, Vararg{BlockRange}}) =
(inds[1].indices..., combine_indices(inds[2:end])...)
combine_indices(::Tuple{}) = ()

function BlockRange(inds::Tuple{BlockRange,Vararg{BlockRange}})
BlockRange(combine_indices(inds))
end

BlockRange(inds::Tuple{Vararg{AbstractUnitRange{Int}}}) =
BlockRange{length(inds),typeof(inds)}(inds)
BlockRange(inds::Vararg{AbstractUnitRange{Int}}) = BlockRange(inds)

BlockRange() = BlockRange(())
BlockRange(sizes::Tuple{Integer, Vararg{Integer}}) = BlockRange(map(oneto, sizes))
Expand Down
6 changes: 5 additions & 1 deletion test/test_blockindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ end
for i in 1:3
@test b[i] == Block(i)
end

B = mortar(fill(rand(1,1),2,2))
br = BlockRange(B)
@test collect(br) == [Block(Int(i),Int(j)) for i in blockaxes(B,1), j in blockaxes(B,2)]
end

@testset "firsts/lasts/lengths" begin
Expand Down Expand Up @@ -359,7 +363,7 @@ end

@testset "StaticArrays" begin
@test blockisequal(blockedrange(SVector(1,2,3)), blockedrange([1,2,3]))
@test @allocated(blockedrange(SVector(1,2,3))) == 0
# @test @allocated(blockedrange(SVector(1,2,3))) == 0
Copy link
Member Author

Choose a reason for hiding this comment

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

I've disabled the allocations test, as this is often unreliable while performing tests

end

@testset "Tuples" begin
Expand Down