Skip to content

Commit

Permalink
0.7 Deprecations (#13)
Browse files Browse the repository at this point in the history
* Update Julia version

* Complex128 -> ComplexF64

* Fix deprecation warnings

* Make 0.7 changes compatible to 0.6

* Don't allow travis failure on nightly

* Require only 0.6

* Fix using Test

* use Compat in tests

* Compat.LinearAlgebra

* Fix
  • Loading branch information
saschatimme authored Jul 15, 2018
1 parent cd398cd commit 7408ecf
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ git:

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia: nightly
# matrix:
# allow_failures:
# - julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
Expand Down
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.6
Compat 0.70
MultivariatePolynomials 0.1.1
2 changes: 2 additions & 0 deletions src/FixedPolynomials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module FixedPolynomials
abstract type AbstractPolySystem{T} end
export AbstractPolySystem

using Compat

#import Base: gradient

include("poly.jl")
Expand Down
12 changes: 6 additions & 6 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function PolyConfig(g::Polynomial{T}, reduced_exponents::Matrix{UInt16}, big_loo
exponents = g.exponents
m, n = size(reduced_exponents)

reduced_exponents_delimiters = Vector{UInt16}(n)
reduced_exponents_delimiters = Vector{UInt16}(undef, n)
reduced_exponents_map = Vector{NTuple{2, UInt16}}()
for j=1:n
nindices = 0
Expand All @@ -33,7 +33,7 @@ function PolyConfig(g::Polynomial{T}, reduced_exponents::Matrix{UInt16}, big_loo
end

# monomials_full = BitMatrix(exponents)
monomials_delimiters = Vector{UInt16}(n)
monomials_delimiters = Vector{UInt16}(undef, n)
monomials = Vector{UInt16}()
for j=1:n
nindices = 0
Expand All @@ -46,10 +46,10 @@ function PolyConfig(g::Polynomial{T}, reduced_exponents::Matrix{UInt16}, big_loo
monomials_delimiters[j] = nindices
end

grad_monomials_delimiters = Vector{Vector{Tuple{Delimiter, Exponent}}}(m)
grad_monomials = Vector{Vector{Index}}(m)
grad_monomials_delimiters = Vector{Vector{Tuple{Delimiter, Exponent}}}(undef, m)
grad_monomials = Vector{Vector{Index}}(undef, m)
for varindex = 1:m
imonomials_delimiters = Vector{Tuple{Delimiter, Exponent}}(n)
imonomials_delimiters = Vector{Tuple{Delimiter, Exponent}}(undef, n)
imonomials = Vector{Index}()
for j=1:n
nindices = 0
Expand Down Expand Up @@ -369,7 +369,7 @@ mutable struct GradientDiffResult{T, AV<:AbstractVector{T}}
end

function GradientDiffResult(cfg::GradientConfig{T}) where T
GradientDiffResult{T, Vector{T}}(zero(T), Vector{T}(size(cfg.differences, 1)))
GradientDiffResult{T, Vector{T}}(zero(T), Vector{T}(undef, size(cfg.differences, 1)))
end
function GradientDiffResult(grad::AbstractVector{T}) where T
GradientDiffResult{T, Vector{T}}(zero(T), grad)
Expand Down
10 changes: 5 additions & 5 deletions src/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ function _coefficients_exponents(poly::MP.AbstractPolynomialLike{T}, vars) where
terms = MP.terms(poly)
nterms = length(terms)
nvars = length(vars)
exps = Matrix{Int}(nvars, nterms)
coefficients = Vector{T}(nterms)
exps = Matrix{Int}(undef, nvars, nterms)
coefficients = Vector{T}(undef, nterms)
for j = 1:nterms
term = terms[j]
coefficients[j] = MP.coefficient(term)
Expand Down Expand Up @@ -244,7 +244,7 @@ function substitute(p::Polynomial{S}, varindex, x::T) where {S<:Number, T<:Numbe

for j = 1:nterms
coeff = cfs[j]
exp = Vector{Int}(nvars - 1)
exp = Vector{Int}(undef, nvars - 1)
# first we calculate the new coefficient and remove the varindex-th row
for i = 1:nvars
if i == varindex
Expand Down Expand Up @@ -339,7 +339,7 @@ Checks whether `p` is a homogenous polynomial. Note that this is unaffected from
value of `homogenized(p)`.
"""
function ishomogenous(p::Polynomial)
monomials_degree = sum(exponents(p), 1)
monomials_degree = Compat.sum(exponents(p), dims=1)
max_deg = monomials_degree[1]
all(x -> x == max_deg, monomials_degree)
end
Expand All @@ -354,7 +354,7 @@ function homogenize(p::Polynomial, variable::Symbol=:x0; respect_homogenous=true
if p.homogenized || (respect_homogenous && ishomogenous(p))
p
else
monomials_degree = sum(exponents(p), 1)
monomials_degree = Compat.sum(exponents(p), dims=1)
max_deg = monomials_degree[1]
Polynomial([max_deg .- monomials_degree; exponents(p)], coefficients(p), [variable; variables(p)], true)
end
Expand Down
7 changes: 5 additions & 2 deletions src/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,12 @@ function JacobianDiffResult(cfg::JacobianConfig{T}) where T
zeros(T, length(cfg.polys), size(cfg.differences, 1)))
end

function JacobianDiffResult(value::AbstractVector{T}, jacobian::AbstractMatrix{T}) where T
JacobianDiffResult{T, typeof(value), typeof(jacobian)}(value, jacobian)
@static if VERSION < v"0.7-"
function JacobianDiffResult(value::AbstractVector{T}, jacobian::AbstractMatrix{T}) where T
JacobianDiffResult{T, typeof(value), typeof(jacobian)}(value, jacobian)
end
end

value(r::JacobianDiffResult) = r.value
jacobian(r::JacobianDiffResult) = r.jacobian

Expand Down
2 changes: 1 addition & 1 deletion src/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function computetables(exponents::Matrix{T}) where {T<:Integer}
end
# now we copy the relevant subsection
# we do not compute the differences now since we need to compute the lookuptable first
differences = Matrix{UInt8}(m, maxk)
differences = Matrix{UInt8}(undef, m, maxk)
for i=1:m, j=1:maxk
differences[i, j] = lookuptable[j, i]
end
Expand Down
4 changes: 2 additions & 2 deletions test/config_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
@test_throws BoundsError FixedPolynomials.gradient!(u, f, rand(2), cfg)
@test_throws BoundsError FixedPolynomials.gradient!(u[1:2], f, w, cfg)

wc = rand(Complex128, 3)
uc = zeros(Complex128, 3)
wc = rand(ComplexF64, 3)
uc = zeros(ComplexF64, 3)
cfg = config(f, wc)
@test cfg isa GradientConfig
@test f(wc) evaluate(f, wc, cfg)
Expand Down
4 changes: 2 additions & 2 deletions test/poly_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@test variables(p) == [:x1, :x2, :x3]
@test degree(p) == 4

@test (convert(Polynomial{Complex128}, p) isa Polynomial{Complex128})
@test (convert(Polynomial{ComplexF64}, p) isa Polynomial{ComplexF64})
q = Polynomial([3 1; 1 1; 0 2], [-2, 3], [:x_1, :x_2, :x_3])
prom_p, prom_q = promote(p,q)
@test typeof(prom_p) == typeof(prom_q)
Expand Down Expand Up @@ -88,7 +88,7 @@
# Due to bug during evaluation of "empty" polynomials
F = convert(Vector{Polynomial{Float64}}, [f, g, h])

J = [differentiate(f, i) for f in F, i=1:nvariables.(F[1])]
J = [differentiate(f, i) for f in F, i=1:nvariables(F[1])]
u = rand(3)
@test map(f -> evaluate(f, u), J) == [1.0 1.0 2.0; 1.0 0.0 1.0; 0.0 1.0 1.0]
end
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using FixedPolynomials
using Base.Test
using Compat.Test
using Compat

import DynamicPolynomials
Impl = DynamicPolynomials
const Impl = DynamicPolynomials
include("poly_test.jl")
include("config_test.jl")
include("system_test.jl")
4 changes: 3 additions & 1 deletion test/system_test.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Compat.LinearAlgebra

@testset "System" begin
Impl.@polyvar x y z
Expand Down Expand Up @@ -33,7 +34,8 @@
@test cfg2 !== cfg

U = zeros(2, 3)
DF = vcat(RowVector([p(w) for p in ∇f]), [p(w) for p in ∇g] |> RowVector)

DF = [∇f[1](w) ∇f[2](w) ∇f[3](w); ∇g[1](w) ∇g[2](w) ∇g[3](w)]
evaluate(F, w, cfg)
@test DF jacobian(F, w, cfg, true)
@test DF jacobian!(U, F, w, cfg, true)
Expand Down

0 comments on commit 7408ecf

Please sign in to comment.