Skip to content

Commit

Permalink
Use inverse_trimap instead of redefining it (#2522)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Jul 5, 2024
1 parent 1bee618 commit 2ae5939
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions src/Bridges/Variable/bridges/hermitian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,12 @@ function MOI.get(
return MOI.HermitianPositiveSemidefiniteConeTriangle(bridge.n)
end

function _matrix_indices(k)
# If `k` is a diagonal index, `s(k)` is odd and 1 + 8k is a perfect square.
n = 1 + 8k
s = isqrt(n)
j = if s^2 == n
div(s, 2)
else
# Otherwise, if it is after the diagonal index `k` but before the
# diagonal index `k'` with `s(k') = s(k) + 2`, we have
# `s(k) <= s < s(k) + 2`.
# By shifting by `+1` before `div`, we make sure to have the right
# column.
div(s + 1, 2)
end
i = k - MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(j - 1))
return i, j
end

function _variable_map(idx::MOI.Bridges.IndexInVector, n)
N = MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(n))
if idx.value <= N
return idx.value
end
i, j = _matrix_indices(idx.value - N)
i, j = MOI.Utilities.inverse_trimap(idx.value - N)
d = MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(j))
return N + j * n + d + i
end
Expand Down

0 comments on commit 2ae5939

Please sign in to comment.