Skip to content

Preserve block information in more slicing operations #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 = "1.6.2"
version = "1.7.0"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
10 changes: 10 additions & 0 deletions src/blockindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ _indices(B) = B

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

struct BlockInds{BB,T<:Integer,INDS<:AbstractVector{T}} <: AbstractVector{T}
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a docstring so I know what this is meant to do?

Copy link
Collaborator Author

@mtfishman mtfishman Apr 28, 2025

Choose a reason for hiding this comment

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

Can do. I was holding off doing "final touches" like that to get your reaction if this is something you want in the first place (and get feedback on the name).

Copy link
Member

Choose a reason for hiding this comment

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

I can't react to something I don't understand 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gotcha, I thought I described it in the first comment of the PR but I can add a docstring as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a docstring along with some tests, let me know if that helps to clarify the purpose of this object. I changed the name to BlockedSlice but I'm not so happy with that and again I'm open to suggestions.

block::BB
indices::INDS
end

for f in (:axes, :size)
@eval $f(S::BlockInds) = $f(S.indices)
end

@propagate_inbounds getindex(S::BlockInds, i::Integer) = getindex(S.indices, i)

struct BlockRange{N,R<:NTuple{N,AbstractUnitRange{<:Integer}}} <: AbstractArray{Block{N,Int},N}
indices::R
Expand Down
2 changes: 1 addition & 1 deletion src/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function unblock(A, inds, I)
end

_blockslice(B, a::AbstractUnitRange) = BlockSlice(B, a)
_blockslice(B, a) = a # drop block structure
_blockslice(B, a) = BlockInds(B, a)

# Allow `ones(2)[Block(1)[1:1], Block(1)[1:1]]` which is
# similar to `ones(2)[1:1, 1:1]`.
Expand Down
Loading