
    ёiS2                    ^   S SK Jr  S SKJrJr  S SKrS SKrS SKJrJ	r	  S SK
Jr  S SKJrJrJrJrJr  S SKJr  S SKJrJr  \(       a  S SKJr  S S	KJrJrJrJr  S S
KJrJrJ r   SS/r!S r"S r#S r$S r%    S             SS jjr&S r'\    S               SS jj5       r(g)    )annotations)TYPE_CHECKINGAnyN)_C_opsin_dynamic_mode)convert_dtype)_current_expected_place_get_paddle_placecoredygraph_onlyin_pir_mode)LayerHelper)max	to_tensor)CPUPlaceCUDAPinnedPlace	CUDAPlaceTensor)	DTypeLikeNumericSequence	ShapeLikesparse_coo_tensorsparse_csr_tensorc                    U(       a<  [        U5      [        U R                  5      :w  a  U R                  [        U5      5      $ U $ )N)r   dtypeastype)datar   s     V/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/sparse/creation.py_handle_dtyper   .   s4    =#<<;;}U344K    c                   [        U R                  5      S:X  d   e[        U SS9nUS-   nUR                  5       n[        UR                  5      S:  a#  [        R
                  " X!R                  SS  5      n[        U5      $ )N      )axis)lenshaper   numpynpappendlist)indicesvalueslenss      r   _infer_dense_shaper.   5   sm    w}}"""wQD!8D::<D
6<<1yy||AB/0:r    c                    [        U 5      n U c  [        5       n U $ [        U [        R                  [        R
                  [        R                  [        R                  45      (       d  [        S5      eU $ )Nz^'place' must be any of paddle.Place, paddle.CPUPlace, paddle.CUDAPinnedPlace, paddle.CUDAPlace)	r
   r	   
isinstancer   Placer   r   r   
ValueError)places    r   
_get_placer4   ?   sh    e$E}') L 

DMM4+?+?P  l
 	
 Lr    c                    U [         R                  [         R                  [         R                  [         R                  4;  a  [        S5      eg )NzDthe dtype of indices must be 'int8' or 'int16' or 'int32' or 'int64')paddleint8int16int32int64	TypeError)r   s    r   _check_indices_dtyper<   L   s9    V[[&,,fllKKR
 	
 Lr    c           
        [        5       (       Ga   [        U5      n[        U [        R                  R
                  5      (       d  [        U SUSS9n [        U[        R                  R
                  5      (       d  [        XXE5      n[        U R                  5      S:w  a  [        S5      eU R                  S   nU R                  S   n[        U R                  5        XaR                  S   :w  a  [        SU S	UR                  S    35      e[        UR                  5      S-
  nU R                  R                  U5      (       d  U R                  US
5      n UR                  R                  U5      (       d  UR                  US
5      n[        X5      nXQl        [#        X5      n	Uc  U	nOO[%        U5      nX):  a  [        SU	 SU 35      e[        U5      Xx-   :w  a  [        SU SU S[        U5       35      e[&        R(                  " XU5      $ [+        5       (       a  [&        R(                  " XU5      $ Sn
XS.nUS   c  SUS'   SU0n[-        U
5      nUR/                  U5      nUR1                  XSU0US9  U$ )a  
Constructs a sparse ``paddle.Tensor`` in coordinate format according to the indices
and values of the specified non-zero elements.

Args:
    indices(list|tuple|ndarray|Tensor): the indices of non-zero elements.
        Can be a list, tuple, numpy\.ndarray, paddle\.Tensor. The indices must be 2-D.
    values(list|tuple|ndarray|Tensor): Initial values for the tensor.
        Can be a scalar, list, tuple, numpy\.ndarray, paddle\.Tensor.
    shape(list|tuple|None, optional): The shape of the sparse tensor also represents the shape of
        original dense tensor. If not provided the smallest shape will be inferred to
        hold all elements.
    dtype(str|paddle.dtype|np.dtype, optional): The desired data type of returned tensor. Can be 'bool' , 'float16' ,
        'float32' , 'float64' , 'int8' , 'int16' , 'int32' , 'int64' , 'uint8',
        'complex64' , 'complex128'. Default: None, infers dtype from ``data``
        except for python float number which gets dtype from ``get_default_type`` .
    place(CPUPlace|CUDAPinnedPlace|CUDAPlace|str|None, optional): The place to allocate Tensor. Can be
        CPUPlace, CUDAPinnedPlace, CUDAPlace. Default: None, means global place. If ``place`` is
        string, It can be ``cpu``, ``gpu:x`` and ``gpu_pinned``, where ``x`` is the index of the GPUs.
    stop_gradient(bool, optional): Whether to block the gradient propagation of Autograd. Default: True.

Returns:
    Tensor: A Tensor constructed from ``indices`` and ``values`` .

Examples:

    .. code-block:: python

        >>> import paddle

        >>> indices = [[0, 1, 2], [1, 2, 0]]
        >>> values = [1.0, 2.0, 3.0]
        >>> dense_shape = [3, 3]
        >>> coo = paddle.sparse.sparse_coo_tensor(indices, values, dense_shape)
        >>> print(coo)
        Tensor(shape=[3, 3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
               indices=[[0, 1, 2],
                        [1, 2, 0]],
               values=[1., 2., 3.])
NTr   r3   stop_gradientr"   z'indices' must be 2-D.r#   r   zBthe indices and values must have same number of non-zero, but get z and Fzthe minimum shape required is z
, but get z7the number of dimensions(len(shape) must be sparse_dim(z) + dense_dim(z), but get sparse_sparse_coo_tensor)r,   r+   r&   out)typeinputsoutputsattrs)r   r4   r0   r   eagerr   r   r%   r&   r2   r<   r   r3   _equals_copy_tor   r?   r.   r*   r   rA   r   r   )create_sparse_variable_for_type_inference	append_op)r+   r,   r&   r   r3   r?   nnz
sparse_dim	dense_dim	min_shapeop_typerD   rF   helperrB   s                  r   r   r   S   s   l 5!'4::#4#455t5G &$**"3"344veCFw}}"566mmA]]1%
W]]+,,q/!TUXTYY^_e_k_klm_n^op  %)	}}$$U++&&ue4G||##E**__UE2Fv-,&w7	=EKE  4YKz%Q  5zZ33 Mj\Yghqgrr}  B  CH  I  ~J  K  ..vFF	..vFF -"78E!H% W%>>uE%U 	 	
 
r    c                f   U R                  5       nUR                  5       n[        R                  " US S USS  :  5      S-   n[        [	        U5      U-  5      U-  [	        U5      :w  a  [        SU S35      eUR                  5       S-   n[        [	        U5      U-  5      S-
  nUS:X  a  Xe/$ XFU/$ )Nr@   r#   z-The calculated original matrix batch size is za, but it cannot correctly split the row data. Please carefully check the data or the input shape.)r'   r(   sumintr%   r2   r   )crowscolscrows_numpy
cols_numpybatchscolrows          r   _infer_dense_csr_shaper\      s    ++-KJVVK${1267!;FCv%&/C4DD;F8  De  f
 	
 ..
Q
C
c+'
(1
,C{zS!!r    c                (   [        U5      n[        U [        R                  R                  5      (       d  [        U SUSS9n [        U[        R                  R                  5      (       d  [        USUSS9n[        U[        R                  R                  5      (       d  [        X$XV5      n[        U R                  5        [        UR                  5        Ub-  [        U5      S:w  a  [        U5      S:w  a  [        SU 35      eO[        X5      nU[        U5      S-
     nU R                  R                  U5      (       d  U R                  US5      n UR                  R                  U5      (       d  UR                  US5      nUR                  R                  U5      (       d  UR                  US5      n[        X$5      nXbl        [        U R                   5      S:w  d2  [        UR                   5      S:w  d  [        UR                   5      S:w  a  [        S	5      e[        U5      [        U5      :w  a  [        S
5      e[        U5      S:X  ak  U R                   S   US-   :w  a  [        SU R                   S    SU S35      eU S   S:w  a  [        S5      eU S   UR                   S   :w  a  [        S5      eO8U R                   S   US-   -  S:w  a  [        SU R                   S    SU S35      e[        R                  R#                  XX#U5      $ )a  
Constructs a sparse ``paddle.Tensor`` in CSR(Compressed Sparse Row) format according to the
``crows``, ``cols`` and ``values``.
Currently, the crows and cols of each batch must be incremented.

Args:
    crows(list|tuple|ndarray|Tensor): 1-D array, each element in the rows represents the
        starting position of the first non-zero element of each row in values.
        Can be a list, tuple, numpy\.ndarray, paddle\.Tensor.
    cols(list|tuple|ndarray|Tensor): 1-D array, the column of non-zero elements.
        Can be a list, tuple, numpy\.ndarray, paddle\.Tensor.
    values(list|tuple|ndarray|Tensor): 1-D array, the non-zero elements.
        Can be a scalar, list, tuple, numpy\.ndarray, paddle\.Tensor.
    shape(list|tuple, optional): The shape of the sparse tensor also represents the shape of
        original dense tensor.
        hold all elements.
    dtype(str|paddle.dtype|np.dtype, optional): The desired data type of returned tensor. Can be 'bool' , 'float16' ,
        'float32' , 'float64' , 'int8' , 'int16' , 'int32' , 'int64' , 'uint8',
        'complex64' , 'complex128'. Default: None, infers dtype from ``data``
        except for python float number which gets dtype from ``get_default_type`` .
    place(CPUPlace|CUDAPinnedPlace|CUDAPlace|str|None, optional): The place to allocate Tensor. Can be
        CPUPlace, CUDAPinnedPlace, CUDAPlace. Default: None, means global place. If ``place`` is
        string, It can be ``cpu``, ``gpu:x`` and ``gpu_pinned``, where ``x`` is the index of the GPUs.
    stop_gradient(bool, optional): Whether to block the gradient propagation of Autograd. Default: True.

Returns:
    Tensor: A Tensor constructed from ``crows``, ``cols`` and ``values`` .

Examples:

    .. code-block:: python

        >>> import paddle

        >>> crows = [0, 2, 3, 5]
        >>> cols = [1, 3, 2, 0, 1]
        >>> values = [1, 2, 3, 4, 5]
        >>> dense_shape = [3, 4]
        >>> csr = paddle.sparse.sparse_csr_tensor(crows, cols, values, dense_shape)
        >>> print(csr)
        Tensor(shape=[3, 4], dtype=paddle.int64, place=Place(cpu), stop_gradient=True,
               crows=[0, 2, 3, 5],
               cols=[1, 3, 2, 0, 1],
               values=[1, 2, 3, 4, 5])
NTr>   r"      z>SparseCsrTensor only support 2-D or 3-D matrix. but get shape Fr#   z-The 'crows', 'cols' and 'values' must be 1-D.z3the length of cols must be same as length of valuesr   zThe length(z%) of crows must be equal to the rows(z)+1 of matrix.z the 0th value of crows must be 0r@   z<the last value of crows must be equal the number of non-zeroz&) of crows must be divisible the rows()r4   r0   r   rG   r   r   r<   r   r%   r2   r\   r3   rH   rI   r   r?   r&   r   )rU   rV   r,   r&   r   r3   r?   rowss           r   r   r      s   p uEeTZZ..//%t5MdDJJ--..TdKfdjj//006%?%$u:?s5zQPQVPWX  'u3Ua D;;u%%ue,::e$$}}UE*<<&&.6)F(
5;;1DJJ1 4FLL8IQ8NHII
4yCKNOO
5zQ;;q>TAX%ekk!n--RSWRXXfg  8q=?@@9Q'N  (
 ;;q>TAX&!+ekk!n--STXSYYgh 
 ::''VM r    )NNNT)r+   zMlist[list[int]] | tuple[tuple[int, ...], ...] | npt.NDArray[np.int_] | Tensorr,   +NumericSequence | npt.NDArray[Any] | Tensorr&   ShapeLike | Noner   DTypeLike | Noner3   3CPUPlace | CUDAPinnedPlace | CUDAPlace | str | Noner?   boolreturnr   )rU   ;list[int] | tuple[int, ...] | npt.NDArray[np.int_] | TensorrV   rf   r,   r`   r&   ra   r   rb   r3   rc   r?   rd   re   r   ))
__future__r   typingr   r   r'   r(   r6   r   r   paddle.base.data_feederr   paddle.base.frameworkr	   r
   r   r   r   paddle.base.layer_helperr   paddle.tensorr   r   numpy.typingnptr   r   r   r   paddle._typingr   r   r   __all__r   r.   r4   r<   r   r\   r    r    r   <module>rr      s?   # %   * 1  1 (CCDD 

 #"AEt	t 8t t t ?t t tn"" 
 #"AEsFs
Es 8s 	s
 s ?s s s sr    