Skip to content

Commit bdce97f

Browse files
authored
replace [x == nothing] with [isnothing(x)] (#443)
1 parent 41e026c commit bdce97f

15 files changed

+40
-41
lines changed

src/common.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function _fit(P::Type{<:AbstractPolynomial},
146146
var = :x,) where {T}
147147
x = mapdomain(P, x)
148148
vand = vander(P, x, deg)
149-
if weights !== nothing
149+
if !isnothing(weights)
150150
coeffs = _wlstsq(vand, y, weights)
151151
else
152152
coeffs = vand \ y
@@ -462,7 +462,7 @@ _eltype(::Type{<:AbstractPolynomial}) = nothing
462462
_eltype(::Type{<:AbstractPolynomial{T}}) where {T} = T
463463
function _eltype(P::Type{<:AbstractPolynomial}, p::AbstractPolynomial)
464464
T′ = _eltype(P)
465-
T = T′ === nothing ? eltype(p) : T′
465+
T = isnothing(T′) ? eltype(p) : T′
466466
T
467467
end
468468
Base.iszero(p::AbstractPolynomial) = all(iszero, p)
@@ -706,7 +706,7 @@ Returns an iterator over the terms, `pᵢ⋅basis(p,i)`, of the polynomial for e
706706
monomials(p) = Monomials(p)
707707
function Base.iterate(v::Monomials, state...)
708708
y = iterate(pairs(v.p), state...)
709-
y === nothing && return nothing
709+
isnothing(y) && return nothing
710710
kv, s = y
711711
return (kv[2]*basis(v.p, kv[1]), s)
712712
end
@@ -723,18 +723,18 @@ _indeterminate(::Type{P}) where {P <: AbstractPolynomial} = nothing
723723
_indeterminate(::Type{P}) where {T, X, P <: AbstractPolynomial{T,X}} = X
724724
function indeterminate(::Type{P}) where {P <: AbstractPolynomial}
725725
X = _indeterminate(P)
726-
X === nothing ? :x : X
726+
isnothing(X) ? :x : X
727727
end
728728
indeterminate(p::P) where {P <: AbstractPolynomial} = _indeterminate(P)
729729
function indeterminate(PP::Type{P}, p::AbstractPolynomial{T,Y}) where {P <: AbstractPolynomial, T,Y}
730730
X = _indeterminate(PP)
731-
X === nothing && return Y
731+
isnothing(X) && return Y
732732
assert_same_variable(X,Y)
733733
return X
734-
#X = _indeterminate(PP) === nothing ? indeterminate(p) : _indeterminate(PP)
734+
#X = isnothing(_indeterminate(PP)) ? indeterminate(p) : _indeterminate(PP)
735735
end
736736
function indeterminate(PP::Type{P}, x::Symbol) where {P <: AbstractPolynomial}
737-
X = _indeterminate(PP) === nothing ? x : _indeterminate(PP)
737+
X = isnothing(_indeterminate(PP)) ? x : _indeterminate(PP)
738738
end
739739

740740
#=
@@ -761,7 +761,7 @@ Base.zero(p::P, var=indeterminate(p)) where {P <: AbstractPolynomial} = zero(P,
761761
Returns a representation of 1 as the given polynomial.
762762
"""
763763
Base.one(::Type{P}) where {P<:AbstractPolynomial} = throw(ArgumentError("No default method defined")) # no default method
764-
Base.one(::Type{P}, var::SymbolLike) where {P <: AbstractPolynomial} = one((P){eltype(P), Symbol(var === nothing ? :x : var)})
764+
Base.one(::Type{P}, var::SymbolLike) where {P <: AbstractPolynomial} = one((P){eltype(P), Symbol(isnothing(var) ? :x : var)})
765765
Base.one(p::P, var=indeterminate(p)) where {P <: AbstractPolynomial} = one(P, var)
766766

767767
Base.oneunit(::Type{P}, args...) where {P <: AbstractPolynomial} = one(P, args...)

src/polynomials/ChebyshevT.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct ChebyshevT{T, X} <: AbstractPolynomial{T, X}
4848
end
4949

5050
N = findlast(!iszero, coeffs)
51-
N === nothing && return new{T,X}(zeros(T,1))
51+
isnothing(N) && return new{T,X}(zeros(T,1))
5252
cs = T[coeffs[i] for i firstindex(coeffs):N]
5353
new{T,X}(cs)
5454
end

src/polynomials/ImmutablePolynomial.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ function ImmutablePolynomial{T,X}(coeffs::AbstractVector{S}) where {T,X,S}
8383
@warn "ignoring the axis offset of the coefficient vector"
8484
end
8585
N = findlast(!iszero, coeffs)
86-
N == nothing && return ImmutablePolynomial{R,X,0}(())
86+
isnothing(N) && return ImmutablePolynomial{R,X,0}(())
8787
N′ = N + 1 - firstindex(coeffs)
8888
ImmutablePolynomial{T, X, N′}([coeffs[i] for i firstindex(coeffs):N])
8989
end
9090

9191
## -- Tuple arguments
9292
function ImmutablePolynomial{T,X}(coeffs::Tuple) where {T,X}
9393
N = findlast(!iszero, coeffs)
94-
N == nothing && return zero(ImmutablePolynomial{T,X})
94+
isnothing(N) && return zero(ImmutablePolynomial{T,X})
9595
ImmutablePolynomial{T,X,N}(NTuple{N,T}(coeffs[i] for i in 1:N))
9696
end
9797

@@ -124,8 +124,8 @@ for op in [:isequal, :(==)]
124124
(N == M && $op(p1s,p2s)) && return true
125125
n1 = findlast(!iszero, p1s) # now trim out zeros
126126
n2 = findlast(!iszero, p2s)
127-
(n1 == nothing && n2 == nothing) && return true
128-
(n1 == nothing || n2 == nothing) && return false
127+
(isnothing(n1) && isnothing(n2)) && return true
128+
(isnothing(n1) || isnothing(n2)) && return false
129129
$op(p1s[1:n1],p2s[1:n2]) && return true
130130
false
131131
end

src/polynomials/LaurentPolynomial.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct LaurentPolynomial{T, X} <: LaurentBasisPolynomial{T, X}
7777
m::Union{Int, Nothing}=nothing) where {T, X, S}
7878

7979
fnz = findfirst(!iszero, coeffs)
80-
fnz == nothing && return new{T,X}(zeros(T,1), Ref(0), Ref(0))
80+
isnothing(fnz) && return new{T,X}(zeros(T,1), Ref(0), Ref(0))
8181
lnz = findlast(!iszero, coeffs)
8282
if Base.has_offset_axes(coeffs)
8383
# if present, use axes
@@ -87,7 +87,7 @@ struct LaurentPolynomial{T, X} <: LaurentBasisPolynomial{T, X}
8787

8888
c = convert(Vector{T}, coeffs[fnz:lnz])
8989

90-
m′ = fnz - 1 + (m == nothing ? 0 : m)
90+
m′ = fnz - 1 + (isnothing(m) ? 0 : m)
9191
n = m′ + (lnz-fnz)
9292

9393
(n - m′ + 1 == length(c)) || throw(ArgumentError("Lengths do not match"))

src/polynomials/Poly.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Poly{T <: Number,X} <: Polynomials.StandardBasisPolynomial{T,X}
3030
else
3131
# determine the last nonzero element and truncate a accordingly
3232
last_nz = findlast(!iszero, a)
33-
a_last = max(1, last_nz === nothing ? 0 : last_nz)
33+
a_last = max(1, isnothing(last_nz) ? 0 : last_nz)
3434
new{T,X}(a[1:a_last])
3535
end
3636
end

src/polynomials/Polynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct Polynomial{T, X} <: StandardBasisPolynomial{T, X}
3939
@warn "ignoring the axis offset of the coefficient vector"
4040
end
4141
N = findlast(!iszero, coeffs)
42-
N == nothing && return new{T,X}(zeros(T,1))
42+
isnothing(N) && return new{T,X}(zeros(T,1))
4343
cs = T[coeffs[i] for i firstindex(coeffs):N]
4444
new{T,X}(cs)
4545
end

src/polynomials/SparsePolynomial.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ end
124124
# inherits order for underlying dictionary
125125
function Base.iterate(v::PolynomialKeys{SparsePolynomial{T,X}}, state...) where {T,X}
126126
y = iterate(v.p.coeffs, state...)
127-
y == nothing && return nothing
127+
isnothing(y) && return nothing
128128
return (y[1][1], y[2])
129129
end
130130

131131
function Base.iterate(v::PolynomialValues{SparsePolynomial{T,X}}, state...) where {T,X}
132132
y = iterate(v.p.coeffs, state...)
133-
y == nothing && return nothing
133+
isnothing(y) && return nothing
134134
return (y[1][2], y[2])
135135
end
136136

src/polynomials/factored_polynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ end
9292
Base.convert(::Type{P}, p::P) where {P <: FactoredPolynomial} = p
9393
function Base.convert(P::Type{<:FactoredPolynomial}, p::FactoredPolynomial{T,X}) where {T,X}
9494
T′ = _eltype(P)
95-
𝑻 = T′ == nothing ? T : T′
95+
𝑻 = isnothing(T′) ? T : T′
9696
𝑿 = indeterminate(P, p)
9797
d = Dict{𝑻,Int}()
9898
copy!(d, p.coeffs)

src/polynomials/pi_n_polynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Base.copyto!(p::PnPolynomial{T, X}, x::S) where
3636

3737
function Polynomials.degree(p::PnPolynomial)
3838
i = findlast(!iszero, p.coeffs)
39-
i == nothing && return -1
39+
isnothing(i) && return -1
4040
i - 1
4141
end
4242

src/polynomials/standard-basis.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ end
116116
for i in 1 : N
117117
for j in 1 : M
118118
k = i + j - 1
119-
if exprs[k] === nothing
119+
if isnothing(exprs[k])
120120
exprs[k] = :(p1[$i] * p2[$j])
121121
else
122122
exprs[k] = :(muladd(p1[$i], p2[$j], $(exprs[k])))
@@ -334,10 +334,10 @@ function _gcd_noda_sasaki(a::Vector{T}, b::Vector{S};
334334
R = eltype(one(T)/one(S))
335335

336336
na1 = findlast(!iszero,a) # degree(a) + 1
337-
na1 === nothing && return(ones(R, 1))
337+
isnothing(na1) && return(ones(R, 1))
338338

339339
nb1 = findlast(!iszero,b) # degree(b) + 1
340-
nb1 === nothing && return(ones(R, 1))
340+
isnothing(nb1) && return(ones(R, 1))
341341

342342
a1 = R[a[i] for i in 1:na1]
343343
b1 = R[b[i] for i in 1:nb1]
@@ -364,7 +364,7 @@ function _gcd_noda_sasaki(a::Vector{T}, b::Vector{S};
364364
end
365365
a1 ./= sc
366366
na1 = findlast(t -> (abs(t) > tol),a1[1:nb1-1])
367-
na1 === nothing && (na1 = 0)
367+
isnothing(na1) && (na1 = 0)
368368
resize!(a1, na1)
369369
end
370370

@@ -472,7 +472,7 @@ function roots(p::P; kwargs...) where {T, P <: StandardBasisPolynomial{T}}
472472

473473
as = [p[i] for i in 0:d]
474474
K = findlast(!iszero, as)
475-
if K == nothing
475+
if isnothing(K)
476476
return R[]
477477
end
478478
k = findfirst(!iszero, as)
@@ -524,7 +524,7 @@ function fit(P::Type{<:StandardBasisPolynomial},
524524
weights = nothing,
525525
var = :x,) where {T}
526526

527-
if deg == length(x) -1 && weights == nothing
527+
if deg == length(x) -1 && isnothing(weights)
528528
_polynomial_fit(P, x, y; var=var)
529529
else
530530
_fit(P, x, y, deg; weights=weights, var=var)

0 commit comments

Comments
 (0)