Skip to content

Commit 382b29a

Browse files
authored
Merge pull request #11 from JuliaAlgebra/fix-0.7
Fixes for Julia v0.7
2 parents 172550a + caa6747 commit 382b29a

File tree

13 files changed

+64
-49
lines changed

13 files changed

+64
-49
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ notifications:
1111
matrix:
1212
allow_failures:
1313
- julia: nightly
14+
15+
before_script:
16+
- julia -e 'Pkg.add("MultivariatePolynomials")'
17+
- julia -e 'Pkg.checkout("MultivariatePolynomials", "bl/fix-0.7bis")'
18+
1419
after_success:
1520
# push coverage results to Coveralls
1621
- julia -e 'cd(Pkg.dir("DynamicPolynomials")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
julia 0.6
22
MultivariatePolynomials 0.1.0
33
Nullables
4+
Compat 0.49

src/DynamicPolynomials.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ __precompile__()
22

33
module DynamicPolynomials
44

5-
import Base: length, getindex, vect, isless, isempty, start, done, next, convert, dot, copy, eltype, zero, one, *, +, -
5+
import Base: length, getindex, vect, isless, isempty, start, done, next, zero, one, *, +, -
6+
7+
using Compat
68

79
using MultivariatePolynomials
810
const MP = MultivariatePolynomials

src/comp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function grlex(x::Vector{Int}, y::Vector{Int})
135135
end
136136
end
137137

138-
function Base.isapprox(p::Polynomial{C, S}, q::Polynomial{C, T}; rtol::Real=Base.rtoldefault(S, T), atol::Real=0, ztol::Real=Base.rtoldefault(S, T)) where {C, S, T}
138+
function Base.isapprox(p::Polynomial{C, S}, q::Polynomial{C, T}; rtol::Real=Base.rtoldefault(S, T, 0), atol::Real=0, ztol::Real=Base.rtoldefault(S, T, 0)) where {C, S, T}
139139
i = j = 1
140140
while i <= length(p.x) || j <= length(q.x)
141141
if i > length(p.x) || (j <= length(q.x) && q.x[j] > p.x[i])

src/diff.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function MP.differentiate(m::Monomial{C}, x::PolyVar{C}) where C
2-
i = findfirst(_vars(m), x)
2+
i = findfirst(equalto(x), _vars(m))
33
if (i == nothing || i == 0) || m.z[i] == 0
44
zeroterm(m)
55
else
@@ -11,14 +11,14 @@ end
1111

1212
function MP.differentiate(p::Polynomial{C, T}, x::PolyVar{C}) where {C, T}
1313
# grlex order preserved
14-
i = findfirst(_vars(p), x)
14+
i = findfirst(equalto(x), _vars(p))
1515
S = Base.promote_op(*, T, Int)
16-
if i == nothing || i == 0
16+
if i === nothing || i == 0
1717
zero(Polynomial{C, S})
1818
else
19-
keep = find([z[i] > 0 for z in p.x.Z])
20-
Z = [copy(p.x.Z[i]) for i in keep]
21-
a = Vector{S}(length(keep))
19+
keep = findall(z -> z[i] > 0, p.x.Z)
20+
Z = copy.(p.x.Z[keep])
21+
a = Vector{S}(uninitialized, length(keep))
2222
for j in 1:length(Z)
2323
a[j] = p.a[keep[j]] * Z[j][i]
2424
Z[j][i] -= 1

src/mono.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ end
1919

2020
Monomial{C}(vars::Tuple{Vararg{PolyVar{C}}}, z::Vector{Int}) where C = Monomial{C}([vars...], z)
2121

22-
iscomm(::Type{Monomial{C}}) where {C} = C
23-
Monomial{C}() where {C} = Monomial{C}(PolyVar{C}[], Int[])
22+
iscomm(::Type{Monomial{C}}) where C = C
23+
Monomial{C}() where C = Monomial{C}(PolyVar{C}[], Int[])
2424
Monomial(vars::TupOrVec{PolyVar{C}}, z::Vector{Int}) where C = Monomial{C}(vars, z)
25-
Monomial(x::PolyVar{C}) where {C} = Monomial{C}(x)
25+
Monomial{C}(x::PolyVar{C}) where C = Monomial{C}([x], [1])
26+
Monomial(x::PolyVar{C}) where C = Monomial{C}(x)
2627

2728
Base.copy(m::M) where {M<:Monomial} = M(m.vars, copy(m.z))
28-
Base.convert(::Type{Monomial{C}}, x::PolyVar{C}) where C = Monomial{C}([x], [1])
2929

3030
# Generate canonical reperesentation by removing variables that are not used
3131
function canonical(m::Monomial)

src/monovec.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function _sortmonovec(X::DMonoVec{C}) where {C}
182182
allvars, Z, σ
183183
end
184184
function _removedups!(Z::Vector{Vector{Int}}, σ::Vector{Int})
185-
dups = find(i -> Z[σ[i]] == Z[σ[i-1]], 2:length(σ))
185+
dups = findall(i -> Z[σ[i]] == Z[σ[i-1]], 2:length(σ))
186186
deleteat!(σ, dups)
187187
end
188188
function MP.sortmonovec(X::DMonoVec{C}) where {C}
@@ -198,7 +198,7 @@ end
198198
function MonomialVector{C}(X::DMonoVec{C}) where C
199199
allvars, Z = buildZvarsvec(PolyVar{C}, X)
200200
sort!(Z, rev=true, lt=grlex)
201-
dups = find(i -> Z[i] == Z[i-1], 2:length(Z))
201+
dups = findall(i -> Z[i] == Z[i-1], 2:length(Z))
202202
deleteat!(Z, dups)
203203
MonomialVector{C}(allvars, Z)
204204
end

src/mult.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ function insertvar(v::Vector{PolyVar{C}}, x::PolyVar{C}, i::Int) where {C}
1111
n = length(v)
1212
I = 1:i-1
1313
J = i:n
14-
K = J+1
15-
w = Vector{PolyVar{C}}(n+1)
14+
K = J.+1
15+
w = Vector{PolyVar{C}}(uninitialized, n+1)
1616
w[I] = v[I]
1717
w[i] = x
1818
w[K] = v[J]
1919
updatez = z -> begin
20-
newz = Vector{Int}(n+1)
20+
newz = Vector{Int}(uninitialized, n+1)
2121
newz[I] = z[I]
2222
newz[i] = 1
2323
newz[K] = z[J]
@@ -79,8 +79,8 @@ function *(p::Polynomial{C, S}, q::Polynomial{C, T}) where {C, S, T}
7979
allvars, maps = mergevars([_vars(p), _vars(q)])
8080
end
8181
N = length(p)*length(q)
82-
Z = Vector{Vector{Int}}(N)
83-
a = Vector{U}(N)
82+
Z = Vector{Vector{Int}}(uninitialized, N)
83+
a = Vector{U}(uninitialized, N)
8484
i = 0
8585
for u in p
8686
for v in q

src/poly.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ struct Polynomial{C, T} <: AbstractPolynomial{T}
99
x::MonomialVector{C}
1010

1111
function Polynomial{C, T}(a::Vector{T}, x::MonomialVector{C}) where {C, T}
12-
if length(a) != length(x) throw(ArgumentError("There should be as many coefficient than monomials"))
13-
end
12+
length(a) == length(x) || throw(ArgumentError("There should be as many coefficient than monomials"))
1413
zeroidx = Int[]
1514
for (i,α) in enumerate(a)
1615
if iszero(α)
@@ -20,7 +19,7 @@ struct Polynomial{C, T} <: AbstractPolynomial{T}
2019
if !isempty(zeroidx)
2120
isnz = ones(Bool, length(a))
2221
isnz[zeroidx] = false
23-
nzidx = find(isnz)
22+
nzidx = findall(isnz)
2423
a = a[nzidx]
2524
x = x[nzidx]
2625
end
@@ -41,18 +40,19 @@ Polynomial{C, T}(a::AbstractVector, X::DMonoVec) where {C, T} = Polynomial{C, T}
4140
Polynomial{C}(a::Vector{T}, x) where {C, T} = Polynomial{C, T}(a, x)
4241
Polynomial(af::Union{Function, Vector}, x::DMonoVec{C}) where {C} = Polynomial{C}(af, x)
4342

44-
Polynomial{C}(α) where {C} = Polynomial(Term{C}(α))
45-
Polynomial(x::Union{PolyVar{C}, Monomial{C}}) where {C} = Polynomial(Term{C}(x))
43+
Polynomial{C, T}(p::Polynomial{C, T}) where {C, T} = p
44+
Polynomial{C, T}(p::Polynomial{C, S}) where {C, S, T} = Polynomial{C}(Vector{T}(p.a), p.x)
45+
Polynomial{C, T}(p::AbstractPolynomialLike) where {C, T} = Polynomial{C, T}(polynomial(p, T))
46+
Polynomial{C, T}(t::Term{C}) where {C, T} = Polynomial{C, T}([T(t.α)], [t.x])
47+
Polynomial{C, T}(m::DMonomialLike{C}) where {C, T} = Polynomial(Term{C, T}(m))
48+
Polynomial{C, T}(α) where {C, T} = Polynomial(Term{C, T}(α))
49+
4650
Polynomial{C}(p::Union{Polynomial{C}, Term{C}, Monomial{C}, PolyVar{C}}) where {C} = Polynomial(p)
51+
Polynomial{C}(α) where {C} = Polynomial(Term{C}(α))
4752

4853
Polynomial(p::Polynomial) = p
4954
Polynomial(t::Term{C, T}) where {C, T} = Polynomial{C, T}([t.α], [t.x])
50-
Base.convert(::Type{Polynomial{C, T}}, α) where {C, T} = Polynomial(Term{C, T}(α))
51-
Base.convert(::Type{Polynomial{C, T}}, m::DMonomialLike{C}) where {C, T} = Polynomial(Term{C, T}(m))
52-
Base.convert(::Type{Polynomial{C, T}}, t::Term{C}) where {C, T} = Polynomial{C, T}([T(t.α)], [t.x])
53-
Base.convert(::Type{Polynomial{C, T}}, p::Polynomial{C, T}) where {C, T} = p
54-
Base.convert(::Type{Polynomial{C, T}}, p::Polynomial{C, S}) where {C, S, T} = Polynomial{C}(Vector{T}(p.a), p.x)
55-
Base.convert(::Type{Polynomial{C, T}}, p::AbstractPolynomialLike) where {C, T} = Polynomial{C, T}(polynomial(p, T))
55+
Polynomial(x::Union{PolyVar{C}, Monomial{C}}) where {C} = Polynomial(Term{C}(x))
5656

5757
#Base.convert(::Type{TermContainer{C, T}}, p::Polynomial{C}) where {C, T} = Polynomial{C, T}(p)
5858

@@ -168,8 +168,8 @@ function MP.polynomial(Q::AbstractMatrix, mv::MonomialVector{C}, ::Type{T}) wher
168168
n = length(mv)
169169
if C
170170
N = trimap(n, n, n)
171-
Z = Vector{Vector{Int}}(N)
172-
a = Vector{T}(N)
171+
Z = Vector{Vector{Int}}(uninitialized, N)
172+
a = Vector{T}(uninitialized, N)
173173
for i in 1:n
174174
for j in i:n
175175
k = trimap(i, j, n)
@@ -184,8 +184,8 @@ function MP.polynomial(Q::AbstractMatrix, mv::MonomialVector{C}, ::Type{T}) wher
184184
v = _vars(mv)
185185
else
186186
N = n^2
187-
x = Vector{Monomial{C}}(N)
188-
a = Vector{T}(N)
187+
x = Vector{Monomial{C}}(uninitialized, N)
188+
a = Vector{T}(uninitialized, N)
189189
offset = 0
190190
for i in 1:n
191191
# for j in 1:n wouldn't be cache friendly for Q

src/subs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function fillmap!(vals, vars, s::MP.Substitution)
2-
j = findfirst(vars, s.first)
2+
j = findfirst(equalto(s.first), vars)
33
# 0.6 behaviour:
44
# If j == 0, that means that the variable is not present
55
# so it is ignored
@@ -28,7 +28,7 @@ _substype(s::MP.Substitutions) = _substype(s...)
2828

2929
function _subsmap(::MP.Eval, vars, s::MP.Substitutions)
3030
# Every variable will be replaced by some value of type T
31-
vals = Vector{_substype(s)}(length(vars))
31+
vals = Vector{_substype(s)}(uninitialized, length(vars))
3232
fillmap!(vals, vars, s...)
3333
for i in 1:length(vals)
3434
@assert isassigned(vals, i) "Variable $(vars[i]) was not assigned a value"
@@ -37,8 +37,8 @@ function _subsmap(::MP.Eval, vars, s::MP.Substitutions)
3737
end
3838
function _subsmap(::MP.Subs, vars::Vector{PolyVar{C}}, s::MP.Substitutions) where {C}
3939
# Some variable may not be replaced
40-
vals = Vector{promote_type(_substype(s), PolyVar{C})}(length(vars))
41-
copy!(vals, vars)
40+
vals = Vector{promote_type(_substype(s), PolyVar{C})}(uninitialized, length(vars))
41+
copyto!(vals, vars)
4242
fillmap!(vals, vars, s...)
4343
vals
4444
end

0 commit comments

Comments
 (0)