def generate_compute_ATA(L, ATA, A, m, n, index_prefix=''):
    """Generate code to declare and compute ATA[i,j] = sum_k A[k,i]*A[k,j] with given A shaped (m,n)."""
    i = L.Symbol(index_prefix + 'i')
    j = L.Symbol(index_prefix + 'j')
    k = L.Symbol(index_prefix + 'k')
    code = [L.ArrayDecl('double', ATA, (n, n), values=0), L.ForRange(i, 0,
        n, body=L.ForRange(j, 0, n, body=L.ForRange(k, 0, m, body=L.
        AssignAdd(ATA[i, j], A[k, i] * A[k, j]))))]
    return L.StatementList(code)
