Internal Documentation
Contents
Index
BlockArrays.BlockIndexRangeBlockArrays.BlockIndicesBlockArrays.BlockRangeBlockArrays.BlockSliceBlockArrays.BlockedOneToBlockArrays.BlockedUnitRangeBlockArrays.NoncontiguousBlockSliceBlockArrays.SubBlockIteratorBlockArrays.blockcheckbounds_indicesBlockArrays.blockcheckindexBlockArrays.unblock
Internals
BlockArrays.BlockedOneTo — TypeBlockedOneTo{T, <:Union{AbstractVector{T}, NTuple{<:Any,T}}} where {T}Define an AbstractUnitRange{T} that has been divided into blocks, which is used to represent axes of block arrays. This parallels Base.OneTo in that the first value is guaranteed to be 1.
Construction is typically via blockedrange which converts a vector of block lengths to a BlockedUnitRange.
Examples
julia> blockedrange([2,2,3]) # block lengths
3-blocked 7-element BlockedOneTo{Int64, Vector{Int64}}:
1
2
─
3
4
─
5
6
7See also BlockedUnitRange.
BlockArrays.BlockedUnitRange — TypeBlockedUnitRangeis an AbstractUnitRange{<:Integer} that has been divided into blocks. Construction is typically via blockedrange which converts a vector of block lengths to a BlockedUnitRange.
Examples
julia> blockedrange(2, [2,2,3]) # first value and block lengths
3-blocked 7-element BlockedUnitRange{Int64, Vector{Int64}}:
2
3
─
4
5
─
6
7
8See also BlockedOneTo.
BlockArrays.BlockRange — TypeBlockRange(axes::Tuple{Vararg{AbstractUnitRange{<:Integer}}})
BlockRange(sizes::Tuple{Vararg{Integer}})Represent a Cartesian range of blocks.
The relationship between Block and BlockRange mimics the relationship between CartesianIndex and CartesianIndices.
Examples
julia> BlockRange((2:3, 3:4)) |> collect
2×2 Matrix{Block{2, Int64}}:
Block(2, 3) Block(2, 4)
Block(3, 3) Block(3, 4)
julia> BlockRange((2, 2)) |> collect # number of elements, starting at 1
2×2 Matrix{Block{2, Int64}}:
Block(1, 1) Block(1, 2)
Block(2, 1) Block(2, 2)
julia> Block(1):Block(2)
BlockRange((1:2,))
julia> Block.(1:2)
BlockRange((1:2,))
julia> BlockRange((Block.(1:2), Block.(3:4)))
BlockRange((1:2, 3:4))BlockArrays.BlockIndexRange — TypeBlockIndexRange(block, startind:stopind)Represents a cartesian range inside a block. Type alias for BlockIndices with the indices constrained to ranges.
It can be constructed and used to index into BlockArrays in the following manner:
julia> BlockIndexRange(Block(1,2), (2:3,3:4))
Block(1, 2)[2:3, 3:4]
julia> Block(1)[2:3] === BlockIndexRange(Block(1), 2:3)
true
julia> Block(1,2)[2:3,3:4] === BlockIndexRange(Block(1,2), (2:3,3:4))
true
julia> BlockIndexRange((Block(1)[2:3], Block(2)[3:4]))
Block(1, 2)[2:3, 3:4]
julia> arr = Array(reshape(1:25, (5,5)));
julia> a = BlockedArray(arr, [3,2], [1,4])
2×2-blocked 5×5 BlockedMatrix{Int64}:
1 │ 6 11 16 21
2 │ 7 12 17 22
3 │ 8 13 18 23
───┼────────────────
4 │ 9 14 19 24
5 │ 10 15 20 25
julia> a[Block(1,2)[1:2,2:3]]
2×2 Matrix{Int64}:
11 16
12 17
julia> a[Block(2,2)[1:2,3:4]]
2×2 Matrix{Int64}:
19 24
20 25BlockArrays.BlockIndices — TypeBlockIndices(block, startind:stopind)Represents a cartesian product of indices inside a block. It can be constructed and used to index into BlockArrays in the following manner:
julia> BlockIndices(Block(1,2), ([1,3],[2,4]))
Block(1, 2)[[1, 3], [2, 4]]
julia> Block(1)[[1,3]] == BlockIndices(Block(1), [1,3])
true
julia> Block(1,2)[[1,3],[2,4]] == BlockIndices(Block(1,2), ([1,3],[2,4]))
true
julia> BlockIndices((Block(1)[[1,3]], Block(2)[[2,4]]))
Block(1, 2)[[1, 3], [2, 4]]
julia> arr = Array(reshape(1:25, (5,5)));
julia> a = BlockedArray(arr, [3,2], [1,4])
2×2-blocked 5×5 BlockedMatrix{Int64}:
1 │ 6 11 16 21
2 │ 7 12 17 22
3 │ 8 13 18 23
───┼────────────────
4 │ 9 14 19 24
5 │ 10 15 20 25
julia> a[Block(1,2)[[1,3],[2,4]]]
2×2 Matrix{Int64}:
11 21
13 23
julia> a[Block(2,2)[[2],[2,4]]]
1×2 Matrix{Int64}:
15 25BlockArrays.BlockSlice — TypeBlockSlice(block, indices)Represents an AbstractUnitRange{<:Integer} of indices attached to a block, a subblock, or a range of blocks.
Upon calling to_indices(), Blocks are converted to BlockSlice objects to represent the indices over which the block, subblock, or range of blocks spans.
This mimics the relationship between Colon and Base.Slice.
BlockArrays.NoncontiguousBlockSlice — TypeNoncontiguousBlockSlice(blocks, indices)Represents an AbstractVector of indices attached to a (potentially non-contiguous) subblock, set of blocks, or set of subblocks. This is the generalization of BlockSlice to non-contiguous slices.
Upon calling to_indices(), a collection of blocks are converted to NoncontiguousBlockSlice objects to represent the indices over which the blocks span.
This mimics the relationship between Colon and Base.Slice, Block and BlockSlice, etc.
BlockArrays.unblock — Functionunblock(block_sizes, inds, I)Returns the indices associated with a block as a BlockSlice.
BlockArrays.SubBlockIterator — TypeSubBlockIterator(subblock_lasts::Vector{Int}, block_lasts::Vector{Int})
SubBlockIterator(A::AbstractArray, bs::NTuple{N,AbstractUnitRange{Int}} where N, dim::Integer)Return an iterator over the BlockIndexRanges of the blocks specified by subblock_lasts. The Block index part of BlockIndexRange is determined by subblock_lasts. That is to say, the Block index first specifies one of the block represented by subblock_lasts and then the inner-block index range specifies the region within the block. Each such block corresponds to a block specified by blocklasts.
Note that the invariance subblock_lasts ⊂ block_lasts must hold and must be ensured by the caller.
Examples
julia> using BlockArrays
julia> import BlockArrays: SubBlockIterator
julia> A = BlockArray(1:6, 1:3);
julia> subblock_lasts = blocklasts(axes(A, 1))
3-element ArrayLayouts.RangeCumsum{Int64, UnitRange{Int64}}:
1
3
6
julia> block_lasts = [1, 3, 4, 6];
julia> itr = SubBlockIterator(subblock_lasts, block_lasts)
SubBlockIterator([1, 3, 6], [1, 3, 4, 6])
julia> collect(itr)
4-element Vector{BlockIndexRange{1, Tuple{UnitRange{Int64}}, Tuple{Int64}, Int64}}:
Block(1)[1:1]
Block(2)[1:2]
Block(3)[1:1]
Block(3)[2:3]BlockArrays.blockcheckbounds_indices — Functionblockcheckbounds_indices(Bool, IA::Tuple{Vararg{BlockRange{1}}}, I::Tuple)Return true if the "requested" indices in the tuple map(i -> Block.(i), I) fall within the bounds of the "permitted" indices specified by the tuple IA. This function recursively consumes elements of these tuples in a 1-for-1 fashion.
The actual bounds-checking is performed by blockcheckindex.
Examples
julia> B = BlockArray(zeros(6,6), 1:3, 1:3);
julia> blockaxes(B)
(BlockRange((3,)), BlockRange((3,)))
julia> BlockArrays.blockcheckbounds_indices(Bool, blockaxes(B), (1,2))
true
julia> BlockArrays.blockcheckbounds_indices(Bool, blockaxes(B), (4,1))
false
julia> BlockArrays.blockcheckbounds_indices(Bool, blockaxes(B), (1:2,2:3))
true
julia> BlockArrays.blockcheckbounds_indices(Bool, blockaxes(B), (1:2,2:4))
falseBlockArrays.blockcheckindex — Functionblockcheckindex(Bool, inds::BlockRange{1}, index)Return true if Block.(index) is within the bounds of inds.
Examples
julia> BlockArrays.blockcheckindex(Bool, BlockRange((1:2,)), 1)
true
julia> BlockArrays.blockcheckindex(Bool, BlockRange((1:2,)), 3)
false
julia> BlockArrays.blockcheckindex(Bool, BlockRange((1:3,)), 2:3)
true
julia> BlockArrays.blockcheckindex(Bool, BlockRange((1:3,)), 2:4)
false