ó
    Î‘®i„9  ã                  ó*  • S SK Jr  S SKJrJrJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  \(       a  S SKJr  / r\     S                 SS jj5       r\     S                 SS	 jj5       r\     S                 SS
 jj5       r     SS jr\    S                 SS jj5       r\    S                 SS jj5       r\    S                 SS jj5       r    SS jrg)é    )Úannotations)ÚTYPE_CHECKINGÚLiteralÚoverload)Ú_C_ops)Úcheck_variable_and_dtype)ÚLayerHelper)Úin_dynamic_or_pir_mode)ÚTensorc                ó   • g ©N© ©ÚrowÚcolptrÚinput_nodesÚsample_sizeÚeidsÚreturn_eidsÚperm_bufferÚnames           Úc/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/geometric/sampling/neighbors.pyÚsample_neighborsr      ó   € ð %(ó    c                ó   • g r   r   r   s           r   r   r   *   ó   € ð  r   c                ó   • g r   r   r   s           r   r   r   7   ó   € ð =@r   Nc           
     óš  • U(       a  Uc  [        S5      eUb  SOSn[        5       (       a/  [        R                  " U UUUUUUU5      u  n	n
nU(       a  XšU4$ Xš4$ [	        U SSS5        [	        USSS5        [	        US	SS5        U(       a  [	        US
SS5        U(       a  [	        USSS5        [        S0 [        5       D6nUR                  U R                  S9n	UR                  U R                  S9n
UR                  U R                  S9nUR                  SU UUU(       a  UOSU(       a  UOSS.U	U
US.UUUS.S9  U(       a  XšU4$ Xš4$ )a¤  

Graph Sample Neighbors API.

This API is mainly used in Graph Learning domain, and the main purpose is to
provide high performance of graph sampling method. For example, we get the
CSC(Compressed Sparse Column) format of the input graph edges as `row` and
`colptr`, so as to convert graph data into a suitable format for sampling.
`input_nodes` means the nodes we need to sample neighbors, and `sample_sizes`
means the number of neighbors and number of layers we want to sample.

Besides, we support fisher-yates sampling in GPU version.

Args:
    row (Tensor): One of the components of the CSC format of the input graph, and
                  the shape should be [num_edges, 1] or [num_edges]. The available
                  data type is int32, int64.
    colptr (Tensor): One of the components of the CSC format of the input graph,
                     and the shape should be [num_nodes + 1, 1] or [num_nodes + 1].
                     The data type should be the same with `row`.
    input_nodes (Tensor): The input nodes we need to sample neighbors for, and the
                          data type should be the same with `row`.
    sample_size (int, optional): The number of neighbors we need to sample. Default value is -1,
                       which means returning all the neighbors of the input nodes.
    eids (Tensor, optional): The eid information of the input graph. If return_eids is True,
                        then `eids` should not be None. The data type should be the
                        same with `row`. Default is None.
    return_eids (bool, optional): Whether to return eid information of sample edges. Default is False.
    perm_buffer (Tensor, optional): Permutation buffer for fisher-yates sampling. If `use_perm_buffer`
                          is True, then `perm_buffer` should not be None. The data type should
                          be the same with `row`. If not None, we will use fiser-yates sampling
                          to speed up. Only useful for gpu version. Default is None.
    name (str, optional): Name for the operation (optional, default is None).
                          For more information, please refer to :ref:`api_guide_Name`.

Returns:
    - out_neighbors (Tensor), the sample neighbors of the input nodes.

    - out_count (Tensor), the number of sampling neighbors of each input node, and the shape
      should be the same with `input_nodes`.

    - out_eids (Tensor), if `return_eids` is True, we will return the eid information of the
      sample edges.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> # edges: (3, 0), (7, 0), (0, 1), (9, 1), (1, 2), (4, 3), (2, 4),
        >>> #        (9, 5), (3, 5), (9, 6), (1, 6), (9, 8), (7, 8)
        >>> row = [3, 7, 0, 9, 1, 4, 2, 9, 3, 9, 1, 9, 7]
        >>> colptr = [0, 2, 4, 5, 6, 7, 9, 11, 11, 13, 13]
        >>> nodes = [0, 8, 1, 2]
        >>> sample_size = 2
        >>> row = paddle.to_tensor(row, dtype="int64")
        >>> colptr = paddle.to_tensor(colptr, dtype="int64")
        >>> nodes = paddle.to_tensor(nodes, dtype="int64")
        >>> out_neighbors, out_count = paddle.geometric.sample_neighbors(row, colptr, nodes, sample_size=sample_size, return_eids=False)

Nú3`eids` should not be None if `return_eids` is True.TFÚRow©Úint32Úint64Úgraph_sample_neighborsÚCol_PtrÚXÚEidsÚPerm_Buffer©Údtype)r"   r'   r(   r)   r*   )ÚOutÚ	Out_CountÚOut_Eids)r   r   Úflag_perm_buffer©ÚtypeÚinputsÚoutputsÚattrs)r   )
Ú
ValueErrorr
   r   r&   r   r	   ÚlocalsÚ"create_variable_for_type_inferencer,   Ú	append_op)r   r   r   r   r   r   r   r   Úuse_perm_bufferÚout_neighborsÚ	out_countÚout_eidsÚhelpers                r   r   r   D   s²  € öP Ø‰<ÜØEóð ð *Ñ5‘d¸5€Oä×Ñô
 ×)Ò)ØØØØØØØØó	
ñ		
ØØØö Ø ¨XÐ5Ð5ØÐ'Ð'äØˆUÐ&Ð(@ôô Ø	Ð-Ð/Gôô ØSÐ,Ð.Fôö Ü Ø&Ð,Ð.Fô	
ö Ü ØØØØ$ô		
ô Ñ8¬v«xÑ8€FØ×=Ñ=ÀCÇIÁIÐ=ÐN€MØ×9Ñ9ÀÇ	Á	Ð9ÐJ€IØ×8Ñ8¸s¿y¹yÐ8ÐI€HØ
×ÑØ%àØØÞ'‘D¨TÞ*9™;¸tñ
ð !Ø"Ø ñ
ð 'Ø&Ø /ñ
ð ñ ö( Ø¨Ð1Ð1ØÐ#Ð#r   c                ó   • g r   r   ©r   r   Úedge_weightr   r   r   r   r   s           r   Úweighted_sample_neighborsrB   Ù   r   r   c                ó   • g r   r   r@   s           r   rB   rB   æ   r   r   c                ó   • g r   r   r@   s           r   rB   rB   ó   r   r   c           	     óh  • U(       a  Uc  [        S5      e[        5       (       a.  [        R                  " U UUUUUU5      u  nn	n
U(       a  X‰U
4$ X‰4$ [	        U SSS5        [	        USSS5        [	        USSS5        [	        US	SS5        U(       a  [	        US
SS5        [        S0 [        5       D6nUR                  U R                  S9nUR                  U R                  S9n	UR                  U R                  S9n
UR                  SU UUUU(       a  UOSS.UU	U
S.UUS.S9  U(       a  X‰U
4$ X‰4$ )a  
Graph Weighted Sample Neighbors API.

This API is mainly used in Graph Learning domain, and the main purpose is to
provide high performance of graph weighted-sampling method. For example, we get the
CSC(Compressed Sparse Column) format of the input graph edges as `row` and
`colptr`, so as to convert graph data into a suitable format for sampling, and the
input `edge_weight` should also match the CSC format. Besides, `input_nodes` means
the nodes we need to sample neighbors, and `sample_sizes` means the number of neighbors
and number of layers we want to sample. This API will finally return the weighted sampled
neighbors, and the probability of being selected as a neighbor is related to its weight,
with higher weight and higher probability.

Args:
    row (Tensor): One of the components of the CSC format of the input graph, and
                  the shape should be [num_edges, 1] or [num_edges]. The available
                  data type is int32, int64.
    colptr (Tensor): One of the components of the CSC format of the input graph,
                     and the shape should be [num_nodes + 1, 1] or [num_nodes + 1].
                     The data type should be the same with `row`.
    edge_weight (Tensor): The edge weight of the CSC format graph edges. And the shape
                          should be [num_edges, 1] or [num_edges]. The available data
                          type is float32.
    input_nodes (Tensor): The input nodes we need to sample neighbors for, and the
                          data type should be the same with `row`.
    sample_size (int, optional): The number of neighbors we need to sample. Default value is -1,
                       which means returning all the neighbors of the input nodes.
    eids (Tensor, optional): The eid information of the input graph. If return_eids is True,
                        then `eids` should not be None. The data type should be the
                        same with `row`. Default is None.
    return_eids (bool, optional): Whether to return eid information of sample edges. Default is False.
    name (str, optional): Name for the operation (optional, default is None).
                          For more information, please refer to :ref:`api_guide_Name`.

Returns:
    - out_neighbors (Tensor), the sample neighbors of the input nodes.

    - out_count (Tensor), the number of sampling neighbors of each input node, and the shape
      should be the same with `input_nodes`.

    - out_eids (Tensor), if `return_eids` is True, we will return the eid information of the
      sample edges.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> # edges: (3, 0), (7, 0), (0, 1), (9, 1), (1, 2), (4, 3), (2, 4),
        >>> #        (9, 5), (3, 5), (9, 6), (1, 6), (9, 8), (7, 8)
        >>> row = [3, 7, 0, 9, 1, 4, 2, 9, 3, 9, 1, 9, 7]
        >>> colptr = [0, 2, 4, 5, 6, 7, 9, 11, 11, 13, 13]
        >>> weight = [0.1, 0.5, 0.2, 0.5, 0.9, 1.9, 2.0, 2.1, 0.01, 0.9, 0,12, 0.59, 0.67]
        >>> nodes = [0, 8, 1, 2]
        >>> sample_size = 2
        >>> row = paddle.to_tensor(row, dtype="int64")
        >>> colptr = paddle.to_tensor(colptr, dtype="int64")
        >>> weight = paddle.to_tensor(weight, dtype="float32")
        >>> nodes = paddle.to_tensor(nodes, dtype="int64")
        >>> out_neighbors, out_count = paddle.geometric.weighted_sample_neighbors(
        ...     row, colptr, weight, nodes, sample_size=sample_size, return_eids=False
        ... )

Nr!   r   r#   rB   r   rA   Úfloat32r   r   r+   )r   r   rA   r   r   )r;   r<   r=   )r   r   r1   )rB   )
r6   r
   r   rB   r   r	   r7   r8   r,   r9   )r   r   rA   r   r   r   r   r   r;   r<   r=   r>   s               r   rB   rB      sš  € öV Ø‰<ÜØEóð ô ×Ñô
 ×,Ò,ØØØØØØØó
ñ		
ØØØö Ø ¨XÐ5Ð5ØÐ'Ð'äØˆUÐ&Ð(Côô ØÐ,Ð.Iôô ØØØ	Ø#ô	ô ØØØØ#ô	ö Ü Ø&Ð,Ð.Iô	
ô ÑA¼»ÑA€FØ×=Ñ=ÀCÇIÁIÐ=ÐN€MØ×9Ñ9ÀÇ	Á	Ð9ÐJ€IØ×8Ñ8¸s¿y¹yÐ8ÐI€HØ
×ÑØ(àØØ&Ø&Þ'‘D¨Tñ
ð +Ø"Ø ñ
ð 'Ø&ñ
ð ñ ö& Ø¨Ð1Ð1ØÐ#Ð#r   ).....)r   r   r   r   r   r   r   Úintr   úTensor | Noner   úLiteral[True]r   rH   r   ú
str | NoneÚreturnútuple[Tensor, Tensor, Tensor])r   r   r   r   r   r   r   rG   r   rH   r   úLiteral[False]r   rH   r   rJ   rK   útuple[Tensor, Tensor])r   r   r   r   r   r   r   rG   r   rH   r   Úboolr   rH   r   rJ   rK   ú5tuple[Tensor, Tensor] | tuple[Tensor, Tensor, Tensor])éÿÿÿÿNFNN)....)r   r   r   r   rA   r   r   r   r   rG   r   rH   r   rI   r   rJ   rK   rL   )r   r   r   r   rA   r   r   r   r   rG   r   rH   r   rM   r   rJ   rK   rN   )r   r   r   r   rA   r   r   r   r   rG   r   rH   r   rO   r   rJ   rK   rP   )rQ   NFN)Ú
__future__r   Útypingr   r   r   Úpaddler   Úpaddle.base.data_feederr   Úpaddle.base.layer_helperr	   Úpaddle.frameworkr
   r   Ú__all__r   rB   r   r   r   Ú<module>rY      sB  ðõ #ç 3Ñ 3å Ý <Ý 0Ý 3æÝØ
€ð 
ð
 ØØ!$Ø!$Øð	(Ø	ð	(àð	(ð ð	(ð ð		(ð
 ð	(ð ð	(ð ð	(ð ð	(ð #ô	(ó 
ð	(ð 
ð
 ØØ"%Ø!$Øð	 Ø	ð	 àð	 ð ð	 ð ð		 ð
 ð	 ð  ð	 ð ð	 ð ð	 ð ô	 ó 
ð	 ð 
ð
 ØØØ!$Øð	@Ø	ð	@àð	@ð ð	@ð ð		@ð
 ð	@ð ð	@ð ð	@ð ð	@ð ;ô	@ó 
ð	@ð  Ø	ØØØ	ôR$ðj 
ð ØØ!$Øð	(Ø	ð	(àð	(ð ð	(ð ð		(ð
 ð	(ð ð	(ð ð	(ð ð	(ð #ô	(ó 
ð	(ð 
ð ØØ"%Øð	 Ø	ð	 àð	 ð ð	 ð ð		 ð
 ð	 ð ð	 ð  ð	 ð ð	 ð ô	 ó 
ð	 ð 
ð ØØØð	@Ø	ð	@àð	@ð ð	@ð ð		@ð
 ð	@ð ð	@ð ð	@ð ð	@ð ;ô	@ó 
ð	@ð" Ø	ØØ	õS$r   