def chebyshev_polynomials(adj, k):
    'Calculate Chebyshev polynomials up to order k. Return a list of sparse matrices (tuple representation).'
    print('Calculating Chebyshev polynomials up to order {}...'.format(k))
    adj_normalized = normalize_adj(adj)
    laplacian = (sp.eye(adj.shape[0]) - adj_normalized)
    (largest_eigval, _) = eigsh(laplacian, 1, which='LM')
    scaled_laplacian = (((2.0 / largest_eigval[0]) * laplacian) - sp.eye(adj.shape[0]))
    t_k = list()
    t_k.append(sp.eye(adj.shape[0]))
    t_k.append(scaled_laplacian)

    def chebyshev_recurrence(t_k_minus_one, t_k_minus_two, scaled_lap):
        s_lap = sp.csr_matrix(scaled_lap, copy=True)
        return ((2 * s_lap.dot(t_k_minus_one)) - t_k_minus_two)
    for i in range(2, (k + 1)):
        t_k.append(chebyshev_recurrence(t_k[(- 1)], t_k[(- 2)], scaled_laplacian))
    return sparse_to_tuple(t_k)
Calculate Chebyshev polynomials up to order k. Return a list of sparse matrices (tuple representation).
def chebyshev_polynomials(adj, k):
    
    print('Calculating Chebyshev polynomials up to order {}...'.format(k))
    adj_normalized = normalize_adj(adj)
    laplacian = (sp.eye(adj.shape[0]) - adj_normalized)
    (largest_eigval, _) = eigsh(laplacian, 1, which='LM')
    scaled_laplacian = (((2.0 / largest_eigval[0]) * laplacian) - sp.eye(adj.shape[0]))
    t_k = list()
    t_k.append(sp.eye(adj.shape[0]))
    t_k.append(scaled_laplacian)

    def chebyshev_recurrence(t_k_minus_one, t_k_minus_two, scaled_lap):
        s_lap = sp.csr_matrix(scaled_lap, copy=True)
        return ((2 * s_lap.dot(t_k_minus_one)) - t_k_minus_two)
    for i in range(2, (k + 1)):
        t_k.append(chebyshev_recurrence(t_k[(- 1)], t_k[(- 2)], scaled_laplacian))
    return sparse_to_tuple(t_k)