Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages #11

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MixedSubdivisions"
uuid = "291d046c-3347-11e9-1e74-c3d251d406c6"
authors = ["Sascha Timme <sascha.timme@gmail.com>"]
version = "0.3.1"
version = "0.3.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -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"]
44 changes: 30 additions & 14 deletions src/MixedSubdivisions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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