(A)
return CA(U, D, V, F, G, row_sum, col_sum)
:param numpy.ndarray A:
:param numpy.ndarray A:
: param numpy . ndarray A :
def correspondence(A):
    """
    :param numpy.ndarray A:
    """
    A = np.asarray(A)

    total = np.sum(A)
    if total > 0:
        corr_mat = A / total
    else:
        # ???
        corr_mat = A

    col_sum = np.sum(corr_mat, axis=0, keepdims=True)
    row_sum = np.sum(corr_mat, axis=1, keepdims=True)
    E = row_sum * col_sum

    with np.errstate(divide="ignore"):
        D_r, D_c = row_sum.ravel() ** -1, col_sum.ravel() ** -1
    D_r, D_c = np.nan_to_num(D_r), np.nan_to_num(D_c)

    def gsvd(M, wu, wv):
        assert len(M.shape) == 2
        assert len(wu.shape) == 1 and len(wv.shape) == 1
        Wu_sqrt = np.sqrt(wu)
        Wv_sqrt = np.sqrt(wv)
        B = np.c_[Wu_sqrt] * M * np.r_[Wv_sqrt]
        Ub, D, Vb = np.linalg.svd(B, full_matrices=False)
        U = np.c_[Wu_sqrt ** -1] * Ub
        V = (np.c_[Wv_sqrt ** -1] * Vb.T).T
        return U, D, V

    U, D, V = gsvd(corr_mat - E, D_r, D_c)

    F = np.c_[D_r] * U * D
    G = np.c_[D_c] * V.T * D

    if F.shape == (1, 1) and F[0, 0] == 0:
        F[0, 0] = 1

    return CA(U, D, V, F, G, row_sum, col_sum)
def correspondence ( A ) : A = np . asarray ( A ) total = np . sum ( A ) if total > 0 : corr_mat = A / total else : # ??? corr_mat = A col_sum = np . sum ( corr_mat , axis = 0 , keepdims = True ) row_sum = np . sum ( corr_mat , axis = 1 , keepdims = True ) E = row_sum * col_sum with np . errstate ( divide = "ignore" ) : D_r , D_c = row_sum . ravel ( ) ** - 1 , col_sum . ravel ( ) ** - 1 D_r , D_c = np . nan_to_num ( D_r ) , np . nan_to_num ( D_c ) def gsvd ( M , wu , wv ) : assert len ( M . shape ) == 2 assert len ( wu . shape ) == 1 and len ( wv . shape ) == 1 Wu_sqrt = np . sqrt ( wu ) Wv_sqrt = np . sqrt ( wv ) B = np . c_ [ Wu_sqrt ] * M * np . r_ [ Wv_sqrt ] Ub , D , Vb = np . linalg . svd ( B , full_matrices = False ) U = np . c_ [ Wu_sqrt ** - 1 ] * Ub V = ( np . c_ [ Wv_sqrt ** - 1 ] * Vb . T ) . T return U , D , V U , D , V = gsvd ( corr_mat - E , D_r , D_c ) F = np . c_ [ D_r ] * U * D G = np . c_ [ D_c ] * V . T * D if F . shape == ( 1 , 1 ) and F [ 0 , 0 ] == 0 : F [ 0 , 0 ] = 1 return CA ( U , D , V , F , G , row_sum , col_sum )