ó žÃÒYc @sdZddlmZddlZddlZdddddd d d d g Zdd „Zddd„Z ddd„Z dZ d„Z yee dƒZ Wnek r·d„Z nXd„Ze e _e jddƒe _e jddƒZejddƒZee_dZddd„ZyeedƒZWnek rPd„ZnXddd„Zee_ejddƒe_ejddƒZejdd ƒZee_dZd„Zyeed ƒZWnek réd„ZnXd„Zee_ejddƒe_dS( svFunctions which help end users define customize node_match and edge_match functions to use during isomorphism checks. iÿÿÿÿ(t permutationsNtcategorical_node_matchtcategorical_edge_matchtcategorical_multiedge_matchtnumerical_node_matchtnumerical_edge_matchtnumerical_multiedge_matchtgeneric_node_matchtgeneric_edge_matchtgeneric_multiedge_matchcCsuy2tj|j|j|p!|j|j|jƒSWn<tk rptj|j|j |p`|j|j |j ƒSXdS(s!Returns a deepcopy of a function.N( ttypest FunctionTypet func_codet func_globalst__name__t func_defaultst func_closuretAttributeErrort__code__t __globals__t __defaults__t __closure__(tftname((s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pytcopyfuncs gñh㈵øä>g:Œ0âŽyE>cCsLxEt||ƒD]4\}}t||ƒ||t|ƒkstSqWtS(sÏReturns True if x and y are sufficiently close, elementwise. Parameters ---------- rtol : float The relative error tolerance. atol : float The absolute error tolerance. (tziptabstFalsetTrue(txtytrtoltatoltxityi((s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pytallclose"s $cCs"t||ƒ||t|ƒkS(sÂReturns True if x and y are sufficiently close. Parameters ---------- rtol : float The relative error tolerance. atol : float The absolute error tolerance. (R(RRRR ((s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pytclose4s sP 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]) csOtjjˆƒr'‡‡fd†}n$ttˆˆƒƒ‰‡fd†}|S(Ncs"|jˆˆƒ|jˆˆƒkS(N(tget(tdata1tdata2(tattrtdefault(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pytmatchcscst‡‡fd†ˆDƒƒS(Nc3s9|]/\}}ˆj||ƒˆj||ƒkVqdS(N(R%(t.0R(td(R&R'(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pys is(tall(R&R'(tattrs(R&R's‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*hs(tnxtutilstis_string_liketlistR(R(R)R*((R(R.R)s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyRas cOs t||ŽS(N(R(targstkwargs((s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyRsscsOtjjˆƒr'‡‡fd†}n$ttˆˆƒƒ‰‡fd†}|S(Ncsltg|jƒD]}|jˆˆƒ^qƒ}tg|jƒD]}|jˆˆƒ^qAƒ}||kS(N(tsettvaluesR%(t datasets1t datasets2tdatatvalues1tvalues2(R(R)(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*ys11cs¢tgƒ}x=|jƒD]/‰t‡fd†ˆDƒƒ}|j|ƒqWtgƒ}x=|jƒD]/‰t‡fd†ˆDƒƒ}|j|ƒqeW||kS(Nc3s'|]\}}ˆj||ƒVqdS(N(R%(R+R(R,(R&(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pys ƒsc3s'|]\}}ˆj||ƒVqdS(N(R%(R+R(R,(R'(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pys ‡s(R5R6ttupletadd(R7R8R:RR;(R.(R&R's‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*€s  (R/R0R1R2R(R(R)R*((R(R.R)s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyRws  tnodetedges 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'], [.25, .5]) cs[tjjˆƒr-‡‡‡‡fd†}n*ttˆˆƒƒ‰‡‡‡fd†}|S(Ncs1t|jˆˆƒ|jˆˆƒdˆdˆƒS(NRR (R$R%(R&R'(R R(R)R(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*¹scsogˆD]\}}|j||ƒ^q}gˆD]\}}|j||ƒ^q2}t||dˆdˆƒS(NRR (R%R#(R&R'R(R,R:R;(R R.R(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*Às++(R/R0R1R2R(R(R)RR R*((R R(R.R)Rs‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR·s cOs t||ŽS(N(R(R3R4((s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyRÍscs[tjjˆƒr-‡‡‡‡fd†}n*ttˆˆƒƒ‰‡‡‡fd†}|S(Ncs{tg|jƒD]}|jˆˆƒ^qƒ}tg|jƒD]}|jˆˆƒ^qAƒ}t||dˆdˆƒS(NRR (tsortedR6R%R#(R7R8R9R:R;(R R(R)R(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*Ós11csçg}x=|jƒD]/‰t‡fd†ˆDƒƒ}|j|ƒqWg}x=|jƒD]/‰t‡fd†ˆDƒƒ}|j|ƒqYW|jƒ|jƒx@t||ƒD]+\}}t||dˆdˆƒs°tSq°WtSdS(Nc3s'|]\}}ˆj||ƒVqdS(N(R%(R+R(R,(R&(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pys Ýsc3s'|]\}}ˆj||ƒVqdS(N(R%(R+R(R,(R'(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pys ásRR (R6R<tappendtsortRR#RR(R7R8R:RR;R!R"(R R.R(R&R's‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*Ús  (R/R0R1R2R(R(R)RR R*((R R(R.R)Rs‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyRÑs s 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 networkx.algorithms.isomorphism.matchhelpers import close >>> from networkx.algorithms.isomorphism import generic_node_match >>> nm = generic_node_match('weight', 1.0, close) >>> nm = generic_node_match('color', 'red', eq) >>> nm = generic_node_match(['weight', 'color'], [1.0, 'red'], [close, eq]) csUtjjˆƒr*‡‡‡fd†}n'ttˆˆˆƒƒ‰‡fd†}|S(Ncs%ˆ|jˆˆƒ|jˆˆƒƒS(N(R%(R&R'(R(R)top(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*scsMxFˆD]:\}}}||j||ƒ|j||ƒƒstSqWtSdS(N(R%RR(R&R'R(R,toperator(R.(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR* s'(R/R0R1R2R(R(R)RCR*((R(R.R)RCs‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyRs cOs t||ŽS(N(R(R3R4((s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR/scs[tjj|ƒr0|g}|g}ˆg‰ntt||ƒƒ‰‡‡fd†}|S(sqReturns 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 dgeattributes. 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 networkx.algorithms.isomorphism.matchhelpers import close >>> from networkx.algorithms.isomorphism import generic_node_match >>> nm = generic_node_match('weight', 1.0, close) >>> nm = generic_node_match('color', 'red', eq) >>> nm = generic_node_match(['weight', 'color'], ... [1.0, 'red'], ... [close, eq]) ... csñg}x=|jƒD]/‰t‡fd†ˆDƒƒ}|j|ƒqWg}x=|jƒD]/‰t‡fd†ˆDƒƒ}|j|ƒqYWx^t|ƒD]L}xCt||ƒD].\}}ttd„||ˆƒƒs¯Pq¯q¯WtSq™WtSdS(Nc3s'|]\}}ˆj||ƒVqdS(N(R%(R+R(R,(R&(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pys fsc3s'|]\}}ˆj||ƒVqdS(N(R%(R+R(R,(R'(s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pys jscSs |||ƒS(N((RRtz((s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pytns( R6R<RARRR-tmapRR(R7R8R:RR;tvals2R!R"(R.RC(R&R's‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR*cs(R/R0R1R2R(R(R)RCR*((R.RCs‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyR 3s*   (t__doc__t itertoolsRR tnetworkxR/t__all__tNoneRR#R$tcategorical_docRRtNotImplementedErrorRtreplacettmpdoct numerical_docRRRt generic_docRRR (((s‚/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/isomorphism/matchhelpers.pyts`    *      "    $    H