Skip to content

Use inverse_trimap instead of redefining it #2522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)

Check warning on line 197 in src/Bridges/Variable/bridges/hermitian.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/bridges/hermitian.jl#L197

Added line #L197 was not covered by tests
d = MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(j))
return N + j * n + d + i
end
Expand Down
Loading