From 7cb368965b313a0b8889621d8c17aa3b404ae419 Mon Sep 17 00:00:00 2001 From: Sascha Timme Date: Fri, 28 Jun 2019 16:07:44 +0200 Subject: [PATCH] Better error messages --- Project.toml | 5 +++-- src/MixedSubdivisions.jl | 44 +++++++++++++++++++++++++++------------- test/runtests.jl | 14 ++++++++++++- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/Project.toml b/Project.toml index 8f590d0..af9fd4d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MixedSubdivisions" uuid = "291d046c-3347-11e9-1e74-c3d251d406c6" authors = ["Sascha Timme "] -version = "0.3.1" +version = "0.3.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -15,8 +15,9 @@ ProgressMeter = "^0.8, ^0.9, ^1.0" StaticArrays = "^0.9, ^0.10, ^0.11" [extras] +MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3" PolynomialTestSystems = "4c526841-e1e8-562c-bfa9-9f39d642e243" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["PolynomialTestSystems", "Test"] +test = ["MultivariatePolynomials", "PolynomialTestSystems", "Test"] diff --git a/src/MixedSubdivisions.jl b/src/MixedSubdivisions.jl index 5a5ddec..ffef80b 100644 --- a/src/MixedSubdivisions.jl +++ b/src/MixedSubdivisions.jl @@ -1207,6 +1207,7 @@ Base.show(io::IO, MVC::MixedVolumeCounter) = print(io, "MixedVolume: $(MVC.volum traverser(Aᵢ::Matrix...; kwargs...) = traverser(Aᵢ; kwargs...) function traverser(As::Vector{<:Matrix}; algorithm=:regeneration) + length(As) == size(As[1], 1) || throw(ArgumentError("Number of supports and number of variables doesn't match.")) if algorithm == :regeneration RegenerationTraverser(As) elseif algorithm == :total_degree @@ -1241,19 +1242,27 @@ There are two possible values for `algorithm`: * `:regeneration`: Use the tropical regeneration algorithm described in Section 7.2 """ function mixed_volume(args...; show_progress=true, kwargs...) - T = traverser(args...; kwargs...) - mv = 0 - complete = next_cell!(T) - if show_progress - p = ProgressMeter.ProgressUnknown("Mixed volume: ") - end - while !complete - mv += mixed_cell(T).volume - show_progress && ProgressMeter.update!(p, mv) + try + T = traverser(args...; kwargs...) + mv = 0 complete = next_cell!(T) + if show_progress + p = ProgressMeter.ProgressUnknown("Mixed volume: ") + end + while !complete + mv += mixed_cell(T).volume + show_progress && ProgressMeter.update!(p, mv) + complete = next_cell!(T) + end + show_progress && ProgressMeter.finish!(p) + mv + catch e + if isa(e, InexactError) + throw(OverflowError("Mixed volume cannot since an integer overflow occured.")) + else + rethrow(e) + end end - show_progress && ProgressMeter.finish!(p) - mv end """ @@ -1497,8 +1506,15 @@ induced by a sligtly perturbated lifting are computed. The mixed cells are stored as a [`MixedCell`](@ref). """ function mixed_cells(support::Vector{<:Matrix}, lifting::Vector{<:Vector}) - iter = MixedCellIterator(support, lifting) - [copy(c) for c in iter] + try + return [copy(c) for c in MixedCellIterator(support, lifting)] + catch e + if isa(e, InexactError) + throw(OverflowError("Mixed cells cannot be computed for this lift since an integer overflow occured.")) + else + rethrow(e) + end + end end @inline function shift_indices!(ind::Vector{<:NTuple{2, <:Integer}}, m) @@ -1560,7 +1576,7 @@ function fine_mixed_cells(support::Vector{<:Matrix}, lifting_sampler=gaussian_li end end catch e - if isa(e, InexactError) || isa(e, SingularException) + if isa(e, InexactError) || isa(e, LinearAlgebra.SingularException) return nothing else rethrow(e) diff --git a/test/runtests.jl b/test/runtests.jl index 375ec65..658c9e0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,8 @@ using MixedSubdivisions const MS = MixedSubdivisions -import PolynomialTestSystems: equations, cyclic, ipp2 +import MultivariatePolynomials +const MP = MultivariatePolynomials +import PolynomialTestSystems: equations, cyclic, ipp2, cyclooctane using Test @testset "MixedSubdivisions" begin @@ -102,4 +104,14 @@ using Test @test sum(c -> c.volume, cells) == 924 @test lift isa Vector{Vector{Int32}} end + + @testset "Overflow error messages" begin + f = equations(cyclooctane()) + @test_throws ArgumentError MS.mixed_volume(f) + F = [f; randn(2, 18) * [MP.variables(f);1]] + A = support(F) + lifting = map(Ai -> MS.gaussian_lifting_sampler(size(Ai,2)), A) + @test_throws OverflowError mixed_cells(A, lifting) + @test fine_mixed_cells(F) === nothing + end end