ó
ú£Õ\c           @   sn   d  Z  d d l Z d d l m Z d j d g ƒ Z d d g Z d d „ Z	 d	 d
 d d d „ Z
 d „  Z d S(   s&   Generators of  x-y pairs of node data.iÿÿÿÿN(   t   dict_to_numpy_arrayt    s%   Aric Hagberg <aric.hagberg@gmail.com>t   node_attribute_xyt   node_degree_xyc         c   s!  | d k r t |  ƒ } n t | ƒ } |  j } xê |  j ƒ  D]Ü \ } } | | k r[ q= n  | | j | d ƒ } |  j ƒ  rÛ x™ | j ƒ  D]J \ } } | | j | d ƒ }	 x% | j ƒ  D] \ }
 } | |	 f Vq¹ WqŠ Wq= x; | j ƒ  D]- \ } } | | j | d ƒ }	 | |	 f Vqè Wq= Wd S(   s3  Return 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 adjacency 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(   t   Nonet   sett   nodet   adjacency_itert   gett   is_multigrapht   items(   t   Gt	   attributet   nodesR   t   ut   nbrsdictt   uattrt   vt   keyst   vattrt   kt   dt   eattr(    (    s_   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/pairs.pyR   	   s     "	t   outt   inc         #   sê   ˆ  d k r t |  ƒ ‰  n t ˆ  ƒ ‰  |  j } |  j } |  j ƒ  rv i |  j d 6|  j d 6} | | } | | } n  xm | ˆ  d | ƒD]Y \ } }	 ‡  f d †  |  j | ƒ Dƒ }
 x+ | |
 d | ƒD] \ } } |	 | f VqÇ Wq‰ Wd S(   s’  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.
    R   R   t   weightc         3   s'   |  ] \ } } | ˆ  k r | Vq d  S(   N(    (   t   .0t   _t   nbr(   R   (    s_   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/pairs.pys	   <genexpr>w   s    N(   R   R   t   degree_itert   is_directedt   out_degree_itert   in_degree_itert
   edges_iter(   R   t   xt   yR   R   t   xdegt   ydegt	   directionR   t   degut	   neighborsR   t   degv(    (   R   s_   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/pairs.pyR   ?   s    +		
c         C   s`   d d l  m } y d d  l } Wn | d ƒ ‚ n Xy d d  l } Wn | d ƒ ‚ n Xd  S(   Niÿÿÿÿ(   t   SkipTests   NumPy not availables   SciPy not available(   t   noseR*   t   numpyt   scipy(   t   moduleR*   R,   R-   (    (    s_   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/pairs.pyt   setup_module}   s    (   t   __doc__t   networkxt   nxt   networkx.utilsR    t   joint
   __author__t   __all__R   R   R   R/   (    (    (    s_   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/pairs.pyt   <module>   s   	6>