Skip to content

Commit

Permalink
minor efficiency refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rfeinman committed Feb 22, 2022
1 parent 12eec21 commit bd0b5f5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions torchmin/trustregion/exact.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,18 @@ def singular_leading_submatrix(A, U, k):
Compute term that makes the leading ``k`` by ``k``
submatrix from ``A`` singular.
"""
u = U[:k-1, k-1]

# Compute delta
delta = torch.sum(U[:k-1, k-1]**2) - A[k-1, k-1]
delta = u.dot(u) - A[k-1, k-1]

# Initialize v
v = A.new_zeros(A.shape[0])
v[k-1] = 1

# Compute the remaining values of v by solving a triangular system.
if k != 1:
v[:k-1] = solve_triangular(U[:k-1, :k-1], -U[:k-1, k-1])
v[:k-1] = solve_triangular(U[:k-1, :k-1], -u)

return delta, v

Expand Down

0 comments on commit bd0b5f5

Please sign in to comment.