Skip to content

Commit 77d795c

Browse files
committed
use extensions instead of requires when usable
1 parent 64abcba commit 77d795c

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

Project.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ version = "0.1.6"
66
[deps]
77
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
88
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
9+
IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153"
10+
LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043"
911
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1012
OpenBLASConsistentFPCSR_jll = "6cdc7f73-28fd-5e50-80fb-958a8875b1af"
1113
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1214
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1315
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1416

17+
[extensions]
18+
IntervalConstraintProgrammingExt = "IntervalConstraintProgramming"
19+
LazySetsExt = "LazySets"
20+
21+
[weakdeps]
22+
IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153"
23+
LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043"
24+
1525
[compat]
1626
CommonSolve = "0.2"
1727
IntervalArithmetic = "0.20.5"

src/linear_systems/oettli_nonlinear.jl renamed to ext/IntervalConstraintProgrammingExt.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
using .IntervalConstraintProgramming
1+
module IntervalConstraintProgrammingExt
2+
3+
if !isdefined(Base, :get_extension)
4+
using ..IntervalLinearAlgebra
5+
using ..IntervalConstraintProgramming
6+
else
7+
using IntervalLinearAlgebra
8+
using IntervalConstraintProgramming
9+
end
210

311
"""
412
returns the unrolled expression for \$|a ⋅x - b|\$
@@ -44,18 +52,17 @@ function oettli_eq(a, b, x)
4452
rhs = oettli_rhs(ar, br, x)
4553
ex = :(@constraint $lhs - $rhs <= 0)
4654
@eval $ex
47-
4855
end
4956

50-
51-
52-
function (op::NonLinearOettliPrager)(A, b, X::IntervalBox)
57+
function (op::IntervalLinearAlgebra.NonLinearOettliPrager)(A, b, X::IntervalBox)
5358
vars = ntuple(i -> Symbol(:x, i), length(b))
5459
separators = [oettli_eq(A[i,:], b[i], vars) for i in 1:length(b)]
5560
S = reduce(, separators)
5661
return Base.invokelatest(pave, S, X, op.tol)
5762
end
5863

59-
(op::NonLinearOettliPrager)(A, b, X=enclose(A, b)) = op(A, b, IntervalBox(X))
64+
(op::IntervalLinearAlgebra.NonLinearOettliPrager)(A, b, X=enclose(A, b)) = op(A, b, IntervalBox(X))
65+
66+
IntervalLinearAlgebra._default_precondition(_, ::NonLinearOettliPrager) = NoPrecondition()
6067

61-
_default_precondition(_, ::NonLinearOettliPrager) = NoPrecondition()
68+
end

src/linear_systems/oettli_linear.jl renamed to ext/LazySetsExt.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
using .LazySets
1+
module LazySetsExt
22

3-
function (opl::LinearOettliPrager)(A, b)
3+
if !isdefined(Base, :get_extension)
4+
using ..IntervalLinearAlgebra
5+
using ..LazySets
6+
else
7+
using IntervalLinearAlgebra
8+
using LazySets
9+
end
10+
11+
function (opl::IntervalLinearAlgebra.LinearOettliPrager)(A, b)
412
n = length(b)
513
Ac = mid.(A)
614
bc = mid.(b)
@@ -22,4 +30,6 @@ function (opl::LinearOettliPrager)(A, b)
2230
return identity.(filter!(!isempty, polytopes))
2331
end
2432

25-
_default_precondition(_, ::LinearOettliPrager) = NoPrecondition()
33+
IntervalLinearAlgebra._default_precondition(_, ::LinearOettliPrager) = NoPrecondition()
34+
35+
end

src/IntervalLinearAlgebra.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
module IntervalLinearAlgebra
22

3-
using StaticArrays, Requires, Reexport
3+
using StaticArrays, Reexport
44
using LinearAlgebra: checksquare
55

6+
if !isdefined(Base, :get_extension)
7+
using Requires
8+
end
9+
610
import Base: +, -, *, /, \, ==,
711
show, convert, promote_rule, zero, one,
812
getindex, IndexStyle, setindex!, size
@@ -54,20 +58,23 @@ else
5458
end
5559

5660
function __init__()
57-
@require IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153" include("linear_systems/oettli_nonlinear.jl")
58-
@require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("linear_systems/oettli_linear.jl")
61+
@static if !isdefined(Base, :get_extension)
62+
@require IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153" include("../ext/IntervalConstraintProgrammingExt.jl")
63+
@require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("../ext/LazySetsExt.jl")
64+
end
65+
5966
if Sys.ARCH == :x86_64
6067
@info "Switching to OpenBLAS with ConsistentFPCSR = 1 flag enabled, guarantees
6168
correct floating point rounding mode over all threads."
6269
BLAS.lbt_forward(OpenBLASConsistentFPCSR_jll.libopenblas_path; verbose = true)
63-
70+
6471
N = BLAS.get_num_threads()
6572
K = 1024
6673
if NumericalTest.rounding_test(N, K)
6774
@info "OpenBLAS is giving correct rounding on a ($K,$K) test matrix on $N threads"
6875
else
6976
@warn "OpenBLAS is not rounding correctly on the test matrix"
70-
@warn "The number of BLAS threads was set to 1 to ensure rounding mode is consistent"
77+
@warn "The number of BLAS threads was set to 1 to ensure rounding mode is consistent"
7178
if !NumericalTest.rounding_test(1, K)
7279
@warn "The rounding test failed on 1 thread"
7380
end

0 commit comments

Comments
 (0)