Skip to content

Commit 4adb153

Browse files
authored
Add coefficient_type_or_float (#126)
* Add coefficient_type_or_float * Fix * Fix format
1 parent eb1f71c commit 4adb153

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

src/SAGE/SAGE.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function PolyJuMP.bridges(
155155
F::Type{<:MOI.AbstractVectorFunction},
156156
::Type{Cone{Signomials{Nothing}}},
157157
)
158-
return [(SAGEBridge, PolyJuMP._coef_type(F))]
158+
return Tuple{Type,Type}[(SAGEBridge, PolyJuMP.coefficient_type_or_float(F))]
159159
end
160160

161161
include("bridges/age.jl")
@@ -164,7 +164,7 @@ function PolyJuMP.bridges(
164164
F::Type{<:MOI.AbstractVectorFunction},
165165
::Type{Cone{Signomials{Int}}},
166166
)
167-
return [(AGEBridge, PolyJuMP._coef_type(F))]
167+
return Tuple{Type,Type}[(AGEBridge, PolyJuMP.coefficient_type_or_float(F))]
168168
end
169169

170170
include("bridges/signomial.jl")
@@ -173,7 +173,10 @@ function PolyJuMP.bridges(
173173
F::Type{<:MOI.AbstractVectorFunction},
174174
::Type{Cone{Polynomials{M}}},
175175
) where {M}
176-
return [(SignomialsBridge, PolyJuMP._coef_type(F))]
176+
return Tuple{Type,Type}[(
177+
SignomialsBridge,
178+
PolyJuMP.coefficient_type_or_float(F),
179+
)]
177180
end
178181

179182
end

src/constraint.jl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ end
6464
Return a list of bridges that may be needed to bridge `F`-in-`S` constraints but
6565
not the bridges that may be needed by constraints added by the bridges.
6666
"""
67-
bridges(::Type{<:MOI.AbstractFunction}, ::Type{<:MOI.AbstractSet}) = []
67+
bridges(::Type{<:MOI.AbstractFunction}, ::Type{<:MOI.AbstractSet}) =
68+
Tuple{Type,Type}[]
6869

6970
"""
7071
bridges(S::Type{<:MOI.AbstractSet})
@@ -79,21 +80,27 @@ function bridges(
7980
F::Type{<:MOI.AbstractVectorFunction},
8081
::Type{<:ZeroPolynomialSet{SS.FullSpace}},
8182
)
82-
return [(Bridges.Constraint.ZeroPolynomialBridge, _coef_type(F))]
83+
return Tuple{Type,Type}[(
84+
Bridges.Constraint.ZeroPolynomialBridge,
85+
coefficient_type_or_float(F),
86+
)]
8387
end
8488

8589
function bridges(
8690
F::Type{<:MOI.AbstractVectorFunction},
8791
::Type{<:ZeroPolynomialSet{<:SS.AbstractAlgebraicSet}},
8892
)
89-
return [(
93+
return Tuple{Type,Type}[(
9094
Bridges.Constraint.ZeroPolynomialInAlgebraicSetBridge,
91-
_coef_type(F),
95+
coefficient_type_or_float(F),
9296
)]
9397
end
9498

9599
function bridges(F::Type{<:MOI.AbstractVectorFunction}, ::Type{<:PlusMinusSet})
96-
return [(Bridges.Constraint.PlusMinusBridge, _coef_type(F))]
100+
return Tuple{Type,Type}[(
101+
Bridges.Constraint.PlusMinusBridge,
102+
coefficient_type_or_float(F),
103+
)]
97104
end
98105

99106
"""
@@ -143,8 +150,13 @@ function bridgeable(c::JuMP.AbstractConstraint, S::Type{<:MOI.AbstractSet})
143150
return c
144151
end
145152

146-
_coef_type(::Type{<:MOI.AbstractFunction}) = Float64
147-
_coef_type(::Type{<:MOI.Utilities.TypedLike{T}}) where {T} = T
153+
# TODO If `JuMP.value_type` is not `Float64`, we should
154+
# redo `bridgeable`, `bridges` etc... in `JuMP.model_convert`
155+
# the most important is that `MOI.Bridges.concrete_bridge_type`
156+
# works so we should stick to the same coefficient type if there is
157+
# one. If there is none, `Float64` should be fine.
158+
coefficient_type_or_float(::Type{<:MOI.AbstractFunction}) = Float64
159+
coefficient_type_or_float(::Type{<:MOI.Utilities.TypedLike{T}}) where {T} = T
148160

149161
function bridgeable(
150162
c::JuMP.AbstractConstraint,

test/testpolymodule.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ function PolyJuMP.bridges(
3131
F::Type{<:MOI.AbstractVectorFunction},
3232
::Type{<:NonNeg},
3333
)
34-
return [(DummyNonNegBridge, PolyJuMP._coef_type(F))]
34+
return Tuple{Type,Type}[(
35+
DummyNonNegBridge,
36+
PolyJuMP.coefficient_type_or_float(F),
37+
)]
3538
end
3639
function MOI.Bridges.added_constrained_variable_types(
3740
::Type{<:DummyNonNegBridge},

0 commit comments

Comments
 (0)