Skip to content

Commit

Permalink
Merge 28eff7a into 09bd791
Browse files Browse the repository at this point in the history
  • Loading branch information
saschatimme committed Aug 7, 2018
2 parents 09bd791 + 28eff7a commit 300e940
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 51 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ os:
- linux
# - osx
julia:
- 0.6
- 0.7
- nightly

matrix:
allow_failures:
- julia: nightly

notifications:
email: false

Expand Down
4 changes: 1 addition & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
julia 0.6
julia 0.7
MultivariatePolynomials 0.1.3
Nullables
Compat 0.70
33 changes: 15 additions & 18 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.6
- julia_version: 0.7
- julia_version: latest

platform:
- x86 # 32-bit
- x64 # 64-bit

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: latest

branches:
only:
Expand All @@ -22,19 +26,12 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"DynamicPolynomials\"); Pkg.build(\"DynamicPolynomials\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"DynamicPolynomials\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
6 changes: 0 additions & 6 deletions src/DynamicPolynomials.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
__precompile__()

module DynamicPolynomials

using Compat

using MultivariatePolynomials
const MP = MultivariatePolynomials

using Nullables

# Exports which should be available for an enduser
import MultivariatePolynomials: differentiate, variables, subs, maxdegree, mindegree
export differentiate, variables, subs, maxdegree, mindegree
Expand Down
1 change: 1 addition & 0 deletions src/mono.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ end
Monomial::Number) = Monomial{true}(α)
end

Base.broadcastable(m::Monomial) = Ref(m)
Base.copy(m::M) where {M<:Monomial} = M(m.vars, copy(m.z))

# Generate canonical reperesentation by removing variables that are not used
Expand Down
21 changes: 12 additions & 9 deletions src/monovec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ Base.endof(x::MonomialVector) = length(x)
Base.size(x::MonomialVector) = (length(x),)
Base.length(x::MonomialVector) = length(x.Z)
Base.isempty(x::MonomialVector) = length(x) == 0
Base.start(::MonomialVector) = 1
Base.done(x::MonomialVector, state) = length(x) < state
Base.next(x::MonomialVector, state) = (x[state], state+1)
Base.iterate(x::MonomialVector) = isempty(x) ? nothing : (x[1], 1)
function Base.iterate(x::MonomialVector, state::Int)
state < length(x) ? (x[state+1], state+1) : nothing
end

MultivariatePolynomials.extdegree(x::MonomialVector) = isempty(x) ? (0, 0) : extrema(sum.(x.Z))
MultivariatePolynomials.mindegree(x::MonomialVector) = isempty(x) ? 0 : minimum(sum.(x.Z))
Expand Down Expand Up @@ -218,19 +219,21 @@ function MP.mergemonovec(ms::Vector{MonomialVector{C}}) where {C}
L = length.(ms)
X = Vector{Monomial{C}}()
while any(I .<= L)
max = Nullable{Monomial{C}}()
max = nothing
for i in 1:m
if I[i] <= L[i]
x = ms[i][I[i]]
if isnull(max) || get(max) < x
max = Nullable(x)
if max === nothing || max < x
max = x
end
end
end
@assert !isnull(max)
push!(X, get(max))
@assert max !== nothing
# to ensure that max is no more a union
max === nothing && return X
push!(X, max)
for i in 1:m
if I[i] <= L[i] && get(max) == ms[i][I[i]]
if I[i] <= L[i] && max == ms[i][I[i]]
I[i] += 1
end
end
Expand Down
16 changes: 10 additions & 6 deletions src/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ end

iscomm(::Type{Polynomial{C, T}}) where {C, T} = C

Base.broadcastable(p::Polynomial) = Ref(p)
Base.copy(p::Polynomial{C, T}) where {C, T} = Polynomial{C, T}(copy(p.a), copy(p.x))
Base.zero(::Type{Polynomial{C, T}}) where {C, T} = Polynomial(T[], MonomialVector{C}())
Base.one(::Type{Polynomial{C, T}}) where {C, T} = Polynomial([one(T)], MonomialVector{C}(PolyVar{C}[], [Int[]]))
Expand Down Expand Up @@ -75,9 +76,10 @@ Polynomial{C}(f::Function, x) where {C} = Polynomial{C, Base.promote_op(f, Int)}

Base.length(p::Polynomial) = length(p.a)
Base.isempty(p::Polynomial) = isempty(p.a)
Base.start(::Polynomial) = 1
Base.done(p::Polynomial, state) = length(p) < state
Base.next(p::Polynomial, state) = (p[state], state+1)
Base.iterate(p::Polynomial) = isempty(p) ? nothing : (p[1], 1)
function Base.iterate(p::Polynomial, state::Int)
state < length(p) ? (p[state+1], state+1) : nothing
end
#eltype(::Type{Polynomial{C, T}}) where {C, T} = T
Base.getindex(p::Polynomial, I::Int) = Term(p.a[I[1]], p.x[I[1]])

Expand All @@ -90,9 +92,11 @@ Base.endof(p::TermIterator) = length(p.p)
Base.length(p::TermIterator) = length(p.p.a)
Base.size(p::TermIterator) = (length(p),)
Base.isempty(p::TermIterator) = isempty(p.p.a)
Base.start(::TermIterator) = 1
Base.done(p::TermIterator, state) = length(p.p) < state
Base.next(p::TermIterator, state) = (p.p[state], state+1)
Base.iterate(p::TermIterator) = isempty(p) ? nothing : (p[1], 1)
function Base.iterate(p::TermIterator, state::Int)
state < length(p) ? (p[state+1], state+1) : nothing
end

Base.getindex(p::TermIterator, I::Int) = Term(p.p.a[I[1]], p.p.x[I[1]])

MP.terms(p::Polynomial) = TermIterator(p)
Expand Down
1 change: 1 addition & 0 deletions src/term.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Term(x::PolyVar{C}) where C = Term{C}(x)
Term{C, T}(α) where {C, T} = Term{C}(T(α))
Term{C}::T) where {C, T} = Term{C, T}(α, Monomial{C}())

Base.broadcastable(t::Term) = Ref(t)
#(::Type{TermContainer{C}}){C}(x::PolyVar{C}) = Term(x)
#(::Type{TermContainer{C}}){C}(x::Monomial{C}) = Term(x)
#(::Type{TermContainer{C}}){C}(t::TermContainer{C}) = t
Expand Down
5 changes: 3 additions & 2 deletions src/var.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ end

# Variable vector x returned garanteed to be sorted so that if p is built with x then vars(p) == x
macro polyvar(args...)
Compat.reduce((x,y) -> :($x; $y), [buildpolyvar(PolyVar{true}, arg) for arg in args], init=:())
reduce((x,y) -> :($x; $y), [buildpolyvar(PolyVar{true}, arg) for arg in args], init=:())
end
macro ncpolyvar(args...)
Compat.reduce((x,y) -> :($x; $y), [buildpolyvar(PolyVar{false}, arg) for arg in args], init=:())
reduce((x,y) -> :($x; $y), [buildpolyvar(PolyVar{false}, arg) for arg in args], init=:())
end

struct PolyVar{C} <: AbstractVariable
Expand All @@ -49,6 +49,7 @@ struct PolyVar{C} <: AbstractVariable
end

Base.hash(x::PolyVar, u::UInt) = hash(x.id, u)
Base.broadcastable(x::PolyVar) = Ref(x)

MP.name(v::PolyVar) = v.name
MP.monomial(v::PolyVar) = Monomial(v)
Expand Down
5 changes: 3 additions & 2 deletions test/mvp.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Compat.Pkg
const mvp_test = joinpath(Pkg.dir("MultivariatePolynomials"), "test")
using Pkg
import MultivariatePolynomials
const mvp_test = joinpath(dirname(pathof(MultivariatePolynomials)), "..", "test")
const Mod = DynamicPolynomials
const MP = MultivariatePolynomials
include(joinpath(mvp_test, "utils.jl"))
Expand Down
7 changes: 3 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using DynamicPolynomials
using MultivariatePolynomials
using Compat
using Compat.Test
using Test
using LinearAlgebra

include("mono.jl")
include("poly.jl")
include("comp.jl")

module newmodule
using Compat
using Compat.Test
using Test
import DynamicPolynomials
@testset "Polyvar macro hygiene" begin
# Verify that the @polyvar macro works when the package has been activated
Expand Down

0 comments on commit 300e940

Please sign in to comment.