Skip to content

Commit 28a5c27

Browse files
authored
Accept Integers in BlockRange (#276)
1 parent 99aadf4 commit 28a5c27

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/BlockArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Base: @propagate_inbounds, Array, to_indices, to_index,
2929
+, -, *, /, \, min, max, isless, in, copy, copyto!, axes, @deprecate,
3030
BroadcastStyle, checkbounds, throw_boundserror,
3131
oneunit, ones, zeros, intersect, Slice, resize!
32-
using Base: ReshapedArray, dataids
32+
using Base: ReshapedArray, dataids, oneto
3333
import Base: AbstractArray
3434

3535
_maybetail(::Tuple{}) = ()

src/blockindices.jl

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,31 @@ end
311311

312312
# deleted code that isn't used, such as 0-dimensional case
313313
"""
314-
BlockRange(startblock, stopblock)
314+
BlockRange(axes::Tuple{AbstractUnitRange{Int}})
315+
BlockRange(sizes::Vararg{Integer})
315316
316-
represents a cartesian range of blocks.
317+
Represent a Cartesian range of blocks.
317318
318319
The relationship between `Block` and `BlockRange` mimics the relationship between
319-
`CartesianIndex` and `CartesianRange`.
320+
`CartesianIndex` and `CartesianIndices`.
321+
322+
# Examples
323+
```jldoctest
324+
julia> BlockRange(2,2)
325+
2×2 BlockRange{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}:
326+
Block(1, 1) Block(1, 2)
327+
Block(2, 1) Block(2, 2)
328+
329+
julia> BlockRange(2:3, 3:4)
330+
2×2 BlockRange{2, Tuple{UnitRange{Int64}, UnitRange{Int64}}}:
331+
Block(2, 3) Block(2, 4)
332+
Block(3, 3) Block(3, 4)
333+
334+
julia> Block(1):Block(2)
335+
2-element BlockRange{1, Tuple{UnitRange{Int64}}}:
336+
Block(1)
337+
Block(2)
338+
```
320339
"""
321340
BlockRange
322341

@@ -326,8 +345,8 @@ BlockRange(inds::Vararg{AbstractUnitRange{Int},N}) where {N} =
326345
BlockRange(inds)
327346

328347
BlockRange() = BlockRange(())
329-
BlockRange(sizes::Tuple{Int, Vararg{Int}}) = BlockRange(map(Base.OneTo, sizes))
330-
BlockRange(sizes::Vararg{Int}) = BlockRange(sizes)
348+
BlockRange(sizes::Tuple{Integer, Vararg{Integer}}) = BlockRange(map(oneto, sizes))
349+
BlockRange(sizes::Vararg{Integer}) = BlockRange(sizes)
331350

332351
(:)(start::Block{1}, stop::Block{1}) = BlockRange((first(start.n):first(stop.n),))
333352
(:)(start::Block, stop::Block) = throw(ArgumentError("Use `BlockRange` to construct a cartesian range of blocks"))

0 commit comments

Comments
 (0)