
    ёi2                       S SK Jr  S SKJrJrJrJr  S SKrS SKJr  SSK	J
r
Jr  SSKJr  SSKJr  SS	KJrJrJr  \(       a  S S
KJr  / r\" S5      r\SS j5       r\SS j5       rS r\SS j5       r\SS j5       rS r\ S       SS jj5       r\        SS j5       r\        SS j5       r SS jr S     SS jjrg)     )annotations)TYPE_CHECKINGAnyTypeVaroverloadN)_typing   )
check_typecheck_variable_and_dtype)in_pir_mode)Variable)LayerHelpercorein_dynamic_mode)SequenceTc                    g N arrays    S/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/tensor/array.pyarray_lengthr   #   s    +.    c                    g r   r   r   s    r   r   r   '   s    9<r   c                   [        5       (       a'  [        U [        5      (       d   S5       e[        U 5      $ [	        5       (       ah  [        U [
        R                  R                  5      (       a  U R                  5       (       d  [        S5      e[
        R                  R                  U 5      $ [        U [        5      (       a2  U R                  [        R                  R                   R"                  :w  a  [        S5      e[%        S
0 ['        5       D6nUR)                  SS9nSUl        UR-                  SSU /0SU/0S	9  U$ )a  
This OP is used to get the length of the input array.

Args:
    array (list|Tensor): The input array that will be used to compute the length. In dynamic mode, ``array`` is a Python list. But in static graph mode, array is a Tensor whose VarType is DENSE_TENSOR_ARRAY.

Returns:
    Tensor, 0-D Tensor with shape [], which is the length of array.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> arr = paddle.tensor.create_array(dtype='float32')
        >>> x = paddle.full(shape=[3, 3], fill_value=5, dtype="float32")
        >>> i = paddle.zeros(shape=[1], dtype="int32")

        >>> arr = paddle.tensor.array_write(x, i, array=arr)

        >>> arr_len = paddle.tensor.array_length(arr)
        >>> print(arr_len)
        1
9The 'array' in array_write must be a list in dygraph mode8array should be tensor array variable in array_length Opint64dtypeTlod_array_lengthXOuttypeinputsoutputs)r   )r   
isinstancelistlenr   paddlepirValueis_dense_tensor_array_type	TypeError_pir_opsr   r   r&   r   VarDescVarTypeDENSE_TENSOR_ARRAYr   locals"create_variable_for_type_inferencestop_gradient	append_op)r   helpertmps      r   r   r   +   s    2 %&& 	
G	
& 5z	5&**"2"2333355J  ++E22 5(++zzT\\11DDDJ  8vx877g7F #%>SEN 	 	

 
r   c                    g r   r   r   is     r   
array_readr>   f   s    7:r   c                    g r   r   r<   s     r   r>   r>   j   s    ILr   c                (   [        5       (       ae  [        U [        5      (       d   S5       e[        U[        5      (       d   S5       eUR                  S/:X  d   S5       eUR                  S5      nX   $ [        5       (       ah  [        U [        R                  R                  5      (       a  U R                  5       (       d  [        S5      e[        R                  R                  X5      $ [        USS/S	5        [        S0 [!        5       D6n[        U [        5      (       a2  U R"                  [$        R&                  R(                  R*                  :w  a  [        S
5      eUR-                  U R.                  S9nUR1                  SU /U/S.SU/0S9  U$ )a  
This OP is used to read data at the specified position from the input array.

Case:

.. code-block:: text

    Input:
        The shape of first three tensors are [1], and that of the last one is [1,2]:
            array = ([0.6], [0.1], [0.3], [0.4, 0.2])
        And:
            i = [3]

    Output:
        output = [0.4, 0.2]

Args:
    array (list|Tensor): The input array. In dynamic mode, ``array`` is a Python list. But in static graph mode, array is a Tensor whose ``VarType`` is ``DENSE_TENSOR_ARRAY``.
    i (Tensor): 1-D Tensor, whose shape is [1] and dtype is int64. It represents the
        specified read position of ``array``.

Returns:
    Tensor, A Tensor that is read at the specified position of ``array``.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> arr = paddle.tensor.create_array(dtype="float32")
        >>> x = paddle.full(shape=[1, 3], fill_value=5, dtype="float32")
        >>> i = paddle.zeros(shape=[1], dtype="int32")

        >>> arr = paddle.tensor.array_write(x, i, array=arr)

        >>> item = paddle.tensor.array_read(arr, i)
        >>> print(item.numpy())
        [[5. 5. 5.]]
z6The 'array' in array_read must be list in dygraph modez<The index 'i' in array_read must be Variable in dygraph mode   4The shape of index 'i' should be [1] in dygraph moder   r   r=   r   r>   %array should be tensor array variabler    read_from_arrayr#   Ir$   r%   )r>   )r   r)   r*   r   shapeitemr   r,   r-   r.   r/   r0   r1   r>   r   r   r5   r&   r   r2   r3   r4   r6   r!   r8   )r   r=   r9   outs       r   r>   r>   n   so   P %&& 	
D	
& !X&& 	
J	
& ww1#~ 	
B	
~ FF1Ix	5&**"2"2333355J  ))%33 C'LA6VX65(++zzT\\11DDDCDD77ekk7J"s+SEN 	 	

 
r   c                    g r   r   xr=   r   s      r   array_writerM      s     !$r   c                    g r   r   rK   s      r   rM   rM      s     r   c                    g r   r   rK   s      r   rM   rM      s     r   c                T   [        5       (       a  [        U [        5      (       d   S5       e[        U[        5      (       d   S5       eUR                  S/:X  d   S5       eUR	                  S5      nUc  [        U R                  5      n[        U[        5      (       d   S5       eU[        U5      ::  d   S5       eU[        U5      :  a  XU'   U$ UR                  U 5        U$ [        5       (       GaF  [        USS	/S
5        [        U [        R                  R                  5      (       d  [        S[!        U 5       S35      eUbI  [        U[        R                  R                  5      (       a  UR#                  5       (       d  [        S5      eUc)  [        R$                  R                  U R                  5      nUR                  [        R&                  R(                  R*                  R,                  :w  a   [        R.                  " XR                  5      n [        R$                  R1                  X U5        U$ [        USS	/S
5        [3        U S[        S
5        [5        S0 [7        5       D6nUbR  [        U[        5      (       a2  UR                   [8        R:                  R<                  R>                  :w  a  [        S5      eUcJ  URA                  URB                   S3[8        R:                  R<                  R>                  U R                  S9nURE                  SU /U/S.SU/0S9  U$ )a  
This OP writes the input ``x`` into the i-th position of the ``array`` returns the modified array.
If ``array`` is none, a new array will be created and returned.

Args:
    x (Tensor): The input data to be written into array. It's multi-dimensional
        Tensor. Data type: float32, float64, int32, int64 and bool.
    i (Tensor): 0-D Tensor with shape [], which represents the position into which
        ``x`` is written.
    array (list|Tensor, optional): The array into which ``x`` is written. The default value is None,
        when a new array will be created and returned as a result. In dynamic mode, ``array`` is a Python list.
        But in static graph mode, array is a Tensor whose ``VarType`` is ``DENSE_TENSOR_ARRAY``.

Returns:
    list|Tensor, The input ``array`` after ``x`` is written into.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> arr = paddle.tensor.create_array(dtype="float32")
        >>> x = paddle.full(shape=[1, 3], fill_value=5, dtype="float32")
        >>> i = paddle.zeros(shape=[1], dtype="int32")

        >>> arr = paddle.tensor.array_write(x, i, array=arr)

        >>> item = paddle.tensor.array_read(arr, i)
        >>> print(item.numpy())
        [[5. 5. 5.]]
zBThe input data 'x' in array_write must be Variable in dygraph modez=The index 'i' in array_write must be Variable in dygraph moderA   rB   r   r   zNThe index 'i' should not be greater than the length of 'array' in dygraph moder=   r   rM   z$x should be pir.Value, but received .rC   rL   z7array should be tensor array variable in array_write Op.outnamer&   r!   write_to_arrayrE   r$   r%   )rM   )#r   r)   r   rG   rH   create_arrayr!   r*   r+   appendr   r   r,   r-   r.   r0   r&   r/   r1   base	libpaddleDataType	UNDEFINEDcastarray_write_r
   r   r5   r   r2   r3   r4   create_variablerT   r8   )rL   r=   r   r9   s       r   rM   rM      s   H !X&& 	
P	
& !X&& 	
K	
& ww1#~ 	
B	
~ FF1I= )E%&& 	
G	
& CJ 	
\	
 s5z>!H  LLO	 C'MB!VZZ--..B47)1MNNufjj&6&6777799 GHH=OO009E;;&++//88BBBA{{+A$$Uq1 C'MB1cH}57fh7uh//::!5!5!H!HHM  =**}D)\\))<<gg + E
 	!A3'UG$ 	 	

 r   c                D   / nUb=  [        U[        [        45      (       d  [        S[	        U5       35      e[        U5      nU HJ  n[        U[
        [        R                  R                  45      (       a  M4  [        S[	        U5       S35      e   [        5       (       a  U$ [        5       (       a  [        U [        R                  R                  [        R                  45      (       d)  [        R                  R                   R#                  U 5      n [        R$                  R'                  U 5      nU Ht  nU [        R                  R(                  R                  R*                  :w  a  [        R,                  " X05      n[        R$                  R/                  XC[1        U5      5        Mv     U$ [3        S0 [5        5       D6nUR7                  UR8                   S3[        R                  R                  R:                  U S9nU H  n[=        U[1        U5      US9  M     U$ )a  
This OP creates an array. It is used as the input of :ref:`api_paddle_tensor_array_array_read` and
:ref:`api_paddle_tensor_array_array_write`.

Args:
    dtype (str): The data type of the elements in the array. Support data type: float32, float64, int32, int64 and bool.
    initialized_list(list): Used to initialize as default value for created array.
                All values in initialized list should be a Tensor.

Returns:
    list|Tensor, An empty array. In dynamic mode, ``array`` is a Python list. But in static graph mode, array is a Tensor
    whose ``VarType`` is ``DENSE_TENSOR_ARRAY``.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> arr = paddle.tensor.create_array(dtype="float32")
        >>> x = paddle.full(shape=[1, 3], fill_value=5, dtype="float32")
        >>> i = paddle.zeros(shape=[1], dtype="int32")

        >>> arr = paddle.tensor.array_write(x, i, array=arr)

        >>> item = paddle.tensor.array_read(arr, i)
        >>> print(item.numpy())
        [[5. 5. 5.]]

zBRequire type(initialized_list) should be list/tuple, but received zOAll values in `initialized_list` should be Variable or pir.Value, but received rQ   rR   rS   rK   r   )r)   r*   tupler0   r&   r   r,   r-   r.   r   r   r   r2   r3   rZ   rX   	frameworkconvert_np_dtype_to_dtype_r1   rV   rY   r[   r\   r]   r   r   r5   r^   rT   r4   rM   )r!   initialized_listr   valrI   r9   tensor_arrays          r   rV   rV   5  s   B E#*T5M::TUYZjUkTlm  %& #&***:*:;<<abfgjbkallmn   	%$,,"6"6!FGGKK))DDUKEoo**51C--66@@@kk#-OO((<3DE  
11&,&<&<KK=%%%88 '= '
 C#l!;<P  r   )r   z	list[Any]returnint)r   paddle.Tensorrf   rh   )r   zlist[T]r=   rh   rf   r   )r   rh   r=   rh   rf   rh   r   )rL   rh   r=   rh   r   Nonerf   zlist[Any] | paddle.Tensor)rL   rh   r=   rh   r   list[paddle.Tensor]rf   rj   )rL   rh   r=   rh   r   rh   rf   rh   )r!   z_typing.DTypeLikerc   zSequence[paddle.Tensor] | Nonerf   z#paddle.Tensor | list[paddle.Tensor])
__future__r   typingr   r   r   r   r,   r   base.data_feederr
   r   base.frameworkr   common_ops_importr   ra   r   r   r   collections.abcr   __all__r   r   r>   rM   rV   r   r   r   <module>rr      sY    # 8 8   C ( ( : :(
CL 
 . 
 . 
 < 
 <8v 
 : 
 : 
 L 
 LK\ 
6:$$&$/3$$ 
$
 
&/B 

 
&/< 
 dR 8<FF4F )Fr   