Skip to content

use extensions instead of requires when usable #137

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ version = "0.1.6"
[deps]
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153"
LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
OpenBLASConsistentFPCSR_jll = "6cdc7f73-28fd-5e50-80fb-958a8875b1af"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[extensions]
IntervalConstraintProgrammingExt = "IntervalConstraintProgramming"
LazySetsExt = "LazySets"

[weakdeps]
IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153"
LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043"

[compat]
CommonSolve = "0.2"
IntervalArithmetic = "0.20.5"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
using .IntervalConstraintProgramming
module IntervalConstraintProgrammingExt

if !isdefined(Base, :get_extension)
using ..IntervalLinearAlgebra
using ..IntervalConstraintProgramming
else
using IntervalLinearAlgebra
using IntervalConstraintProgramming
end

"""
returns the unrolled expression for \$|a ⋅x - b|\$
Expand Down Expand Up @@ -44,18 +52,17 @@ function oettli_eq(a, b, x)
rhs = oettli_rhs(ar, br, x)
ex = :(@constraint $lhs - $rhs <= 0)
@eval $ex

end



function (op::NonLinearOettliPrager)(A, b, X::IntervalBox)
function (op::IntervalLinearAlgebra.NonLinearOettliPrager)(A, b, X::IntervalBox)
vars = ntuple(i -> Symbol(:x, i), length(b))
separators = [oettli_eq(A[i,:], b[i], vars) for i in 1:length(b)]
S = reduce(∩, separators)
return Base.invokelatest(pave, S, X, op.tol)
end

(op::NonLinearOettliPrager)(A, b, X=enclose(A, b)) = op(A, b, IntervalBox(X))
(op::IntervalLinearAlgebra.NonLinearOettliPrager)(A, b, X=enclose(A, b)) = op(A, b, IntervalBox(X))

IntervalLinearAlgebra._default_precondition(_, ::NonLinearOettliPrager) = NoPrecondition()

_default_precondition(_, ::NonLinearOettliPrager) = NoPrecondition()
end
16 changes: 13 additions & 3 deletions src/linear_systems/oettli_linear.jl → ext/LazySetsExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
using .LazySets
module LazySetsExt

function (opl::LinearOettliPrager)(A, b)
if !isdefined(Base, :get_extension)
using ..IntervalLinearAlgebra
using ..LazySets
else
using IntervalLinearAlgebra
using LazySets
end

function (opl::IntervalLinearAlgebra.LinearOettliPrager)(A, b)
n = length(b)
Ac = mid.(A)
bc = mid.(b)
Expand All @@ -22,4 +30,6 @@ function (opl::LinearOettliPrager)(A, b)
return identity.(filter!(!isempty, polytopes))
end

_default_precondition(_, ::LinearOettliPrager) = NoPrecondition()
IntervalLinearAlgebra._default_precondition(_, ::LinearOettliPrager) = NoPrecondition()

end
17 changes: 12 additions & 5 deletions src/IntervalLinearAlgebra.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module IntervalLinearAlgebra

using StaticArrays, Requires, Reexport
using StaticArrays, Reexport
using LinearAlgebra: checksquare

if !isdefined(Base, :get_extension)
using Requires
end

import Base: +, -, *, /, \, ==,
show, convert, promote_rule, zero, one,
getindex, IndexStyle, setindex!, size
Expand Down Expand Up @@ -54,20 +58,23 @@ else
end

function __init__()
@require IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153" include("linear_systems/oettli_nonlinear.jl")
@require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("linear_systems/oettli_linear.jl")
@static if !isdefined(Base, :get_extension)
@require IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153" include("../ext/IntervalConstraintProgrammingExt.jl")
@require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("../ext/LazySetsExt.jl")
end

if Sys.ARCH == :x86_64
@info "Switching to OpenBLAS with ConsistentFPCSR = 1 flag enabled, guarantees
correct floating point rounding mode over all threads."
BLAS.lbt_forward(OpenBLASConsistentFPCSR_jll.libopenblas_path; verbose = true)

N = BLAS.get_num_threads()
K = 1024
if NumericalTest.rounding_test(N, K)
@info "OpenBLAS is giving correct rounding on a ($K,$K) test matrix on $N threads"
else
@warn "OpenBLAS is not rounding correctly on the test matrix"
@warn "The number of BLAS threads was set to 1 to ensure rounding mode is consistent"
@warn "The number of BLAS threads was set to 1 to ensure rounding mode is consistent"
if !NumericalTest.rounding_test(1, K)
@warn "The rounding test failed on 1 thread"
end
Expand Down
Loading