o
    3ήc                     @   s$   d Z ddgZdddZd	ddZdS )
z&Generators of  x-y pairs of node data.node_attribute_xynode_degree_xyNc                 c   s    |du r
t | }nt |}| j}|  D ]C\}}||vrq|| |d}|  rF| D ]\}}|| |d}	|D ]}
||	fV  q<q.q|D ]}|| |d}	||	fV  qHqdS )a9  Returns iterator of node-attribute pairs for all edges in G.

    Parameters
    ----------
    G: NetworkX graph

    attribute: key
       The node attribute key.

    nodes: list or iterable (optional)
        Use only edges that are incident to specified nodes.
        The default is all nodes.

    Returns
    -------
    (x, y): 2-tuple
        Generates 2-tuple of (attribute, attribute) values.

    Examples
    --------
    >>> G = nx.DiGraph()
    >>> G.add_node(1, color="red")
    >>> G.add_node(2, color="blue")
    >>> G.add_edge(1, 2)
    >>> list(nx.node_attribute_xy(G, "color"))
    [('red', 'blue')]

    Notes
    -----
    For undirected graphs each edge is produced twice, once for each edge
    representation (u, v) and (v, u), with the exception of self-loop edges
    which only appear once.
    N)setnodes	adjacencygetis_multigraphitems)G	attributer   Gnodesunbrsdictuattrvkeysvattr_ r   N/tmp/pip-target-vg8gfxp4/lib/python/networkx/algorithms/assortativity/pairs.pyr      s*   "
outinc                 #   s     du r	t | nt   |  r!| j| jd}|| }|| }n| j }}| |dD ] \}}	 fdd| |D }
||
|dD ]	\}}|	|fV  qBq,dS )a  Generate node degree-degree pairs for edges in G.

    Parameters
    ----------
    G: NetworkX graph

    x: string ('in','out')
       The degree type for source node (directed graphs only).

    y: string ('in','out')
       The degree type for target node (directed graphs only).

    weight: string or None, optional (default=None)
       The edge attribute that holds the numerical value used
       as a weight.  If None, then each edge has weight 1.
       The degree is the sum of the edge weights adjacent to the node.

    nodes: list or iterable (optional)
        Use only edges that are adjacency to specified nodes.
        The default is all nodes.

    Returns
    -------
    (x, y): 2-tuple
        Generates 2-tuple of (degree, degree) values.


    Examples
    --------
    >>> G = nx.DiGraph()
    >>> G.add_edge(1, 2)
    >>> list(nx.node_degree_xy(G, x="out", y="in"))
    [(1, 1)]
    >>> list(nx.node_degree_xy(G, x="in", y="out"))
    [(0, 0)]

    Notes
    -----
    For undirected graphs each edge is produced twice, once for each edge
    representation (u, v) and (v, u), with the exception of self-loop edges
    which only appear once.
    N)r   r   )weightc                 3   s     | ]\}}| v r|V  qd S Nr   ).0r   nbrr   r   r   	<genexpr>p   s    z!node_degree_xy.<locals>.<genexpr>)r   is_directed
out_degree	in_degreedegreeedges)r	   xyr   r   	directionxdegydegr   degu	neighborsr   degvr   r   r   r   ;   s   +

r   )r   r   NN)__doc____all__r   r   r   r   r   r   <module>   s    
6