Skip to content
Draft
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
10 changes: 10 additions & 0 deletions src/abstractblockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
"""
@inline blockcheckindex(::Type{Bool}, inds::BlockRange{1}, i::Integer) = Block(i) in inds

"""
to_blockindex(A::AbstractArray{T,N}, I::Tuple{Vararg{Integer,N}})

Returns the [`BlockIndex`](@ref) of `A[I...]`.
"""
function to_blockindex(A::AbstractArray{T,N}, I::Tuple{Vararg{Integer,N}}) where {T,N}
blockinds = _to_blockindex.(axes(A), I)
BlockIndex(map(first,blockinds), map(last,blockinds))

Check warning on line 167 in src/abstractblockarray.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractblockarray.jl#L165-L167

Added lines #L165 - L167 were not covered by tests
end

@propagate_inbounds setindex!(block_arr::AbstractBlockArray{T,N}, v, block::Block{N}) where {T,N} =
setindex!(block_arr, v, Block.(block.n)...)
@propagate_inbounds function setindex!(block_arr::AbstractBlockArray{T,N}, v, block::Vararg{Block{1}, N}) where {T,N}
Expand Down
12 changes: 12 additions & 0 deletions src/blockaxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@
@inline blockedrange(blocks::Union{Tuple,AbstractVector}) = BlockedOneTo(_blocklengths2blocklasts(blocks))
@inline blockedrange(f::Integer, blocks::Union{Tuple,AbstractVector}) = _BlockedUnitRange(f, f-oneunit(f) .+ _blocklengths2blocklasts(blocks))

to_blockindex(b::BlockedUnitRange, k::Integer) = BlockIndex(_to_blockindex(b,k)...)
function _to_blockindex(b::BlockedUnitRange, k::Integer)
if isone(b.first)
bl = blocklasts(b)
prevblocklast = k == firstindex(bl) ? first(b)-1 : bl[k-1]
local_index = k - prevblocklast
(k, local_index)

Check warning on line 193 in src/blockaxis.jl

View check run for this annotation

Codecov / codecov/patch

src/blockaxis.jl#L187-L193

Added lines #L187 - L193 were not covered by tests
else
_to_blockindex(axes(b,1), k)

Check warning on line 195 in src/blockaxis.jl

View check run for this annotation

Codecov / codecov/patch

src/blockaxis.jl#L195

Added line #L195 was not covered by tests
end
end

_diff(a::AbstractVector) = diff(a)
_diff(a::Tuple) = diff(collect(a))
@inline _blocklengths(a, bl, dbl) = isempty(bl) ? [dbl;] : [first(bl)-first(a)+oneunit(eltype(a)); dbl]
Expand Down