Skip to content

Commit 2a967b0

Browse files
committed
indices1 -> axes1
new iteration
1 parent 02734a5 commit 2a967b0

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

src/BlockArrays.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export PseudoBlockArray, PseudoBlockMatrix, PseudoBlockVector, PseudoBlockVecOrM
1818
export undef_blocks, undef
1919

2020
import Base: @propagate_inbounds, Array, to_indices, to_index, indices,
21-
unsafe_indices, indices1, first, last, size, length, unsafe_length,
21+
unsafe_indices, first, last, size, length, unsafe_length,
2222
unsafe_convert,
23-
getindex, show, start, next, done,
23+
getindex, show,
2424
broadcast, eltype, convert, broadcast,
2525
@_inline_meta, _maybetail, tail, @_propagate_inbounds_meta, reindex,
2626
RangeIndex, Int, Integer, Number,
@@ -29,10 +29,11 @@ import Base: @propagate_inbounds, Array, to_indices, to_index, indices,
2929
import Compat: copyto!, axes
3030

3131
if VERSION < v"0.7-"
32-
import Base: colon, iteratorsize
32+
import Base: colon, iteratorsize, indices1, start, next, done
3333
const parentindices = parentindexes
34+
const axes1 = indices1
3435
else
35-
import Base: (:), IteratorSize, iterate
36+
import Base: (:), IteratorSize, iterate, axes1
3637
import Base.Broadcast: broadcasted, DefaultArrayStyle
3738
end
3839

src/blockindexrange.jl

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,32 @@ end
2929
first(iter::BlockIndexRange) = BlockIndex(iter.block.n, map(first, iter.indices))
3030
last(iter::BlockIndexRange) = BlockIndex(iter.block.n, map(last, iter.indices))
3131

32-
33-
@inline function start(iter::BlockIndexRange)
34-
iterfirst, iterlast = first(iter), last(iter)
35-
if any(map(>, iterfirst.α, iterlast.α))
36-
return BlockIndex(iterlast.I, iterlast.α .+ 1)
32+
if VERSION < v"0.7-"
33+
@inline function start(iter::BlockIndexRange)
34+
iterfirst, iterlast = first(iter), last(iter)
35+
if any(map(>, iterfirst.α, iterlast.α))
36+
return BlockIndex(iterlast.I, iterlast.α .+ 1)
37+
end
38+
iterfirst
39+
end
40+
@inline function next(iter::BlockIndexRange, state)
41+
state, BlockIndex(state.I, inc(state.α, first(iter).α, last(iter).α))
42+
end
43+
@inline done(iter::BlockIndexRange, state) = state.α[end] > last(iter.indices[end])
44+
else
45+
@inline function iterate(iter::BlockIndexRange)
46+
iterfirst, iterlast = first(iter), last(iter)
47+
if any(map(>, iterfirst.α, iterlast.α))
48+
return nothing
49+
end
50+
iterfirst, iterfirst
51+
end
52+
@inline function iterate(iter::BlockIndexRange, state)
53+
nextstate = BlockIndex(state.I, inc(state.α, first(iter).α, last(iter).α))
54+
nextstate.α[end] > last(iter.indices[end]) && return nothing
55+
nextstate, nextstate
3756
end
38-
iterfirst
39-
end
40-
@inline function next(iter::BlockIndexRange, state)
41-
state, BlockIndex(state.I, inc(state.α, first(iter).α, last(iter).α))
4257
end
43-
@inline done(iter::BlockIndexRange, state) = state.α[end] > last(iter.indices[end])
44-
4558
size(iter::BlockIndexRange) = map(dimlength, first(iter).α, last(iter).α)
4659
length(iter::BlockIndexRange) = prod(size(iter))
4760

src/blockrange.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ else
3838
end
3939

4040
# AbstractArray implementation
41-
axes(iter::BlockRange{N,R}) where {N,R} = map(Base.indices1, iter.indices)
41+
axes(iter::BlockRange{N,R}) where {N,R} = map(axes1, iter.indices)
4242
Base.IndexStyle(::Type{BlockRange{N,R}}) where {N,R} = IndexCartesian()
4343
@inline function Base.getindex(iter::BlockRange{N,<:NTuple{N,Base.OneTo}}, I::Vararg{Int, N}) where {N}
4444
@boundscheck checkbounds(iter, I...)
4545
Block(I)
4646
end
4747
@inline function Base.getindex(iter::BlockRange{N,R}, I::Vararg{Int, N}) where {N,R}
4848
@boundscheck checkbounds(iter, I...)
49-
Block(I .- first.(Base.indices1.(iter.indices)) .+ first.(iter.indices))
49+
Block(I .- first.(axes1.(iter.indices)) .+ first.(iter.indices))
5050
end
5151

5252

src/views.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616
Block(bs::BlockSlice{<:Block}) = bs.block
1717

1818

19-
for f in (:axes, :unsafe_indices, :indices1, :first, :last, :size, :length,
19+
for f in (:axes, :unsafe_indices, :axes1, :first, :last, :size, :length,
2020
:unsafe_length, :start)
2121
@eval $f(S::BlockSlice) = $f(S.indices)
2222
end

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
using BlockArrays, Compat, Compat.Test
1+
using BlockArrays, Compat.LinearAlgebra, Compat, Compat.Test
22

33
if VERSION < v"0.7-"
44
const parentindices = parentindexes
5+
const axes1 = Base.indices1
6+
else
7+
import Base: axes1
58
end
69

710
include("test_blockindices.jl")

test/test_blockviews.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@test step(b) == 1
1212
@test Base.unsafe_length(b) == 2
1313
@test Compat.axes(b) == (Base.OneTo(2),)
14-
@test Base.indices1(b) == Base.OneTo(2)
14+
@test axes1(b) == Base.OneTo(2)
1515
@test Base.unsafe_indices(b) == (Base.OneTo(2),)
1616
@test size(b) == (2,)
1717
@test collect(b) == [2,3]
@@ -112,5 +112,5 @@ end
112112
@testset "block indx range of block range" begin
113113
A = PseudoBlockArray(collect(1:6), 1:3)
114114
V = view(A, Block.(2:3))
115-
@test view(V, Block(2)[1:2]) == [4,5]
115+
@test view(V, Block(2)[1:2]) == [4,5]
116116
end

0 commit comments

Comments
 (0)