def cosine(U, I):
    # u .* v numerator, assume that U() is |u| x |t| and I() is |i| x |t|, hence W is |u| x |i|
    # still sparse matrix if the rows don't intersect on t
    W = U * I.T
    # calculate vectors of sums for rows (dense)
    dU = np.sqrt(U.multiply(U).sum(1))
    dI = np.sqrt(I.multiply(I).sum(1))
    # elementwise divide W by user x item matrix of profile norm multiplications
    # in order to avoid making a huge dense matrix, we need perform the division in two steps
    __divide_csr_cols_by_vector(W, np.asarray(dU).reshape(-1))
    __divide_csr_rows_by_vector(W, np.asarray(dI).reshape(-1))
    # hooray, the u x v matrix is still sparse!
    return W
Calculates the cosine distance between vectors in two sparse matrices U (a x b) and I (c x b).
dataset/ETHPy150Open ksavenkov/recsys-001/recsys/score.py/cosine