
    h*                        S r SSKrSSKrSSKJr  / SQrSS jrSS jrSrS r	\" \	S	5      r
S
 r\\	l         \R                  SS5      \
l         \R                  SS5      r\R                  S	S5      r\\l         SrSS jr\" \S5      rSS jr\\l         \R                  SS5      \l         \R                  SS5      r\R                  SS5      r\\l         SrS r\" \S5      rS r\\l         \R                  SS5      \l         g)zvFunctions which help end users define customize node_match and
edge_match functions to use during isomorphism checks.
    N)permutations)	categorical_node_matchcategorical_edge_matchcategorical_multiedge_matchnumerical_node_matchnumerical_edge_matchnumerical_multiedge_matchgeneric_node_matchgeneric_edge_matchgeneric_multiedge_matchc                     [         R                  " U R                  U R                  U=(       d    U R                  U R
                  U R                  5      $ )z!Returns a deepcopy of a function.)typesFunctionType__code____globals____name____defaults____closure__)fnames     ^/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/isomorphism/matchhelpers.pycopyfuncr      s9    	

AMM4#51::q~~q}}     c                 D   ^^ [        UU4S j[        X5       5       5      $ )zReturns True if x and y are sufficiently close, elementwise.

Parameters
----------
rtol : float
    The relative error tolerance.
atol : float
    The absolute error tolerance.

c              3   T   >#    U  H  u  p[         R                  " XTTS 9v   M     g7f)rel_tolabs_tolN)mathisclose).0xiyiatolrtols      r   	<genexpr>allclose.<locals>.<genexpr>)   s      XiFBt||BD$?is   %()allzip)xyr%   r$   s     ``r   allcloser,      s     XcRSiXXXr   aP  
Returns a comparison function for a categorical node attribute.

The value(s) of the attr(s) must be hashable and comparable via the ==
operator since they are placed into a set([]) object.  If the sets from
G1 and G2 are the same, then the constructed function returns True.

Parameters
----------
attr : string | list
    The categorical node attribute to compare, or a list of categorical
    node attributes to compare.
default : value | list
    The default value for the categorical node attribute, or a list of
    default values for the categorical node attributes.

Returns
-------
match : function
    The customized, categorical `node_match` function.

Examples
--------
>>> import networkx.algorithms.isomorphism as iso
>>> nm = iso.categorical_node_match("size", 1)
>>> nm = iso.categorical_node_match(["color", "size"], ["red", 2])

c                 ~   ^ ^^ [        T [        5      (       a	  U U4S jnU$ [        [        T T5      5      mU4S jnU$ )Nc                 N   > U R                  TT5      UR                  TT5      :H  $ Nget)data1data2attrdefaults     r   match%categorical_node_match.<locals>.matchM   s$    99T7+uyyw/GGGr   c                 4   >^ ^ [        U U4S jT 5       5      $ )Nc              3   n   >#    U  H*  u  pTR                  X5      TR                  X5      :H  v   M,     g 7fr/   r0   )r!   r4   dr2   r3   s      r   r&   8categorical_node_match.<locals>.match.<locals>.<genexpr>T   s*     UuGDuyy)UYYt-??us   25)r(   )r2   r3   attrss   ``r   r6   r7   S   s    UuUUUr   
isinstancestrlistr)   r4   r5   r6   r<   s   `` @r   r   r   J   s=    $	H L Sw'(	V Lr   r   c                 ~   ^ ^^ [        T [        5      (       a	  U U4S jnU$ [        [        T T5      5      mU4S jnU$ )Nc                    > U R                  5        Vs1 s H  o"R                  TT5      iM     nnUR                  5        Vs1 s H  o"R                  TT5      iM     nnX4:H  $ s  snf s  snf r/   )valuesr1   )	datasets1	datasets2datavalues1values2r4   r5   s        r   r6   *categorical_multiedge_match.<locals>.match_   se    ;D;K;K;MN;M4xxg.;MGN;D;K;K;MN;M4xxg.;MGN%% ONs   A$A)c                 ,  >^^ [        5       nU R                  5        H)  m[        U4S jT 5       5      nUR                  U5        M+     [        5       nUR                  5        H)  m[        U4S jT 5       5      nUR                  U5        M+     X$:H  $ )Nc              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr/   r0   r!   r4   r:   r2   s      r   r&   =categorical_multiedge_match.<locals>.match.<locals>.<genexpr>j        BE%))D,,E    #c              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr/   r0   r!   r4   r:   r3   s      r   r&   rN   n   rO   rP   )setrD   tupleadd)rE   rF   rH   r*   rI   r2   r3   r<   s        @@r   r6   rJ   g   sz    eG"))+BEBBA , eG"))+BEBBA , %%r   r=   rA   s   `` @r   r   r   \   s;    $	&& L Sw'(		& Lr   nodeedger   a  
Returns a comparison function for a numerical node attribute.

The value(s) of the attr(s) must be numerical and sortable.  If the
sorted list of values from G1 and G2 are the same within some
tolerance, then the constructed function returns True.

Parameters
----------
attr : string | list
    The numerical node attribute to compare, or a list of numerical
    node attributes to compare.
default : value | list
    The default value for the numerical node attribute, or a list of
    default values for the numerical node attributes.
rtol : float
    The relative error tolerance.
atol : float
    The absolute error tolerance.

Returns
-------
match : function
    The customized, numerical `node_match` function.

Examples
--------
>>> import networkx.algorithms.isomorphism as iso
>>> nm = iso.numerical_node_match("weight", 1.0)
>>> nm = iso.numerical_node_match(["weight", "linewidth"], [0.25, 0.5])

c                    ^ ^^^^ [        T [        5      (       a  UU UU4S jnU$ [        [        T T5      5      mUUU4S jnU$ )Nc                 r   > [         R                  " U R                  TT5      UR                  TT5      TTS9$ )Nr   )r   r    r1   )r2   r3   r$   r4   r5   r%   s     r   r6   #numerical_node_match.<locals>.match   s6    <<		$(		$(	 r   c                    > T VVs/ s H  u  p#U R                  X#5      PM     nnnT VVs/ s H  u  p#UR                  X#5      PM     nnn[        XETTS9$ s  snnf s  snnf )Nr%   r$   )r1   r,   )	r2   r3   r4   r:   rH   rI   r$   r<   r%   s	         r   r6   rZ      sY    9>?gduyy)G?9>?gduyy)G?G4dCC @?s
   AAr=   r4   r5   r%   r$   r6   r<   s   ```` @r   r   r      sA    $	 	  L Sw'(	D
 Lr   r   c                    ^ ^^^^ [        T [        5      (       a  UU UU4S jnU$ [        [        T T5      5      mUUU4S jnU$ )Nc                    > [        UU4S jU R                  5        5       5      n[        UU4S jUR                  5        5       5      n[        X#TTS9$ )Nc              3   F   >#    U  H  oR                  TT5      v   M     g 7fr/   r0   r!   rG   r4   r5   s     r   r&   ;numerical_multiedge_match.<locals>.match.<locals>.<genexpr>        TASXXdG44AS   !c              3   F   >#    U  H  oR                  TT5      v   M     g 7fr/   r0   ra   s     r   r&   rb      rc   rd   r\   )sortedrD   r,   )rE   rF   rH   rI   r$   r4   r5   r%   s       r   r6   (numerical_multiedge_match.<locals>.match   sD    TAQAQASTTGTAQAQASTTGG4dCCr   c                   >^^ / nU R                  5        H)  m[        U4S jT
 5       5      nUR                  U5        M+     / nUR                  5        H)  m[        U4S jT
 5       5      nUR                  U5        M+     UR                  5         UR                  5         [	        X$5       H  u  pV[        XVTT	S9(       a  M    g   g)Nc              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr/   r0   rM   s      r   r&   rb      rO   rP   c              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr/   r0   rR   s      r   r&   rb      rO   rP   r\   FT)rD   rT   appendsortr)   r,   )rE   rF   rH   r*   rI   r"   r#   r2   r3   r$   r<   r%   s          @@r   r6   rg      s    G"))+BEBBq! , G"))+BEBBq! , LLNLLNg/T==  0 r   r=   r]   s   ```` @r   r	   r	      sB    $	D 	D2 L' Sw'(	" Lr   r	   a  
Returns a comparison function for a generic attribute.

The value(s) of the attr(s) are compared using the specified
operators. If all the attributes are equal, then the constructed
function returns True.

Parameters
----------
attr : string | list
    The node attribute to compare, or a list of node attributes
    to compare.
default : value | list
    The default value for the node attribute, or a list of
    default values for the node attributes.
op : callable | list
    The operator to use when comparing attribute values, or a list
    of operators to use when comparing values for each attribute.

Returns
-------
match : function
    The customized, generic `node_match` function.

Examples
--------
>>> from operator import eq
>>> from math import isclose
>>> from networkx.algorithms.isomorphism import generic_node_match
>>> nm = generic_node_match("weight", 1.0, isclose)
>>> nm = generic_node_match("color", "red", eq)
>>> nm = generic_node_match(["weight", "color"], [1.0, "red"], [isclose, eq])

c                    ^ ^^^ [        T [        5      (       a
  U UU4S jnU$ [        [        T TT5      5      mU4S jnU$ )Nc                 V   > T" U R                  TT5      UR                  TT5      5      $ r/   r0   )r2   r3   r4   r5   ops     r   r6   !generic_node_match.<locals>.match  s&    eiig.		$0HIIr   c                 z   > T H4  u  p#nU" U R                  X#5      UR                  X#5      5      (       a  M4    g   g)NFTr0   )r2   r3   r4   r:   operatorr<   s        r   r6   rp     s9    %*!		$ 2EIId4FGG  &+ r   r=   r4   r5   ro   r6   r<   s   ``` @r   r
   r
     s>    $	J L Sw+,	 Lr   r   c                 |   ^^ [        U [        5      (       a	  U /n U/nT/m[        [        X5      5      mUU4S jnU$ )a  Returns a comparison function for a generic attribute.

The value(s) of the attr(s) are compared using the specified
operators. If all the attributes are equal, then the constructed
function returns True. Potentially, the constructed edge_match
function can be slow since it must verify that no isomorphism
exists between the multiedges before it returns False.

Parameters
----------
attr : string | list
    The edge attribute to compare, or a list of node attributes
    to compare.
default : value | list
    The default value for the edge attribute, or a list of
    default values for the edgeattributes.
op : callable | list
    The operator to use when comparing attribute values, or a list
    of operators to use when comparing values for each attribute.

Returns
-------
match : function
    The customized, generic `edge_match` function.

Examples
--------
>>> from operator import eq
>>> from math import isclose
>>> from networkx.algorithms.isomorphism import generic_node_match
>>> nm = generic_node_match("weight", 1.0, isclose)
>>> nm = generic_node_match("color", "red", eq)
>>> nm = generic_node_match(["weight", "color"], [1.0, "red"], [isclose, eq])

c           
        >^^	 / nU R                  5        H)  m[        U4S jT
 5       5      nUR                  U5        M+     / nUR                  5        H)  m	[        U	4S jT
 5       5      nUR                  U5        M+     [        U5       H6  n[	        X%5       H$  u  pg[        [        S XgT5      5      (       a  M#    M4       g   g)Nc              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr/   r0   rM   s      r   r&   9generic_multiedge_match.<locals>.match.<locals>.<genexpr>I       >WTeii((rP   c              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr/   r0   rR   s      r   r&   rw   M  rx   rP   c                     U" X5      $ r/    )r*   r+   zs      r   <lambda>8generic_multiedge_match.<locals>.match.<locals>.<lambda>Q  s    qwr   TF)rD   rT   rk   r   r)   r(   map)rE   rF   rH   r*   rI   vals2r"   r#   r2   r3   r<   ro   s           @@r   r6   &generic_multiedge_match.<locals>.matchF  s    %%'E>>>ANN1 ( %%'E>>>ANN1 ( "'*Eg-36CDD .  + r   r=   rs   s     ` @r   r   r     sC    N $v)TT#$E* Lr   r/   )gh㈵>g:0yE>)__doc__r   r   	itertoolsr   __all__r   r,   categorical_docr   r   r   replacetmpdocnumerical_docr   r   r	   generic_docr
   r   r   r{   r   r   <module>r      sO     "
Y< ""8:RS 4 "1  !0!8!8!H  		 	 	0	02O	P&,  #D,   46LM @  -  ,44VVD  			vv	.	.0K	L$*  !!H& 02FG BL )  (00@  r   