Skip to content

Commit 5b94495

Browse files
authored
Remove error of CleverDict for negative indices (#1167)
1 parent ea68933 commit 5b94495

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/Utilities/CleverDicts.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ function Base.setindex!(c::CleverDict{K, V}, value::V, key::K)::V where {K, V}
169169
h = c.hash(key)::Int64
170170
if h > c.last_index
171171
c.last_index = ifelse(h == c.last_index + 1, h, -1)
172-
elseif h <= 0
173-
error("Invalid key, its hash must be > 0")
174172
end
175173
if 1 <= h <= length(c.vector) && _is_dense(c)
176174
c.vector[h] = value

test/Bridges/lazy_bridge_optimizer.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,21 @@ end
682682
MOIT.contlineartest(bridged, MOIT.TestConfig{T}(solve=false), exclude)
683683
end
684684

685+
@testset "SDPAModel with bridges and caching" begin
686+
# This tests that the computation of the reverse dict in the
687+
# caching optimizer works with negative indices
688+
cached = MOIU.CachingOptimizer(MOIU.Model{Float64}(), MOIU.MANUAL)
689+
vi_cache = MOI.add_variable(cached)
690+
model = SDPAModel{Float64}()
691+
bridged = MOIB.full_bridge_optimizer(model, Float64)
692+
MOIU.reset_optimizer(cached, bridged)
693+
MOIU.attach_optimizer(cached)
694+
vi_bridged = first(MOI.get(bridged, MOI.ListOfVariableIndices()))
695+
@test vi_bridged == MOI.VariableIndex(-1)
696+
@test cached.model_to_optimizer_map[vi_cache] == vi_bridged
697+
@test cached.optimizer_to_model_map[vi_bridged] == vi_cache
698+
end
699+
685700
@testset "Continuous Conic with SDPAModel{Float64}" begin
686701
model = SDPAModel{Float64}()
687702
bridged = MOIB.full_bridge_optimizer(model, Float64)

0 commit comments

Comments
 (0)