Skip to content

Commit c45ae5f

Browse files
authored
issue #178 (#179)
1 parent ce6da6b commit c45ae5f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/infrange.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ for op in (:isequal, :(==))
599599
isinteger(p.x) ? findfirst($op(convert(V, p.x)), r) : nothing
600600
end
601601
end
602-
602+
findfirst(::typeof(isone), r::InfRanges{T}) where {T} = findfirst(==(one(T)), r)
603+
findfirst(::typeof(iszero), r::InfRanges{T}) where {T} = findfirst(==(zero(T)), r)
603604

604605
FillArrays._range_convert(::Type{AbstractVector{T}}, r::InfRanges) where T = convert(AbstractVector{T}, r)
605606

@@ -618,9 +619,9 @@ function LinearAlgebra.diag(D::Diagonal{<:Any,<:InfRanges}, k::Integer = 0)
618619
end
619620
end
620621

621-
function inv(D::Diagonal{T, <:InfRanges}) where {T}
622+
function inv(D::Diagonal{<:Any, <:InfRanges})
622623
d = D.diag
623-
idx = findfirst(==(zero(T)), d)
624+
idx = findfirst(iszero, d)
624625
isnothing(idx) || throw(SingularException(idx))
625626
return Diagonal(inv.(d))
626627
end

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,17 @@ end
10971097
@test searchsorted(factorial.(big(1):∞), 6) == 3:3
10981098
@test searchsortedfirst(factorial.(big(1):∞), 7) == 4
10991099
@test searchsortedlast(factorial.(big(1):∞), 7) == 3
1100+
1101+
@testset "Issue #178" begin
1102+
findfirst(isone, 1:∞) == 1
1103+
findfirst(isone, 0:2:∞) === nothing
1104+
findfirst(isone, -5:∞) == 7
1105+
findfirst(isone, 2:∞) === nothing
1106+
findfirst(iszero, 0:∞) == 1
1107+
findfirst(iszero, 5:∞) === nothing
1108+
findfirst(iszero, 0.5:∞) === nothing
1109+
findfirst(iszero, -5.0:2.5:∞) == 3
1110+
end
11001111
end
11011112

11021113
@testset "convert infrange" begin

0 commit comments

Comments
 (0)