def angle_sparse(P, Q):
    """
    P and Q are sparse matrices from scipy.sparse.

    Angles are computed wrt the rows of P and wrt the columns of Q.
    """
    P = P.tocsc().astype(np.float)
    Q = Q.tocsr().astype(np.float)

    # Normalize P row-wise and Q column-wise
    P_inv_norms = np.sqrt(P.multiply(P).sum(1)) / 1
    Q_inv_norms = 1 / np.sqrt(Q.multiply(Q).sum(0))

    # Requires scipy version >= 0.13
    P = P.multiply(csc_matrix(P_inv_norms))
    Q = Q.multiply(csr_matrix(Q_inv_norms))

    P = P.tocsr()
    Q = Q.tocsc()
    cos_PQ = P.dot(Q).toarray()

    # Rounding errors may result in values outside of the domain of
    # inverse cosine.
    cos_PQ[(cos_PQ > 1)] = 1.
    cos_PQ[(cos_PQ < -1)] = -1.

    out = np.arccos(cos_PQ)

    out = np.squeeze(out)
    if out.ndim == 0:
        return out[()]
    return out


#
# Functions for computing information theoretic distances
#
dataset/ETHPy150Open inpho/vsm/vsm/spatial.py/angle_sparse/swapped operands of `/`