Skip to content

Commit 7b83868

Browse files
authored
BlockRange for AbstractArrays (#292)
1 parent 8283337 commit 7b83868

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

src/abstractblockarray.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ Base.similar(::Type{<:AbstractBlockArray{T,N}}, dims::Dims) where {T,N} = simila
4343
@inline size(block_array::AbstractBlockArray) = map(length, axes(block_array))
4444
@noinline axes(block_array::AbstractBlockArray) = throw(ArgumentError("axes for $(typeof(block_array)) is not implemented"))
4545

46-
BlockRange(B::AbstractBlockArray) = BlockRange(blockaxes(B))
47-
4846
"""
4947
BlockBoundsError([A], [inds...])
5048

src/blockindices.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ BlockRange() = BlockRange(())
353353
BlockRange(sizes::Tuple{Integer, Vararg{Integer}}) = BlockRange(map(oneto, sizes))
354354
BlockRange(sizes::Vararg{Integer}) = BlockRange(sizes)
355355

356+
BlockRange(B::AbstractArray) = BlockRange(blockaxes(B))
357+
356358
(:)(start::Block{1}, stop::Block{1}) = BlockRange((first(start.n):first(stop.n),))
357359
(:)(start::Block, stop::Block) = throw(ArgumentError("Use `BlockRange` to construct a cartesian range of blocks"))
358360
broadcasted(::DefaultArrayStyle{1}, ::Type{Block}, r::AbstractUnitRange) = BlockRange((r,))

src/pseudo_blockarray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ end
209209
# Misc #
210210
########
211211

212+
Base.parent(block_array::PseudoBlockArray) = block_array.blocks
213+
212214
Base.Array(block_array::PseudoBlockArray) = Array(block_array.blocks)
213215

214216
function copyto!(block_array::PseudoBlockArray{T, N, R}, arr::R) where {T,N,R <: AbstractArray}

test/test_blockviews.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
6161

6262
@test view(V, Block(1, 1)) V
6363

64+
B = view(parent(A), axes(A)...)
65+
for I in BlockRange(A)
66+
@test view(B, I) == view(A, I)
67+
end
68+
6469
@test_throws BlockBoundsError view(V, Block(1,2))
6570
@test_throws BlockBoundsError view(V, Block(2,1))
6671

0 commit comments

Comments
 (0)