Skip to content

Commit 67cbf3d

Browse files
committed
use coeffs() in place of p.coeffs
1 parent 6de0677 commit 67cbf3d

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/abstract.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro register(name)
3535
poly = esc(name)
3636
quote
3737
Base.convert(::Type{P}, p::P) where {P<:$poly} = p
38-
Base.convert(P::Type{<:$poly}, p::$poly) where {T} = P(p.coeffs, p.var)
38+
Base.convert(P::Type{<:$poly}, p::$poly) where {T} = P(coeffs(p), p.var)
3939
Base.promote_rule(::Type{$poly{T}}, ::Type{$poly{S}}) where {T,S} =
4040
$poly{promote_type(T, S)}
4141
Base.promote_rule(::Type{$poly{T}}, ::Type{S}) where {T,S<:Number} =

src/common.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ In-place version of [`truncate`](@ref)
170170
function truncate!(p::AbstractPolynomial{T};
171171
rtol::Real = Base.rtoldefault(real(T)),
172172
atol::Real = 0,) where {T}
173-
max_coeff = maximum(abs, p.coeffs)
173+
max_coeff = maximum(abs, coeffs(p))
174174
thresh = max_coeff * rtol + atol
175-
map!(c->abs(c) <= thresh ? zero(T) : c, p.coeffs, p.coeffs)
175+
map!(c->abs(c) <= thresh ? zero(T) : c, coeffs(p), coeffs(p))
176176
return chop!(p, rtol = rtol, atol = atol)
177177
end
178178

@@ -286,14 +286,14 @@ Inspection =#
286286
287287
The length of the polynomial.
288288
"""
289-
Base.length(p::AbstractPolynomial) = length(p.coeffs)
289+
Base.length(p::AbstractPolynomial) = length(coeffs(p))
290290
"""
291291
size(::AbstractPolynomial, [i])
292292
293293
Returns the size of the polynomials coefficients, along axis `i` if provided.
294294
"""
295-
Base.size(p::AbstractPolynomial) = size(p.coeffs)
296-
Base.size(p::AbstractPolynomial, i::Integer) = size(p.coeffs, i)
295+
Base.size(p::AbstractPolynomial) = size(coeffs(p))
296+
Base.size(p::AbstractPolynomial, i::Integer) = size(coeffs(p), i)
297297
Base.eltype(p::AbstractPolynomial{T}) where {T} = T
298298
Base.eltype(::Type{P}) where {P <: AbstractPolynomial} = P
299299
function Base.iszero(p::AbstractPolynomial)
@@ -318,7 +318,7 @@ has a nonzero coefficient. The degree of the zero polynomial is defined to be -1
318318
"""
319319
degree(p::AbstractPolynomial) = iszero(p) ? -1 : length(p) - 1
320320

321-
hasnan(p::AbstractPolynomial) = any(isnan.(p.coeffs))
321+
hasnan(p::AbstractPolynomial) = any(isnan.(coeffs(p)))
322322

323323
"""
324324
domain(::Type{<:AbstractPolynomial})
@@ -416,15 +416,15 @@ end
416416
function Base.getindex(p::AbstractPolynomial{T}, idx::Int) where {T <: Number}
417417
idx < 0 && throw(BoundsError(p, idx))
418418
idx length(p) && return zero(T)
419-
return p.coeffs[idx + 1]
419+
return coeffs(p)[idx + 1]
420420
end
421421
Base.getindex(p::AbstractPolynomial, idx::Number) = getindex(p, convert(Int, idx))
422422
Base.getindex(p::AbstractPolynomial, indices) = [getindex(p, i) for i in indices]
423-
Base.getindex(p::AbstractPolynomial, ::Colon) = p.coeffs
423+
Base.getindex(p::AbstractPolynomial, ::Colon) = coeffs(p)
424424

425425
# setindex
426426
function Base.setindex!(p::AbstractPolynomial, value::Number, idx::Int)
427-
n = length(p.coeffs)
427+
n = length(coeffs(p))
428428
if n idx
429429
resize!(p.coeffs, idx + 1)
430430
p.coeffs[n + 1:idx] .= 0
@@ -446,8 +446,8 @@ Base.setindex!(p::AbstractPolynomial, values, ::Colon) =
446446

447447
#=
448448
identity =#
449-
Base.copy(p::P) where {P <: AbstractPolynomial} = P(copy(p.coeffs), p.var)
450-
Base.hash(p::AbstractPolynomial, h::UInt) = hash(p.var, hash(p.coeffs, h))
449+
Base.copy(p::P) where {P <: AbstractPolynomial} = P(copy(coeffs(p)), p.var)
450+
Base.hash(p::AbstractPolynomial, h::UInt) = hash(p.var, hash(coeffs(p), h))
451451
"""
452452
zero(::Type{<:AbstractPolynomial})
453453
zero(::AbstractPolynomial)
@@ -467,19 +467,19 @@ Base.one(p::P) where {P <: AbstractPolynomial} = one(P)
467467

468468
#=
469469
arithmetic =#
470-
Base.:-(p::P) where {P <: AbstractPolynomial} = P(-p.coeffs, p.var)
470+
Base.:-(p::P) where {P <: AbstractPolynomial} = P(-coeffs(p), p.var)
471471
Base.:+(c::Number, p::AbstractPolynomial) = +(p, c)
472472
Base.:-(p::AbstractPolynomial, c::Number) = +(p, -c)
473473
Base.:-(c::Number, p::AbstractPolynomial) = +(-p, c)
474474
Base.:*(c::Number, p::AbstractPolynomial) = *(p, c)
475475

476476
function Base.:*(p::P, c::S) where {P <: AbstractPolynomial,S}
477477
T = promote_type(P, S)
478-
return T(p.coeffs .* c, p.var)
478+
return T(coeffs(p) .* c, p.var)
479479
end
480480
function Base.:/(p::P, c::S) where {T,P <: AbstractPolynomial{T},S}
481481
R = promote_type(P, eltype(one(T) / one(S)))
482-
return R(p.coeffs ./ c, p.var)
482+
return R(coeffs(p) ./ c, p.var)
483483
end
484484
Base.:-(p1::AbstractPolynomial, p2::AbstractPolynomial) = +(p1, -p2)
485485

@@ -547,8 +547,8 @@ Base.rem(n::AbstractPolynomial, d::AbstractPolynomial) = divrem(n, d)[2]
547547
Comparisons =#
548548
Base.isequal(p1::P, p2::P) where {P <: AbstractPolynomial} = hash(p1) == hash(p2)
549549
Base.:(==)(p1::AbstractPolynomial, p2::AbstractPolynomial) =
550-
(p1.var == p2.var) && (p1.coeffs == p2.coeffs)
551-
Base.:(==)(p::AbstractPolynomial, n::Number) = p.coeffs == [n]
550+
(p1.var == p2.var) && (coeffs(p1) == coeffs(p2))
551+
Base.:(==)(p::AbstractPolynomial, n::Number) = coeffs(p) == [n]
552552
Base.:(==)(n::Number, p::AbstractPolynomial) = p == n
553553

554554
function Base.isapprox(p1::AbstractPolynomial{T},
@@ -564,7 +564,7 @@ function Base.isapprox(p1::AbstractPolynomial{T},
564564
if length(p1t) length(p2t)
565565
return false
566566
end
567-
isapprox(p1t.coeffs, p2t.coeffs, rtol = rtol, atol = atol)
567+
isapprox(coeffs(p1t), coeffs(p2t), rtol = rtol, atol = atol)
568568
end
569569

570570
function Base.isapprox(p1::AbstractPolynomial{T},
@@ -575,7 +575,7 @@ function Base.isapprox(p1::AbstractPolynomial{T},
575575
if length(p1t) != 1
576576
return false
577577
end
578-
isapprox(p1t.coeffs, [n], rtol = rtol, atol = atol)
578+
isapprox(coeffs(p1t), [n], rtol = rtol, atol = atol)
579579
end
580580

581581
Base.isapprox(n::S,

0 commit comments

Comments
 (0)