Skip to content

Commit 6312d50

Browse files
committed
Add first positive method
1 parent f23f15b commit 6312d50

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/arm_pytorch_utilities/tensor_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,7 @@ def ensure_diagonal(Q, dim):
116116
raise RuntimeError("Expect {} sized diagonal vector but given {}".format(dim, Q.shape[0]))
117117
Q = torch.diag(Q)
118118
return Q
119+
120+
def first_positive(x, dim=0):
121+
nonz = (x > 0)
122+
return ((nonz.cumsum(dim) == 1) & nonz).max(dim)

0 commit comments

Comments
 (0)