Skip to content

Commit

Permalink
Add first positive method
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonPi committed Jun 7, 2024
1 parent f23f15b commit 6312d50
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/arm_pytorch_utilities/tensor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ def ensure_diagonal(Q, dim):
raise RuntimeError("Expect {} sized diagonal vector but given {}".format(dim, Q.shape[0]))
Q = torch.diag(Q)
return Q

def first_positive(x, dim=0):
nonz = (x > 0)
return ((nonz.cumsum(dim) == 1) & nonz).max(dim)

0 comments on commit 6312d50

Please sign in to comment.