
    `i                         d dl Z d dlZ	 d dlZdZn# e$ r dZY nw xY w	 	 ddZ e j        dddd	          Z e j        d
ddd          Z	dS )    NTFweakc           	         t           st          d          |                                }|dvrt          d          |sd}| j        dk    rt          d          t
          j        j                            |           s$t
          j        j        	                    |           } | j
        \  }}||k    rt          d          | j        dk    r"|t          j        || j        j        	          fS |d
k    rJt          j        || j        j        	          }t#          j        | j        | j        d|| j        |           nz| | j        z  } t
          j        j                            |           s$t
          j        j        	                    |           } t#          j        dd| j        | j        ddd          \  }}t          j        d| j        j        	          }t          j        |f| j        j        	          }	t/          |||	|           t1          |d                   }
|s|
S t3          |
t          j        |	d|
                   |           |
|fS )aV  Analyzes the connected components of a sparse graph

    Args:
        csgraph (cupy.ndarray of cupyx.scipy.sparse.csr_matrix): The adjacency
            matrix representing connectivity among nodes.
        directed (bool): If ``True``, it operates on a directed graph. If
            ``False``, it operates on an undirected graph.
        connection (str): ``'weak'`` or ``'strong'``. For directed graphs, the
            type of connection to use. Nodes i and j are "strongly" connected
            only when a path exists both from i to j and from j to i.
            If ``directed`` is ``False``, this argument is ignored.
        return_labels (bool): If ``True``, it returns the labels for each of
            the connected components.

    Returns:
        tuple of int and cupy.ndarray, or int:
            If ``return_labels`` == ``True``, returns a tuple ``(n, labels)``,
            where ``n`` is the number of connected components and ``labels`` is
            labels of each connected components. Otherwise, returns ``n``.

    .. seealso:: :func:`scipy.sparse.csgraph.connected_components`
    zpylibcugraph is not available)r   strongz%connection must be 'weak' or 'strong'r      z graph should have two dimensionszgraph should be a square arrayr   )dtyper   N)offsetsindicesweights	num_verts	num_edgeslabelsF)resource_handlegraphr	   r   r
   r   do_expensive_check)   )size)pylibcugraph_availableRuntimeErrorlower
ValueErrorndimcupyxscipysparseisspmatrix_csr
csr_matrixshapennzcupyaranger	   r   emptypylibcugraphstrongly_connected_componentsindptrTweakly_connected_componentszeros_cupy_count_componentsint_cupy_adjust_labelssort)csgraphdirected
connectionreturn_labelsmm1r   _countroot_labelsns              y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/sparse/csgraph/_traversal.pyconnected_componentsr7   
   sU   0 " <:;;;!!##J+++@AAA 
|q;<<<;,,W55 9+$//88MEArBww9:::{a$+aw'<=====XAW_%:;;;2NGOT7;v	? 	? 	? 	? 	? 	79{!0099 	=k(33G<<G < ON$
 
 
	6 Jt7?#8999E*aT)>???K65+A>>>>E!HA 49[!_55v>>>f9     z4raw I labels, raw int32 count, raw int32 root_labelsz
    int j = i;
    while (j != labels[j]) { j = labels[j]; }
    if (j != i) {
        labels[i] = j;
    } else {
        int k = atomicAdd(&count[0], 1);
        root_labels[k] = i;
    }
    r(   z&int32 n_root_labels, raw I root_labelszI labelsav  
    int cur_label = labels;
    int j_min = 0;
    int j_max = n_root_labels - 1;
    int j = (j_min + j_max) / 2;
    while (j_min < j_max) {
        if (cur_label == root_labels[j]) break;
        if (cur_label < root_labels[j]) {
            j_max = j - 1;
        } else {
            j_min = j + 1;
        }
        j = (j_min + j_max) / 2;
    }
    labels = j;
    r*   )Tr   T)
r   cupyx.scipy.sparser   r"   r   ModuleNotFoundErrorr7   ElementwiseKernelr(   r*    r8   r6   <module>r>      s        #! # # #"# =C'+G G G GT 0/:	     -d,,  '    s    