Skip to content

Commit 7d5b9e2

Browse files
authored
fix removal of _isless on Julia 1.8 (#202)
1 parent cb53a93 commit 7d5b9e2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/blockindices.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ getindex(B::Block, ::CartesianIndex{0}) = B
6767
@inline (*)(index::Block, a::Integer) = *(a,index)
6868

6969
# comparison
70-
@inline isless(I1::Block{N}, I2::Block{N}) where {N} = Base.IteratorsMD._isless(0, I1.n, I2.n)
70+
# _isless copied from Base in Julia 1.7 since it was removed in 1.8.
71+
@inline function _isless(ret, I1::Tuple{Int,Vararg{Int,N}}, I2::Tuple{Int,Vararg{Int,N}}) where {N}
72+
newret = ifelse(ret==0, icmp(last(I1), last(I2)), ret)
73+
t1, t2 = Base.front(I1), Base.front(I2)
74+
# avoid dynamic dispatch by telling the compiler relational invariants
75+
return isa(t1, Tuple{}) ? _isless(newret, (), ()) : _isless(newret, t1, t2::Tuple{Int,Vararg{Int}})
76+
end
77+
_isless(ret, ::Tuple{}, ::Tuple{}) = ifelse(ret==1, true, false)
78+
icmp(a, b) = ifelse(isless(a,b), 1, ifelse(a==b, 0, -1))
79+
@inline isless(I1::Block{N}, I2::Block{N}) where {N} = _isless(0, I1.n, I2.n)
7180

7281
# conversions
7382
convert(::Type{T}, index::Block{1}) where {T<:Number} = convert(T, index.n[1])
@@ -373,4 +382,4 @@ BlockSlice{Block{1,BT},RT}(a::Base.OneTo) where {BT,RT<:AbstractUnitRange} =
373382
BlockSlice{BlockRange{1,Tuple{BT}},RT}(a::Base.OneTo) where {BT<:AbstractUnitRange,RT<:AbstractUnitRange} =
374383
BlockSlice(BlockRange(convert(BT, Base.OneTo(1))), convert(RT, a))::BlockSlice{BlockRange{1,Tuple{BT}},RT}
375384
BlockSlice{BlockIndexRange{1,Tuple{BT}},RT}(a::Base.OneTo) where {BT<:AbstractUnitRange,RT<:AbstractUnitRange} =
376-
BlockSlice(BlockIndexRange(Block(1), convert(BT, Base.OneTo(1))), convert(RT, a))::BlockSlice{BlockIndexRange{1,Tuple{BT}},RT}
385+
BlockSlice(BlockIndexRange(Block(1), convert(BT, Base.OneTo(1))), convert(RT, a))::BlockSlice{BlockIndexRange{1,Tuple{BT}},RT}

0 commit comments

Comments
 (0)