Skip to content

Commit b55c7a4

Browse files
authored
Generalize more functions to non-Int64 ranges (#455)
1 parent 83d8c3e commit b55c7a4

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
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.5.0"
3+
version = "1.6.0"
44

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

src/blockaxis.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ end
101101
return (first(a), (blocklasts(a)[oneto(end-1)] .+ oneunit(eltype(a)))...)
102102
end
103103

104+
function Base.AbstractUnitRange{T}(r::BlockedUnitRange) where {T}
105+
return _BlockedUnitRange(convert(T,first(r)), convert.(T,blocklasts(r)))
106+
end
107+
104108
"""
105109
BlockedOneTo{T, <:Union{AbstractVector{T}, NTuple{<:Any,T}}} where {T}
106110
@@ -156,6 +160,10 @@ BlockedOneTo(::BlockedOneTo) = throw(ArgumentError("Forbidden due to ambiguity")
156160

157161
axes(b::BlockedOneTo) = (b,)
158162

163+
function Base.AbstractUnitRange{T}(r::BlockedOneTo) where {T}
164+
return BlockedOneTo(convert.(T,blocklasts(r)))
165+
end
166+
159167
"""
160168
blockedrange(blocklengths::Union{Tuple, AbstractVector})
161169
blockedrange(first::Integer, blocklengths::Union{Tuple, AbstractVector})

src/blockbroadcast.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Base.eltype(::Type{<:SubBlockIterator}) = BlockIndexRange{1,Tuple{UnitRange{Int}
100100
Base.IteratorSize(::Type{<:SubBlockIterator}) = Base.HasLength()
101101
Base.length(it::SubBlockIterator) = length(it.block_lasts)
102102

103-
SubBlockIterator(arr::AbstractArray, bs::NTuple{N,AbstractUnitRange{Int}}, dim::Integer) where N =
103+
SubBlockIterator(arr::AbstractArray, bs::Tuple{Vararg{AbstractUnitRange{<:Integer}}}, dim::Integer) =
104104
SubBlockIterator(blocklasts(axes(arr, dim)), blocklasts(bs[dim]))
105105

106106
function Base.iterate(it::SubBlockIterator, (i, j) = (1,1))
@@ -113,10 +113,10 @@ function Base.iterate(it::SubBlockIterator, (i, j) = (1,1))
113113
return (bir, (i + 1, j))
114114
end
115115

116-
subblocks(::Any, bs::NTuple{N,AbstractUnitRange{Int}}, dim::Integer) where N =
116+
subblocks(::Any, bs::Tuple{Vararg{AbstractUnitRange{<:Integer}}}, dim::Integer) =
117117
(nothing for _ in blockaxes(bs[dim], 1))
118118

119-
function subblocks(arr::AbstractArray, bs::NTuple{N,AbstractUnitRange{Int}}, dim::Integer) where N
119+
function subblocks(arr::AbstractArray, bs::Tuple{Vararg{AbstractUnitRange{<:Integer}}}, dim::Integer)
120120
return SubBlockIterator(arr, bs, dim)
121121
end
122122

test/test_blockrange.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ using BlockArrays, Test
7373
@test BlockRange(1:3) == collect(BlockRange(1:3)) == [Block(1),Block(2),Block(3)]
7474
@test BlockRange(1:3,1:2) == collect(BlockRange(1:3,1:2))
7575
end
76+
77+
# non Int64 range
78+
r = blockedrange([Int32(1)])
79+
@test convert(AbstractUnitRange{Int64}, r) isa BlockedOneTo{Int64}
80+
v = mortar([[1]], (r,))
81+
@test Int.(v) == v
82+
83+
r = blockedrange([Int32(1)])[Block(1):Block(1)]
84+
@test convert(AbstractUnitRange{Int64}, r) isa BlockedUnitRange{Int64}
85+
v = mortar([[1]], (r,))
86+
@test Int.(v) == v
7687
end
7788

7889
@testset "block index range" begin

0 commit comments

Comments
 (0)