Skip to content

Commit 8113edf

Browse files
authored
Use Base.only when appropriate (#2751)
1 parent 8ba5a93 commit 8113edf

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

src/Bridges/Constraint/bridges/VectorizeBridge.jl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ function MOI.get(
123123
if x === nothing
124124
return nothing
125125
end
126-
@assert length(x) == 1
127-
return x[1] + bridge.set_constant
126+
return only(x) + bridge.set_constant
128127
end
129128

130129
function MOI.get(
@@ -133,16 +132,15 @@ function MOI.get(
133132
bridge::VectorizeBridge,
134133
)
135134
x = MOI.get(model, attr, bridge.vector_constraint)
136-
@assert length(x) == 1
137135
if MOI.Utilities.is_ray(MOI.get(model, MOI.PrimalStatus(attr.result_index)))
138136
# If it is an infeasibility certificate, it is a ray and satisfies the
139137
# homogenized problem, see https://github.com/jump-dev/MathOptInterface.jl/issues/433
140-
return x[1]
138+
return only(x)
141139
else
142140
# Otherwise, we need to add the set constant since the ConstraintPrimal
143141
# is defined as the value of the function and the set_constant was
144142
# removed from the original function
145-
return x[1] + bridge.set_constant
143+
return only(x) + bridge.set_constant
146144
end
147145
end
148146

@@ -180,8 +178,7 @@ function MOI.get(
180178
if x === nothing
181179
return nothing
182180
end
183-
@assert length(x) == 1
184-
return x[1]
181+
return only(x)
185182
end
186183

187184
function MOI.set(
@@ -235,8 +232,7 @@ function MOI.get(
235232
MOI.get(model, attr, bridge.vector_constraint),
236233
true,
237234
)
238-
@assert length(f) == 1
239-
return convert(G, f[1])
235+
return convert(G, only(f))
240236
end
241237

242238
function MOI.get(

src/Bridges/Variable/bridges/VectorizeBridge.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ function MOI.get(
141141
bridge::VectorizeBridge,
142142
)
143143
x = MOI.get(model, attr, bridge.vector_constraint)
144-
@assert length(x) == 1
145-
y = x[1]
144+
y = only(x)
146145
status = MOI.get(model, MOI.PrimalStatus(attr.result_index))
147146
if !MOI.Utilities.is_ray(status)
148147
# If it is an infeasibility certificate, it is a ray and satisfies the
@@ -160,9 +159,7 @@ function MOI.get(
160159
attr::MOI.ConstraintDual,
161160
bridge::VectorizeBridge,
162161
)
163-
x = MOI.get(model, attr, bridge.vector_constraint)
164-
@assert length(x) == 1
165-
return x[1]
162+
return only(MOI.get(model, attr, bridge.vector_constraint))
166163
end
167164

168165
function MOI.get(

src/FileFormats/MPS/MPS.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,7 @@ function Base.read!(io::IO, model::Model)
11991199
if header == HEADER_NAME
12001200
parse_name_line(data, line)
12011201
elseif header == HEADER_OBJSENSE
1202-
@assert length(items) == 1
1203-
sense = uppercase(items[1])
1202+
sense = uppercase(only(items))
12041203
@assert sense == "MAX" || sense == "MIN"
12051204
data.is_minimization = sense == "MIN"
12061205
elseif header == HEADER_ROWS

0 commit comments

Comments
 (0)