@@ -16,7 +16,7 @@ function findblockindex(b::AbstractVector, k::Integer)
16
16
bl = blocklasts (b)
17
17
blockidx = _searchsortedfirst (bl, k)
18
18
@assert blockindex != lastindex (bl) + 1 # guaranteed by the @boundscheck above
19
- prevblocklast = blockidx == firstindex (bl) ? first (b)- 1 : bl[blockidx- 1 ]
19
+ prevblocklast = blockidx == firstindex (bl) ? first (b)- oneunit ( eltype (b)) : bl[blockidx- 1 ]
20
20
local_index = k - prevblocklast
21
21
return BlockIndex (blockidx, local_index)
22
22
end
60
60
61
61
const DefaultBlockAxis = BlockedUnitRange{Int,Vector{Int}}
62
62
63
- @inline _BlockedUnitRange (cs:: AbstractVector ) = _BlockedUnitRange (one (eltype (cs)), cs)
64
- @inline _BlockedUnitRange (cs:: NTuple ) = _BlockedUnitRange (one (eltype (cs)), cs)
63
+ @inline _BlockedUnitRange (cs:: AbstractVector ) = _BlockedUnitRange (oneunit (eltype (cs)), cs)
64
+ @inline _BlockedUnitRange (cs:: NTuple ) = _BlockedUnitRange (oneunit (eltype (cs)), cs)
65
65
_BlockedUnitRange (cs:: Tuple ) = _BlockedUnitRange (promote (cs... ))
66
66
_BlockedUnitRange (f, cs:: Tuple ) = _BlockedUnitRange (f, promote (cs... ))
67
67
@@ -74,21 +74,21 @@ _blocklengths2blocklasts(blocks::Fill) = cumsum(blocks)
74
74
_blocklengths2blocklasts (blocks:: Ones ) = cumsum (blocks)
75
75
@inline blockedrange (blocks:: Union{Tuple,AbstractVector} ) = _BlockedUnitRange (_blocklengths2blocklasts (blocks))
76
76
77
- @inline blockfirsts (a:: BlockedUnitRange ) = [first (a); @views (blocklasts (a)[1 : end - 1 ]) .+ 1 ]
77
+ @inline blockfirsts (a:: BlockedUnitRange ) = [first (a); @views (blocklasts (a)[1 : end - 1 ]) .+ oneunit ( eltype (a)) ]
78
78
# optimize common cases
79
79
@inline function blockfirsts (a:: BlockedUnitRange{<:Union{Vector, RangeCumsum{<:Any, <:UnitRange}}} )
80
80
v = Vector {eltype(a)} (undef, length (blocklasts (a)))
81
81
v[1 ] = first (a)
82
- v[2 : end ] .= @views (blocklasts (a)[oneto (end - 1 )]) .+ 1
82
+ v[2 : end ] .= @views (blocklasts (a)[oneto (end - 1 )]) .+ oneunit ( eltype (a))
83
83
return v
84
84
end
85
85
@inline blocklasts (a:: BlockedUnitRange ) = a. lasts
86
86
87
87
_diff (a:: AbstractVector ) = diff (a)
88
88
_diff (a:: Tuple ) = diff (collect (a))
89
- @inline blocklengths (a:: BlockedUnitRange ) = isempty (blocklasts (a)) ? [_diff (blocklasts (a));] : [first (blocklasts (a))- first (a)+ one (eltype (a)); _diff (blocklasts (a))]
89
+ @inline blocklengths (a:: BlockedUnitRange ) = isempty (blocklasts (a)) ? [_diff (blocklasts (a));] : [first (blocklasts (a))- first (a)+ oneunit (eltype (a)); _diff (blocklasts (a))]
90
90
91
- length (a:: BlockedUnitRange ) = isempty (blocklasts (a)) ? zero (eltype (a)) : Integer (last (blocklasts (a))- first (a)+ one (eltype (a)))
91
+ length (a:: BlockedUnitRange ) = isempty (blocklasts (a)) ? zero (eltype (a)) : Integer (last (blocklasts (a))- first (a)+ oneunit (eltype (a)))
92
92
93
93
"""
94
94
blockisequal(a::AbstractUnitRange{Int}, b::AbstractUnitRange{Int})
@@ -257,11 +257,11 @@ julia> blocksizes(A,2)
257
257
blocksizes (A) = map (blocklengths, axes (A))
258
258
blocksizes (A,i) = blocklengths (axes (A,i))
259
259
260
- axes (b:: BlockedUnitRange ) = (_BlockedUnitRange (blocklasts (b) .- (first (b)- 1 )),)
260
+ axes (b:: BlockedUnitRange ) = (_BlockedUnitRange (blocklasts (b) .- (first (b)- oneunit ( eltype (b)) )),)
261
261
unsafe_indices (b:: BlockedUnitRange ) = axes (b)
262
262
first (b:: BlockedUnitRange ) = b. first
263
263
# ::Integer works around case where blocklasts might return different type
264
- last (b:: BlockedUnitRange ):: Integer = isempty (blocklasts (b)) ? first (b)- 1 : last (blocklasts (b))
264
+ last (b:: BlockedUnitRange ) = isempty (blocklasts (b)) ? first (b)- oneunit ( eltype (b)) : last (blocklasts (b))
265
265
266
266
# view and indexing are identical for a unitrange
267
267
Base. view (b:: BlockedUnitRange , K:: Block{1} ) = b[K]
@@ -273,24 +273,24 @@ Base.view(b::BlockedUnitRange, K::Block{1}) = b[K]
273
273
@boundscheck K in bax || throw (BlockBoundsError (b, k))
274
274
S = first (bax)
275
275
K == S && return first (b): first (cs)
276
- return cs[k- 1 ]+ one (eltype (b)): cs[k]
276
+ return cs[k- 1 ]+ oneunit (eltype (b)): cs[k]
277
277
end
278
278
279
279
@propagate_inbounds function getindex (b:: BlockedUnitRange , KR:: BlockRange{1} )
280
280
cs = blocklasts (b)
281
- isempty (KR) && return _BlockedUnitRange (one (eltype (b)),cs[1 : 0 ])
281
+ isempty (KR) && return _BlockedUnitRange (oneunit (eltype (b)),cs[1 : 0 ])
282
282
K,J = first (KR),last (KR)
283
283
k,j = Integer (K),Integer (J)
284
284
bax = blockaxes (b,1 )
285
285
@boundscheck K in bax || throw (BlockBoundsError (b,K))
286
286
@boundscheck J in bax || throw (BlockBoundsError (b,J))
287
287
K == first (bax) && return _BlockedUnitRange (first (b),cs[k: j])
288
- _BlockedUnitRange (cs[k- 1 ]+ one (eltype (b)),cs[k: j])
288
+ _BlockedUnitRange (cs[k- 1 ]+ oneunit (eltype (b)),cs[k: j])
289
289
end
290
290
291
291
@propagate_inbounds function getindex (b:: BlockedUnitRange , KR:: BlockRange{1,Tuple{Base.OneTo{Int}}} )
292
292
cs = blocklasts (b)
293
- isempty (KR) && return _BlockedUnitRange (one (eltype (b)),cs[Base. OneTo (0 )])
293
+ isempty (KR) && return _BlockedUnitRange (oneunit (eltype (b)),cs[Base. OneTo (0 )])
294
294
J = last (KR)
295
295
j = Integer (J)
296
296
bax = blockaxes (b,1 )
@@ -422,7 +422,7 @@ julia> blocklengths(b)
422
422
3
423
423
```
424
424
"""
425
- blocklengths (a:: AbstractUnitRange{<:Integer} ) = blocklasts (a) .- blockfirsts (a) .+ one (eltype (a))
425
+ blocklengths (a:: AbstractUnitRange{<:Integer} ) = blocklasts (a) .- blockfirsts (a) .+ oneunit (eltype (a))
426
426
427
427
Base. summary (a:: BlockedUnitRange ) = _block_summary (a)
428
428
Base. summary (io:: IO , a:: BlockedUnitRange ) = _block_summary (io, a)
@@ -463,13 +463,13 @@ end
463
463
function blockfirsts (a:: BlockedUnitRange{<:Integer, <:AbstractRange} )
464
464
st = step (blocklasts (a))
465
465
first (a) == 1 || error (" Offset axes not supported" )
466
- @assert first (blocklasts (a))- first (a)+ 1 == st
467
- range (one (eltype (a)); step= st, length= eltype (a)(length (blocklasts (a))))
466
+ @assert first (blocklasts (a))- first (a)+ oneunit ( eltype (a)) == st
467
+ range (oneunit (eltype (a)); step= st, length= eltype (a)(length (blocklasts (a))))
468
468
end
469
469
function blocklengths (a:: BlockedUnitRange{<:Integer, <:AbstractRange} )
470
470
st = step (blocklasts (a))
471
471
first (a) == 1 || error (" Offset axes not supported" )
472
- @assert first (blocklasts (a))- first (a)+ 1 == st
472
+ @assert first (blocklasts (a))- first (a)+ oneunit ( eltype (a)) == st
473
473
Fill (st,length (blocklasts (a)))
474
474
end
475
475
0 commit comments