Skip to content

Commit 627f67d

Browse files
committed
Preserve block information in more slicing operations
1 parent 4059149 commit 627f67d

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-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 = "1.6.2"
3+
version = "1.7.0"
44

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

src/blockindices.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ _indices(B) = B
288288

289289
Block(bs::BlockSlice{<:BlockIndexRange}) = Block(bs.block)
290290

291+
struct BlockInds{BB,T<:Integer,INDS<:AbstractVector{T}} <: AbstractVector{T}
292+
block::BB
293+
indices::INDS
294+
end
295+
296+
for f in (:axes, :size)
297+
@eval $f(S::BlockInds) = $f(S.indices)
298+
end
299+
300+
@propagate_inbounds getindex(S::BlockInds, i::Integer) = getindex(S.indices, i)
291301

292302
struct BlockRange{N,R<:NTuple{N,AbstractUnitRange{<:Integer}}} <: AbstractArray{Block{N,Int},N}
293303
indices::R

src/views.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function unblock(A, inds, I)
1111
end
1212

1313
_blockslice(B, a::AbstractUnitRange) = BlockSlice(B, a)
14-
_blockslice(B, a) = a # drop block structure
14+
_blockslice(B, a) = BlockInds(B, a)
1515

1616
# Allow `ones(2)[Block(1)[1:1], Block(1)[1:1]]` which is
1717
# similar to `ones(2)[1:1, 1:1]`.

0 commit comments

Comments
 (0)