Skip to content

Commit bac5c24

Browse files
authored
Automatic exports (#262)
* Automatic exports * Fix format
1 parent be81f8d commit bac5c24

21 files changed

+297
-329
lines changed

src/MultivariatePolynomials.jl

+19-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import DataStructures
66

77
import MutableArithmetics as MA
88

9-
export AbstractPolynomialLike, AbstractTermLike, AbstractMonomialLike
10-
119
"""
1210
AbstractPolynomialLike{T}
1311
@@ -31,7 +29,6 @@ Abstract type for a value that can act like a monomial. For instance, an `Abstra
3129
"""
3230
abstract type AbstractMonomialLike <: AbstractTermLike{Int} end
3331

34-
export AbstractVariable, AbstractMonomial, AbstractTerm, AbstractPolynomial
3532
"""
3633
AbstractVariable <: AbstractMonomialLike
3734
@@ -60,7 +57,7 @@ Abstract type for a polynomial of coefficient type `T`, i.e. a sum of `AbstractT
6057
"""
6158
abstract type AbstractPolynomial{T} <: AbstractPolynomialLike{T} end
6259

63-
const APL{T} = AbstractPolynomialLike{T}
60+
const _APL{T} = AbstractPolynomialLike{T}
6461

6562
include("zip.jl")
6663
include("lazy_iterators.jl")
@@ -97,4 +94,22 @@ include("default_polynomial.jl")
9794

9895
include("deprecate.jl")
9996

97+
const _EXCLUDE_SYMBOLS = [Symbol(@__MODULE__), :eval, :include]
98+
99+
for sym in names(@__MODULE__; all = true)
100+
sym_string = string(sym)
101+
if sym in _EXCLUDE_SYMBOLS ||
102+
startswith(sym_string, "_") ||
103+
startswith(sym_string, "@_")
104+
continue
105+
end
106+
if !(
107+
Base.isidentifier(sym) ||
108+
(startswith(sym_string, "@") && Base.isidentifier(sym_string[2:end]))
109+
)
110+
continue
111+
end
112+
@eval export $sym
113+
end
114+
100115
end # module

src/antidifferentiation.jl

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export antidifferentiate
2-
31
"""
42
antidifferentiate(p::AbstractPolynomialLike, v::AbstractVariable, deg::Union{Int, Val}=1)
53
@@ -34,16 +32,16 @@ end
3432
function antidifferentiate(t::AbstractTermLike, v::AbstractVariable)
3533
return coefficient(t) * antidifferentiate(monomial(t), v)
3634
end
37-
function antidifferentiate(p::APL, v::AbstractVariable)
35+
function antidifferentiate(p::_APL, v::AbstractVariable)
3836
return polynomial!(antidifferentiate.(terms(p), v), SortedState())
3937
end
4038

4139
# TODO: this signature is probably too wide and creates the potential
4240
# for stack overflows
43-
antidifferentiate(p::APL, xs) = [antidifferentiate(p, x) for x in xs]
41+
antidifferentiate(p::_APL, xs) = [antidifferentiate(p, x) for x in xs]
4442

4543
# antidifferentiate(p, [x, y]) with TypedPolynomials promote x to a Monomial
46-
function antidifferentiate(p::APL, m::AbstractMonomial)
44+
function antidifferentiate(p::_APL, m::AbstractMonomial)
4745
return antidifferentiate(p, variable(m))
4846
end
4947

src/chain_rules.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import ChainRulesCore
22

3-
ChainRulesCore.@scalar_rule +(x::APL) true
4-
ChainRulesCore.@scalar_rule -(x::APL) -1
3+
ChainRulesCore.@scalar_rule +(x::_APL) true
4+
ChainRulesCore.@scalar_rule -(x::_APL) -1
55

6-
ChainRulesCore.@scalar_rule +(x::APL, y::APL) (true, true)
7-
ChainRulesCore.@scalar_rule -(x::APL, y::APL) (true, -1)
6+
ChainRulesCore.@scalar_rule +(x::_APL, y::_APL) (true, true)
7+
ChainRulesCore.@scalar_rule -(x::_APL, y::_APL) (true, -1)
88

9-
function ChainRulesCore.frule((_, Δp, Δq), ::typeof(*), p::APL, q::APL)
9+
function ChainRulesCore.frule((_, Δp, Δq), ::typeof(*), p::_APL, q::_APL)
1010
return p * q, MA.add_mul!!(p * Δq, q, Δp)
1111
end
12-
function ChainRulesCore.rrule(::typeof(*), p::APL, q::APL)
12+
function ChainRulesCore.rrule(::typeof(*), p::_APL, q::_APL)
1313
function times_pullback2(ΔΩ̇)
1414
#ΔΩ = ChainRulesCore.unthunk(Ω̇)
1515
#return (ChainRulesCore.NoTangent(), ChainRulesCore.ProjectTo(p)(ΔΩ * q'), ChainRulesCore.ProjectTo(q)(p' * ΔΩ))

src/comparison.jl

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
export isapproxzero
2-
3-
export LexOrder, InverseLexOrder, Reverse, Graded
4-
51
Base.iszero(v::AbstractVariable) = false
62
Base.iszero(m::AbstractMonomial) = false
73
Base.iszero(t::AbstractTerm) = iszero(coefficient(t))
@@ -16,10 +12,10 @@ end
1612

1713
# See https://github.com/blegat/MultivariatePolynomials.jl/issues/22
1814
# avoids the call to be transfered to left_constant_eq
19-
Base.:(==)(α::Nothing, x::APL) = false
20-
Base.:(==)(x::APL, α::Nothing) = false
21-
Base.:(==)(α::Dict, x::APL) = false
22-
Base.:(==)(x::APL, α::Dict) = false
15+
Base.:(==)(α::Nothing, x::_APL) = false
16+
Base.:(==)(x::_APL, α::Nothing) = false
17+
Base.:(==)(α::Dict, x::_APL) = false
18+
Base.:(==)(x::_APL, α::Dict) = false
2319
Base.:(==)(α::Nothing, x::RationalPoly) = false
2420
Base.:(==)(x::RationalPoly, α::Nothing) = false
2521
Base.:(==)(α::Dict, x::RationalPoly) = false
@@ -33,7 +29,7 @@ function right_term_eq(p::AbstractPolynomial, t)
3329
nterms(p) == 1 && leading_term(p) == t
3430
end
3531
end
36-
right_term_eq(p::APL, t) = right_term_eq(polynomial(p), t)
32+
right_term_eq(p::_APL, t) = right_term_eq(polynomial(p), t)
3733

3834
left_constant_eq(α, v::AbstractVariable) = false
3935
right_constant_eq(v::AbstractVariable, α) = false
@@ -46,8 +42,8 @@ function _term_constant_eq(t::AbstractTermLike, α)
4642
end
4743
left_constant_eq(α, t::AbstractTermLike) = _term_constant_eq(t, α)
4844
right_constant_eq(t::AbstractTermLike, α) = _term_constant_eq(t, α)
49-
left_constant_eq(α, p::APL) = right_term_eq(p, α)
50-
right_constant_eq(p::APL, α) = right_term_eq(p, α)
45+
left_constant_eq(α, p::_APL) = right_term_eq(p, α)
46+
right_constant_eq(p::_APL, α) = right_term_eq(p, α)
5147

5248
function Base.:(==)(mono::AbstractMonomial, v::AbstractVariable)
5349
return isone(degree(mono)) && variable(mono) == v
@@ -117,8 +113,8 @@ end
117113

118114
Base.:(==)(p::RationalPoly, q::RationalPoly) = p.num * q.den == q.num * p.den
119115
# Solve ambiguity with (::PolyType, ::Any)
120-
Base.:(==)(p::APL, q::RationalPoly) = p * q.den == q.num
121-
Base.:(==)(q::RationalPoly, p::APL) = p == q
116+
Base.:(==)(p::_APL, q::RationalPoly) = p * q.den == q.num
117+
Base.:(==)(q::RationalPoly, p::_APL) = p == q
122118
Base.:(==)(α, q::RationalPoly) = α * q.den == q.num
123119
Base.:(==)(q::RationalPoly, α) = α == q
124120

@@ -132,7 +128,7 @@ isapproxzero(m::AbstractMonomialLike; kwargs...) = false
132128
function isapproxzero(t::AbstractTermLike; kwargs...)
133129
return isapproxzero(coefficient(t); kwargs...)
134130
end
135-
function isapproxzero(p::APL; kwargs...)
131+
function isapproxzero(p::_APL; kwargs...)
136132
return all(term -> isapproxzero(term; kwargs...), terms(p))
137133
end
138134
isapproxzero(p::RationalPoly; kwargs...) = isapproxzero(p.num; kwargs...)
@@ -159,10 +155,10 @@ end
159155
function Base.isapprox(p::RationalPoly, q::RationalPoly; kwargs...)
160156
return isapprox(p.num * q.den, q.num * p.den; kwargs...)
161157
end
162-
function Base.isapprox(p::RationalPoly, q::APL; kwargs...)
158+
function Base.isapprox(p::RationalPoly, q::_APL; kwargs...)
163159
return isapprox(p.num, q * p.den; kwargs...)
164160
end
165-
function Base.isapprox(p::APL, q::RationalPoly; kwargs...)
161+
function Base.isapprox(p::_APL, q::RationalPoly; kwargs...)
166162
return isapprox(p * q.den, q.num; kwargs...)
167163
end
168164
function Base.isapprox(q::RationalPoly{C}, α; kwargs...) where {C}

src/conversion.jl

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
export variable, convert_to_constant
2-
31
function convert_constant end
4-
Base.convert(::Type{P}, α) where {P<:APL} = convert_constant(P, α)
2+
Base.convert(::Type{P}, α) where {P<:_APL} = convert_constant(P, α)
53
function convert_constant(::Type{TT}, α) where {T,TT<:AbstractTerm{T}}
64
return term(convert(T, α), constant_monomial(TT))
75
end
86
function convert_constant(::Type{PT}, α) where {PT<:AbstractPolynomial}
97
return convert(PT, convert(term_type(PT), α))
108
end
11-
function Base.convert(::Type{P}, p::APL) where {T,P<:AbstractPolynomial{T}}
9+
function Base.convert(::Type{P}, p::_APL) where {T,P<:AbstractPolynomial{T}}
1210
return error("`convert` not implemented for $P")
1311
end
1412

@@ -84,7 +82,7 @@ MA.scaling(p::AbstractPolynomialLike{T}) where {T} = convert(T, p)
8482
# Conversion polynomial -> constant
8583
# We don't define a method for `Base.convert` to reduce invalidations;
8684
# see https://github.com/JuliaAlgebra/MultivariatePolynomials.jl/pull/172
87-
function convert_to_constant(::Type{S}, p::APL) where {S}
85+
function convert_to_constant(::Type{S}, p::_APL) where {S}
8886
s = zero(S)
8987
for t in terms(p)
9088
if !isconstant(t)
@@ -95,10 +93,10 @@ function convert_to_constant(::Type{S}, p::APL) where {S}
9593
end
9694
return s
9795
end
98-
Base.convert(::Type{T}, p::APL) where {T<:Number} = convert_to_constant(T, p)
99-
function convert_to_constant(p::APL{S}) where {S}
96+
Base.convert(::Type{T}, p::_APL) where {T<:Number} = convert_to_constant(T, p)
97+
function convert_to_constant(p::_APL{S}) where {S}
10098
return convert_to_constant(S, p)
10199
end
102100

103-
# Also covers, e.g., `convert(APL, ::P)` where `P<:APL`
104-
Base.convert(::Type{PT}, p::PT) where {PT<:APL} = p
101+
# Also covers, e.g., `convert(_APL, ::P)` where `P<:_APL`
102+
Base.convert(::Type{PT}, p::PT) where {PT<:_APL} = p

src/deprecate.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ function changecoefficienttype(::Type{P}, ::Type{T}) where {P,T}
3434
return similar_type(P, T)
3535
end
3636

37-
function changecoefficienttype(poly::APL, ::Type{T}) where {T}
37+
function changecoefficienttype(poly::_APL, ::Type{T}) where {T}
3838
Base.depwarn(
3939
"`changecoefficienttype(poly, T::Type)` is deprecated, use `similar(poly, T)` instead",
4040
:changecoefficienttype,
4141
)
4242
return similar(poly, T)
4343
end
4444

45-
function mapcoefficientsnz(f::F, p::APL) where {F<:Function}
45+
function mapcoefficientsnz(f::F, p::_APL) where {F<:Function}
4646
Base.depwarn(
4747
"`mapcoefficientsnz(f, p)` is deprecated, use `map_coefficients(f, p, nonzero = true)` instead",
4848
:map_coefficientsnz,
4949
)
5050
return map_coefficients(f, p, nonzero = true)
5151
end
5252

53-
function mapcoefficientsnz_to!(output::APL, f::F, p::APL) where {F<:Function}
53+
function mapcoefficientsnz_to!(output::_APL, f::F, p::_APL) where {F<:Function}
5454
Base.depwarn(
5555
"`mapcoefficientsnz_to!(output, f, p)` is deprecated, use `map_coefficients_to!(output, f, p, nonzero = true)` instead",
5656
:map_coefficientsnz_to!,

src/differentiation.jl

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export differentiate
2-
31
"""
42
differentiate(p::AbstractPolynomialLike, v::AbstractVariable, deg::Union{Int, Val}=1)
53
@@ -39,33 +37,33 @@ function differentiate(t::AbstractTermLike, v::AbstractVariable)
3937
return coefficient(t) * differentiate(monomial(t), v)
4038
end
4139
# The polynomial function will take care of removing the zeros
42-
function differentiate(p::APL, v::AbstractVariable)
40+
function differentiate(p::_APL, v::AbstractVariable)
4341
return polynomial!(differentiate.(terms(p), v), SortedState())
4442
end
4543
function differentiate(p::RationalPoly, v::AbstractVariable)
4644
return (differentiate(p.num, v) * p.den - p.num * differentiate(p.den, v)) /
4745
p.den^2
4846
end
4947

50-
const ARPL = Union{APL,RationalPoly}
48+
const _ARPL = Union{_APL,RationalPoly}
5149

5250
function differentiate(
5351
ps::AbstractArray{PT},
5452
xs::AbstractArray,
55-
) where {PT<:ARPL}
53+
) where {PT<:_ARPL}
5654
return differentiate.(reshape(ps, (size(ps)..., 1)), reshape(xs, 1, :))
5755
end
5856

59-
function differentiate(ps::AbstractArray{PT}, xs::Tuple) where {PT<:ARPL}
57+
function differentiate(ps::AbstractArray{PT}, xs::Tuple) where {PT<:_ARPL}
6058
return differentiate(ps, collect(xs))
6159
end
6260

6361
# TODO: this signature is probably too wide and creates the potential
6462
# for stack overflows
65-
differentiate(p::ARPL, xs) = [differentiate(p, x) for x in xs]
63+
differentiate(p::_ARPL, xs) = [differentiate(p, x) for x in xs]
6664

6765
# differentiate(p, [x, y]) with TypedPolynomials promote x to a Monomial
68-
differentiate(p::ARPL, m::AbstractMonomial) = differentiate(p, variable(m))
66+
differentiate(p::_ARPL, m::AbstractMonomial) = differentiate(p, variable(m))
6967

7068
# The `R` argument indicates a desired result type. We use this in order
7169
# to attempt to preserve type-stability even though the value of `deg` cannot

0 commit comments

Comments
 (0)