Skip to content

Commit

Permalink
Add more something usage
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Sep 19, 2023
1 parent 4fdfe63 commit 25db4a0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Bridges/Bridges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ function runtests(
end
# Test other bridge functions
for b in values(Constraint.bridges(model))
_general_bridge_tests(b)
_general_bridge_tests(something(b))
end
for b in values(Objective.bridges(model))
_general_bridge_tests(b)
_general_bridge_tests(something(b))
end
for b in values(Variable.bridges(model))
_general_bridge_tests(b)
_general_bridge_tests(something(b))
end
_test_delete(Bridge, model, inner)
return
Expand Down
9 changes: 5 additions & 4 deletions src/Bridges/Variable/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Base.empty!(map::Map)
map.unbridged_function =
Dict{MOI.VariableIndex,Tuple{Int64,MOI.AbstractScalarFunction}}()
else
empty!(map.unbridged_function)
empty!(something(map.unbridged_function))
end
empty!(map.parent_index)
map.current_context = 0
Expand Down Expand Up @@ -371,13 +371,14 @@ function add_keys_for_bridge(
MOI.VariableIndex(-(bridge_index - 1 + i)) for i in 1:MOI.dimension(set)
]
if map.unbridged_function !== nothing
mappings = unbridged_map(map.bridges[bridge_index], variables)
mappings =
unbridged_map(something(map.bridges[bridge_index]), variables)
if mappings === nothing
map.unbridged_function = nothing
else
for mapping in mappings
push!(
map.unbridged_function,
something(map.unbridged_function),
mapping.first => (bridge_index, mapping.second),
)
end
Expand Down Expand Up @@ -441,7 +442,7 @@ Return the expression of `vi` in terms of bridged variables.
"""
function unbridged_function(map::Map, vi::MOI.VariableIndex)
throw_if_cannot_unbridge(map)
context_func = get(map.unbridged_function, vi, nothing)
context_func = get(something(map.unbridged_function), vi, nothing)
if context_func === nothing
return nothing
end
Expand Down
2 changes: 1 addition & 1 deletion src/Nonlinear/evaluator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function MOI.objective_expr(evaluator::Evaluator)
end
return convert_to_expr(
evaluator,
evaluator.model.objective;
something(evaluator.model.objective);
moi_output_format = true,
)
end
Expand Down
2 changes: 1 addition & 1 deletion src/Nonlinear/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ function eval_univariate_hessian(
) where {T}
id = registry.univariate_operator_to_id[op]
if id <= registry.univariate_user_operator_start
return _eval_univariate_2nd_deriv(id, x)
return _eval_univariate_2nd_deriv(id, x)::T
end
offset = id - registry.univariate_user_operator_start
operator = registry.registered_univariate_operators[offset]
Expand Down
8 changes: 4 additions & 4 deletions src/Utilities/universalfallback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function MOI.delete(uf::UniversalFallback, vi::MOI.VariableIndex)
delete!(d, vi)
end
if uf.objective !== nothing
uf.objective = remove_variable(uf.objective, vi)
uf.objective = remove_variable(something(uf.objective), vi)
end
for constraints in values(uf.single_variable_constraints)
_remove_variable(uf, constraints, vi)
Expand Down Expand Up @@ -309,7 +309,7 @@ function MOI.delete(uf::UniversalFallback, vis::Vector{MOI.VariableIndex})
end
end
if uf.objective !== nothing
uf.objective = remove_variable(uf.objective, vis)
uf.objective = remove_variable(something(uf.objective), vis)
end
for constraints in values(uf.single_variable_constraints)
for vi in vis
Expand Down Expand Up @@ -678,7 +678,7 @@ function MOI.get(
# to check for duplicate names.
MOI.get(uf.model, MOI.ConstraintIndex, name)
end
ci_uf = get(uf.name_to_con, name, nothing)
ci_uf = get(something(uf.name_to_con), name, nothing)
throw_if_multiple_with_name(ci_uf, name)
c = check_type_and_multiple_names(MOI.ConstraintIndex{F,S}, ci_uf, ci, name)
return c
Expand All @@ -692,7 +692,7 @@ function MOI.get(
if uf.name_to_con === nothing
uf.name_to_con = build_name_to_con_map(uf.con_to_name)
end
ci_uf = get(uf.name_to_con, name, nothing)
ci_uf = get(something(uf.name_to_con), name, nothing)
throw_if_multiple_with_name(ci_uf, name)
return check_type_and_multiple_names(
MOI.ConstraintIndex,
Expand Down

0 comments on commit 25db4a0

Please sign in to comment.