Skip to content

Commit 0a1e174

Browse files
committed
Call functions instead of field access for BlockedUnitRange
1 parent 7e31cf8 commit 0a1e174

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/blockaxis.jl

+18-18
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ BlockedUnitRange(::BlockedUnitRange) = throw(ArgumentError("Forbidden due to amb
6262
_blocklengths2blocklasts(blocks) = cumsum(blocks) # extra level to allow changing default cumsum behaviour
6363
@inline blockedrange(blocks::Union{Tuple,AbstractVector}) = _BlockedUnitRange(_blocklengths2blocklasts(blocks))
6464

65-
@inline blockfirsts(a::BlockedUnitRange) = [a.first; @views(a.lasts[1:end-1]) .+ 1]
65+
@inline blockfirsts(a::BlockedUnitRange) = [first(a); @views(blocklasts(a)[1:end-1]) .+ 1]
6666
# optimize common cases
6767
@inline function blockfirsts(a::BlockedUnitRange{<:Union{Vector, RangeCumsum{<:Any, <:UnitRange}}})
68-
v = Vector{eltype(a)}(undef, length(a.lasts))
69-
v[1] = a.first
70-
v[2:end] .= @views(a.lasts[oneto(end-1)]) .+ 1
68+
v = Vector{eltype(a)}(undef, length(blocklasts(a)))
69+
v[1] = first(a)
70+
v[2:end] .= @views(blocklasts(a)[oneto(end-1)]) .+ 1
7171
return v
7272
end
7373
@inline blocklasts(a::BlockedUnitRange) = a.lasts
7474

7575
_diff(a::AbstractVector) = diff(a)
7676
_diff(a::Tuple) = diff(collect(a))
77-
@inline blocklengths(a::BlockedUnitRange) = isempty(a.lasts) ? [_diff(a.lasts);] : [first(a.lasts)-a.first+1; _diff(a.lasts)]
77+
@inline blocklengths(a::BlockedUnitRange) = isempty(blocklasts(a)) ? [_diff(blocklasts(a));] : [first(blocklasts(a))-first(a)+1; _diff(blocklasts(a))]
7878

79-
length(a::BlockedUnitRange) = isempty(a.lasts) ? 0 : Integer(last(a.lasts)-a.first+1)
79+
length(a::BlockedUnitRange) = isempty(blocklasts(a)) ? 0 : Integer(last(blocklasts(a))-first(a)+1)
8080

8181
"""
8282
blockisequal(a::AbstractUnitRange{Int}, b::AbstractUnitRange{Int})
@@ -440,24 +440,24 @@ Base.BroadcastStyle(::Type{BlockedUnitRange{R}}) where R = Base.BroadcastStyle(R
440440

441441
_blocklengths2blocklasts(blocks::AbstractRange) = RangeCumsum(blocks)
442442
function blockfirsts(a::BlockedUnitRange{Base.OneTo{Int}})
443-
a.first == 1 || error("Offset axes not supported")
444-
Base.OneTo{Int}(length(a.lasts))
443+
first(a) == 1 || error("Offset axes not supported")
444+
Base.OneTo{Int}(length(blocklasts(a)))
445445
end
446446
function blocklengths(a::BlockedUnitRange{Base.OneTo{Int}})
447-
a.first == 1 || error("Offset axes not supported")
448-
Ones{Int}(length(a.lasts))
447+
first(a) == 1 || error("Offset axes not supported")
448+
Ones{Int}(length(blocklasts(a)))
449449
end
450450
function blockfirsts(a::BlockedUnitRange{<:AbstractRange})
451-
st = step(a.lasts)
452-
a.first == 1 || error("Offset axes not supported")
453-
@assert first(a.lasts)-a.first+1 == st
454-
range(1; step=st, length=length(a.lasts))
451+
st = step(blocklasts(a))
452+
first(a) == 1 || error("Offset axes not supported")
453+
@assert first(blocklasts(a))-first(a)+1 == st
454+
range(1; step=st, length=length(blocklasts(a)))
455455
end
456456
function blocklengths(a::BlockedUnitRange{<:AbstractRange})
457-
st = step(a.lasts)
458-
a.first == 1 || error("Offset axes not supported")
459-
@assert first(a.lasts)-a.first+1 == st
460-
Fill(st,length(a.lasts))
457+
st = step(blocklasts(a))
458+
first(a) == 1 || error("Offset axes not supported")
459+
@assert first(blocklasts(a))-first(a)+1 == st
460+
Fill(st,length(blocklasts(a)))
461461
end
462462

463463

0 commit comments

Comments
 (0)