def update_P(alpha, beta, u, v, ab_updated=False):
    'log space P (gamma) computation'
    torch.add(alpha.reshape((- 1), 1), beta.reshape(1, (- 1)), out=P)
    torch.add(P, (- C), out=P)
    torch.div(P, reg, out=P)
    if (not ab_updated):
        torch.add(P, torch.log((u + M_EPS)).reshape((- 1), 1), out=P)
        torch.add(P, torch.log((v + M_EPS)).reshape(1, (- 1)), out=P)
    torch.exp(P, out=P)
log space P (gamma) computation
def update_P(alpha, beta, u, v, ab_updated=False):
    
    torch.add(alpha.reshape((- 1), 1), beta.reshape(1, (- 1)), out=P)
    torch.add(P, (- C), out=P)
    torch.div(P, reg, out=P)
    if (not ab_updated):
        torch.add(P, torch.log((u + M_EPS)).reshape((- 1), 1), out=P)
        torch.add(P, torch.log((v + M_EPS)).reshape(1, (- 1)), out=P)
    torch.exp(P, out=P)