Skip to content

Commit

Permalink
Merge 8bbfbfb into cd76ab8
Browse files Browse the repository at this point in the history
  • Loading branch information
saschatimme committed Aug 8, 2018
2 parents cd76ab8 + 8bbfbfb commit 8a18748
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 70 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ language: julia
os:
- linux
julia:
- 0.6
- 0.7
- 1.0
- nightly

matrix:
allow_failures:
- julia: nightly

notifications:
email: false

after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("MultivariatePolynomials")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
Expand Down
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
julia 0.6
Compat 0.61
julia 0.7
35 changes: 14 additions & 21 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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.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,22 +25,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(), \"MultivariatePolynomials\");
Pkg.clone(\"https://github.com/blegat/DynamicPolynomials.jl\");
Pkg.clone(\"https://github.com/rdeits/TypedPolynomials.jl\");
Pkg.build(\"MultivariatePolynomials\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"MultivariatePolynomials\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
18 changes: 1 addition & 17 deletions src/MultivariatePolynomials.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
__precompile__()

module MultivariatePolynomials

#using DocStringExtensions

using Compat
import Compat.LinearAlgebra

# The ' operator lowers to `transpose()` in v0.6 and to
# `adjoint()` in v0.7+.
# TOOD: remove this switch when dropping v0.6 support
@static if VERSION <= v"0.7.0-DEV.3351"
import Base: transpose
const adjoint_operator = transpose
else
import Compat.LinearAlgebra: adjoint
const adjoint_operator = adjoint
end
import LinearAlgebra

export AbstractPolynomialLike, AbstractTermLike, AbstractMonomialLike
"""
Expand Down
4 changes: 2 additions & 2 deletions src/det.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function Compat.LinearAlgebra.det(M::Matrix{<:AbstractPolynomialLike})
function LinearAlgebra.det(M::Matrix{<:AbstractPolynomialLike})
m = size(M)[1]
if m > 2
return sum((-1)^(i-1) * M[i,1] * det(M[1:end .!= i, 2:end]) for i in 1:m)
return sum((-1)^(i-1) * M[i,1] * LinearAlgebra.det(M[1:end .!= i, 2:end]) for i in 1:m)
else
return M[1,1] * M[2,2] - M[2,1] * M[1,2]
end
Expand Down
4 changes: 2 additions & 2 deletions src/differentiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ differentiate(α::T, v::AbstractVariable) where T = zero(T)
differentiate(v1::AbstractVariable, v2::AbstractVariable) = v1 == v2 ? 1 : 0
differentiate(t::AbstractTermLike, v::AbstractVariable) = coefficient(t) * differentiate(monomial(t), v)
# The polynomial function will take care of removing the zeros
differentiate(p::APL, v::AbstractVariable) = polynomial(differentiate.(terms(p), v), SortedState())
differentiate(p::APL, v::AbstractVariable) = polynomial(differentiate.(terms(p), Ref(v)), SortedState())
differentiate(p::RationalPoly, v::AbstractVariable) = (differentiate(p.num, v) * p.den - p.num * differentiate(p.den, v)) / p.den^2

const ARPL = Union{APL, RationalPoly}
Expand Down Expand Up @@ -63,7 +63,7 @@ differentiate(p::ARPL, m::AbstractMonomial) = differentiate(p, variable(m))
# so we just set `R` to `Any`
function (_differentiate_recursive(p, x, deg::Int, ::Type{R})::R) where {R}
if deg < 0
throw(DomainError())
throw(DomainError(deg, "degree is negative"))
elseif deg == 0
return p
else
Expand Down
2 changes: 1 addition & 1 deletion src/hash.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ function Base.hash(p::AbstractPolynomial, u::UInt)
if iszero(p)
hash(0, u)
else
reduce((u, t) -> hash(t, u), u, terms(p))
reduce((u, t) -> hash(t, u), terms(p); init=u)
end
end
16 changes: 8 additions & 8 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ for op in [:+, :-]
end
end

adjoint_operator(v::AbstractVariable) = v
adjoint_operator(m::AbstractMonomial) = m
adjoint_operator(t::T) where {T <: AbstractTerm} = adjoint_operator(coefficient(t)) * monomial(t)
adjoint_operator(p::AbstractPolynomialLike) = polynomial(map(adjoint_operator, terms(p)))

Compat.LinearAlgebra.dot(p1::AbstractPolynomialLike, p2::AbstractPolynomialLike) = p1' * p2
Compat.LinearAlgebra.dot(x, p::AbstractPolynomialLike) = x' * p
Compat.LinearAlgebra.dot(p::AbstractPolynomialLike, x) = p' * x
LinearAlgebra.adjoint(v::AbstractVariable) = v
LinearAlgebra.adjoint(m::AbstractMonomial) = m
LinearAlgebra.adjoint(t::T) where {T <: AbstractTerm} = LinearAlgebra.adjoint(coefficient(t)) * monomial(t)
LinearAlgebra.adjoint(p::AbstractPolynomialLike) = polynomial(map(LinearAlgebra.adjoint, terms(p)))

LinearAlgebra.dot(p1::AbstractPolynomialLike, p2::AbstractPolynomialLike) = p1' * p2
LinearAlgebra.dot(x, p::AbstractPolynomialLike) = x' * p
LinearAlgebra.dot(p::AbstractPolynomialLike, x) = p' * x

# Amazingly, this works! Thanks, StaticArrays.jl!
"""
Expand Down
12 changes: 7 additions & 5 deletions src/polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export mindegree, maxdegree, extdegree
export leadingterm, leadingcoefficient, leadingmonomial
export removeleadingterm, removemonomials, monic

Compat.LinearAlgebra.norm(p::AbstractPolynomialLike, r::Int=2) = norm(coefficients(p), r)
LinearAlgebra.norm(p::AbstractPolynomialLike, r::Int=2) = LinearAlgebra.norm(coefficients(p), r)

changecoefficienttype(::Type{TT}, ::Type{T}) where {TT<:AbstractTermLike, T} = termtype(TT, T)
changecoefficienttype(::Type{PT}, ::Type{T}) where {PT<:AbstractPolynomial, T} = polynomialtype(PT, T)
Expand Down Expand Up @@ -54,7 +54,7 @@ polynomial(ts::AbstractVector{<:AbstractTerm}, s::SortedUniqState) = polynomial(
polynomial(a::AbstractVector, x::AbstractVector, s::ListState=MessyState()) = polynomial([α * m for (α, m) in zip(a, x)], s)
polynomial(f::Function, mv::AbstractVector{<:AbstractMonomialLike}) = polynomial([f(i) * mv[i] for i in 1:length(mv)])
function polynomial(Q::AbstractMatrix, mv::AbstractVector)
dot(mv, Q * mv)
LinearAlgebra.dot(mv, Q * mv)
end
function polynomial(Q::AbstractMatrix, mv::AbstractVector, ::Type{T}) where T
polynomial(polynomial(Q, mv), T)
Expand Down Expand Up @@ -368,8 +368,10 @@ function mapcoefficientsnz(f::Function, p::AbstractPolynomialLike)
end
mapcoefficientsnz(f::Function, t::AbstractTermLike) = f(coefficient(t)) * monomial(t)

Base.round(t::AbstractTermLike, args...) = round(coefficient(t), args...) * monomial(t)
function Base.round(p::AbstractPolynomialLike, args...)
Base.round(t::AbstractTermLike; args...) = round(coefficient(t); args...) * monomial(t)
function Base.round(p::AbstractPolynomialLike; args...)
# round(0.1) is zero so we cannot use SortedUniqState
polynomial(round.(terms(p), args...), SortedState())
polynomial(round.(terms(p); args...), SortedState())
end

Base.broadcastable(p::AbstractPolynomialLike) = Ref(p)
2 changes: 1 addition & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BenchmarkTools
TypedPolynomials
DynamicPolynomials 0.1
2 changes: 1 addition & 1 deletion test/differentiation.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testset "Differentiation" begin
Mod.@polyvar x y
@test differentiate(3, y) == 0
@test differentiate.([x, y], y) == [0, 1]
@test differentiate.([x, y], Ref(y)) == [0, 1]
@test differentiate([x, y], (x, y)) == Matrix(1.0I, 2, 2) # TODO: this can be just `I` on v0.7 and above
@test differentiate(true*x+true*x^2, y) == 0
@inferred differentiate(true*x+true*x^2, y)
Expand Down
2 changes: 1 addition & 1 deletion test/example1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Mod.@polyvar x y
p = 2x + 3.0x*y^2 + y
@test differentiate(p, x) == 2 + 3y^2
@test differentiate.(p, (x, y)) == (2 + 3y^2, 6x*y + 1)
@test differentiate.(Ref(p), (x, y)) == (2 + 3y^2, 6x*y + 1)
@test p((x, y)=>(y, x)) == 2y + 3y*x^2 + x
@test subs(p, y=>x^2) == 2x + 3x^5 + x^2
@test p(x=>1, y=>2) == 2 + 3*4 + 2
Expand Down
4 changes: 2 additions & 2 deletions test/polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ const MP = MultivariatePolynomials

@test (@inferred round(2.6x + 1.001x^2)) == 3x + 1x^2
@test (@inferred round(3.1x*y)) == 3x*y
@test (@inferred round(2.613x + 1.1051x^2, 2)) 2.61x + 1.11x^2
@test (@inferred round(3.145x*y, 1)) 3.1x*y
@test (@inferred round(2.613x + 1.1051x^2, digits=2)) 2.61x + 1.11x^2
@test (@inferred round(3.145x*y, digits=1)) 3.1x*y

@testset "Graded Lex Order" begin
Mod.@polyvar x y z
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Compat
using Compat.Test
using Compat.LinearAlgebra
using Test
using LinearAlgebra

using MultivariatePolynomials
const MP = MultivariatePolynomials
Expand Down
6 changes: 3 additions & 3 deletions test/substitution.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Compat.Test: @inferred
import Test: @inferred

@testset "Substitution" begin
Mod.@polyvar x[1:3]
Expand All @@ -12,10 +12,10 @@ using Compat.Test: @inferred
@test (x[1])(x[1]=>x[2]) == x[2]

p = x[1]*x[2]*x[3]
@test Int(p(x => (1, 2, 3))) == 6
@test convert(Int, p(x => (1, 2, 3))) == 6

p = x[1]^2 + x[1]*x[3] - 3
@test Int(p(x => (5, x[1]*x[2], 4))) == 42
@test convert(Int, p(x => (5, x[1]*x[2], 4))) == 42

p = x[1]^2 + x[2]^2
q = p(x[1:2] => [1 -1; 1 1] * vec(x[1:2]))
Expand Down

0 comments on commit 8a18748

Please sign in to comment.