Skip to content

Commit 28fb249

Browse files
committed
Update
1 parent 8b6ef74 commit 28fb249

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

docs/src/submodules/Bridges/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Bridges.debug_supports
9090
## [SetMap API](@id constraint_set_map)
9191

9292
```@docs
93+
Bridges.MapNotInvertible
9394
Bridges.map_set
9495
Bridges.inverse_map_set
9596
Bridges.map_function

src/Bridges/Constraint/set_map.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ function MOI.get(
105105
func = try
106106
MOI.Bridges.inverse_map_function(bridge, mapped_func)
107107
catch err
108+
# MapNotInvertible is thrown if the bridge does not support inverting
109+
# the function. The user doesn't need to know this, only that they
110+
# cannot get the attribute.
108111
if err isa MOI.Bridges.MapNotInvertible
109112
throw(MOI.GetAttributeNotAllowed(attr))
110-
else
111-
rethrow(err)
112113
end
114+
rethrow(err)
113115
end
114116
return MOI.Utilities.convert_approx(G, func)
115117
end
@@ -154,14 +156,16 @@ function MOI.get(
154156
if value === nothing
155157
return nothing
156158
end
157-
return try
158-
MOI.Bridges.inverse_map_function(bridge, value)
159+
try
160+
return MOI.Bridges.inverse_map_function(bridge, value)
159161
catch err
162+
# MapNotInvertible is thrown if the bridge does not support inverting
163+
# the function. The user doesn't need to know this, only that they
164+
# cannot get the attribute.
160165
if err isa MOI.Bridges.MapNotInvertible
161166
throw(MOI.GetAttributeNotAllowed(attr))
162-
else
163-
rethrow(err)
164167
end
168+
rethrow(err)
165169
end
166170
end
167171

src/Bridges/set_map.jl

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,25 @@ used for getting the [`MOI.ConstraintSet`](@ref).
3434
function inverse_map_set end
3535

3636
"""
37+
map_function(bridge::MOI.Bridges.AbstractBridge, func)
3738
map_function(::Type{BT}, func) where {BT}
3839
3940
Return the image of `func` through the linear map `A` defined in
40-
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref). This is
41-
used for getting the [`MOI.ConstraintPrimal`](@ref) of variable
41+
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref).
42+
43+
This function is used for getting the [`MOI.ConstraintPrimal`](@ref) of variable
4244
bridges. For constraint bridges, this is used for bridging the constraint,
43-
setting the [`MOI.ConstraintFunction`](@ref) and
44-
[`MOI.ConstraintPrimalStart`](@ref) and
45-
modifying the function with [`MOI.modify`](@ref).
45+
setting the [`MOI.ConstraintFunction`](@ref) and [`MOI.ConstraintPrimalStart`](@ref)
46+
and modifying the function with [`MOI.modify`](@ref).
47+
48+
The method can alternatively be defined on the bridge type. This legacy
49+
interface is kept for backward compatibility.
50+
"""
51+
function map_function(bridge::AbstractBridge, func)
52+
return map_function(typeof(bridge), func)
53+
end
4654

55+
"""
4756
map_function(::Type{BT}, func, i::IndexInVector) where {BT}
4857
4958
Return the scalar function at the `i`th index of the vector function that
@@ -52,77 +61,65 @@ would be returned by `map_function(BT, func)` except that it may compute the
5261
the [`MOI.VariablePrimal`](@ref) and
5362
[`MOI.VariablePrimalStart`](@ref) of variable bridges.
5463
"""
55-
function map_function end
56-
57-
function map_function(bridge::AbstractBridge, func)
58-
return map_function(typeof(bridge), func)
59-
end
60-
6164
function map_function(::Type{BT}, func, i::IndexInVector) where {BT}
6265
return MOI.Utilities.eachscalar(map_function(BT, func))[i.value]
6366
end
6467

6568
"""
6669
inverse_map_function(bridge::MOI.Bridges.AbstractBridge, func)
70+
inverse_map_function(::Type{BT}, func) where {BT}
6771
6872
Return the image of `func` through the inverse of the linear map `A` defined in
69-
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref). This is
70-
used by [`Variable.unbridged_map`](@ref) and for setting the
71-
[`MOI.VariablePrimalStart`](@ref) of variable bridges
72-
and for getting the [`MOI.ConstraintFunction`](@ref),
73-
the [`MOI.ConstraintPrimal`](@ref) and the
73+
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref).
74+
75+
This function is used by [`Variable.unbridged_map`](@ref) and for setting the
76+
[`MOI.VariablePrimalStart`](@ref) of variable bridges and for getting the
77+
[`MOI.ConstraintFunction`](@ref), the [`MOI.ConstraintPrimal`](@ref) and the
7478
[`MOI.ConstraintPrimalStart`](@ref) of constraint bridges.
79+
7580
If the linear map `A` is not invertible, the error [`MapNotInvertible`](@ref) is
7681
thrown.
7782
78-
inverse_map_function(::Type{BT}, func) where {BT}
79-
8083
The method can alternatively be defined on the bridge type. This legacy
8184
interface is kept for backward compatibility.
8285
"""
83-
function inverse_map_function end
84-
8586
function inverse_map_function(bridge::AbstractBridge, func)
8687
return inverse_map_function(typeof(bridge), func)
8788
end
8889

8990
"""
9091
adjoint_map_function(bridge::MOI.Bridges.AbstractBridge, func)
92+
adjoint_map_function(::Type{BT}, func) where {BT}
9193
9294
Return the image of `func` through the adjoint of the linear map `A` defined in
93-
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref). This is
94-
used for getting the [`MOI.ConstraintDual`](@ref) and
95-
[`MOI.ConstraintDualStart`](@ref) of constraint bridges.
95+
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref).
9696
97-
adjoint_map_function(::Type{BT}, func) where {BT}
97+
This function is used for getting the [`MOI.ConstraintDual`](@ref) and
98+
[`MOI.ConstraintDualStart`](@ref) of constraint bridges.
9899
99100
The method can alternatively be defined on the bridge type. This legacy
100101
interface is kept for backward compatibility.
101102
"""
102-
function adjoint_map_function end
103-
104103
function adjoint_map_function(bridge::AbstractBridge, func)
105104
return adjoint_map_function(typeof(bridge), func)
106105
end
107106

108107
"""
109108
inverse_adjoint_map_function(bridge::MOI.Bridges.AbstractBridge, func)
109+
inverse_adjoint_map_function(::Type{BT}, func) where {BT}
110110
111111
Return the image of `func` through the inverse of the adjoint of the linear map
112-
`A` defined in [`Variable.SetMapBridge`](@ref) and
113-
[`Constraint.SetMapBridge`](@ref). This is used for getting the
114-
[`MOI.ConstraintDual`](@ref) of variable bridges and setting the
115-
[`MOI.ConstraintDualStart`](@ref) of constraint bridges.
112+
`A` defined in [`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref).
113+
114+
This function is used for getting the [`MOI.ConstraintDual`](@ref) of variable
115+
bridges and setting the [`MOI.ConstraintDualStart`](@ref) of constraint bridges.
116+
116117
If the linear map `A` is not invertible, the error [`MapNotInvertible`](@ref) is
117118
thrown.
118119
119-
inverse_adjoint_map_function(::Type{BT}, func) where {BT}
120-
121120
The method can alternatively be defined on the bridge type. This legacy
122121
interface is kept for backward compatibility.
123122
"""
124-
function inverse_adjoint_map_function end
125-
126123
function inverse_adjoint_map_function(bridge::AbstractBridge, func)
127124
return inverse_adjoint_map_function(typeof(bridge), func)
128125
end

0 commit comments

Comments
 (0)