
    ёi]>                    T   S SK Jr  S SKrS SKJrJr  S SKrS SKJr	  S SK
J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  S SKJr  S S	KJr  S S
KJrJr  SSKJr  \(       a  S SKJr  S SK J!r!J"r"J#r#J$r$J%r%  / r&SS jr'\  S         SS jj5       r( " S S5      r)        SS jr*g)    )annotationsN)TYPE_CHECKINGAny)Self)Variablecore)
check_type)convert_np_dtype_to_dtype_in_pir_modestatic_only)LayerHelper)DataType)get_current_insertion_pointset_insertion_point   _setitem_static)Tensor)	DTypeLike	ShapeLikeSize1TensorIndex
TensorLikec                :    [        U 5      R                  5       S;  $ )N)falseoff0none)strlower)vals    S/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/static/input.pyevaluate_flagr#   6   s    s8>>#@@@    c                h   S n[        S0 [        5       D6n[        U S[        [        4S5        [        US[
        [        4S5        [        U5      n[        [        U5      5       HG  nX   c  SX'   [        X   [        5      (       d  M%  X   S:  d  M/  X   S:w  d  M9  [        SX    35      e   Uc  [        R                  " 5       n[        5       (       a  Un[        U[        5      (       d)  [        R                   R"                  R%                  U5      n['        5       nU" 5         [        R(                  R+                  XU["        R,                  " 5       5      n	[/        U5        U	$ UR1                  U UU["        R2                  R4                  R6                  S	US	S	S
9n	[8        R:                  R=                  SS5      n
[?        U
5      (       a`  [        S0 [        5       D6n[        U["        R2                  R4                  5      (       d  [%        U5      nURA                  S0 SU	0UUSU S.S9  U	$ )a
  

This function creates a variable on the global block. The global variable
can be accessed by all the following operators in the graph. The variable
is a placeholder that could be fed with input, such as Executor can feed
input into the variable. When `dtype` is None, the dtype
will get from the global dtype by `paddle.get_default_dtype()`.

Args:
    name (str): The name/alias of the variable, see :ref:`api_guide_Name`
        for more details.
    shape (list|tuple): List|Tuple of integers declaring the shape. You can
        set None or -1 at a dimension to indicate the dimension can be of any
        size. For example, it is useful to set changeable batch size as None or -1.
    dtype (np.dtype|str, optional): The type of the data. Supported
        dtype: bool, float16, float32, float64, int8, int16, int32, int64,
        uint8. Default: None. When `dtype` is not set, the dtype will get
        from the global dtype by `paddle.get_default_dtype()`.
    lod_level (int, optional): The LoD level of the DenseTensor. Usually users
        don't have to set this value. Default: 0.

Returns:
    Variable: The global variable that gives access to the data.

Examples:
    .. code-block:: python

        >>> # doctest: +SKIP("This has diff in xdoctest env")
        >>> import numpy as np
        >>> import paddle
        >>> paddle.enable_static()

        # Creates a variable with fixed size [3, 2, 1]
        # User can only feed data of the same shape to x
        # the dtype is not set, so it will set "float32" by
        # paddle.get_default_dtype(). You can use paddle.get_default_dtype() to
        # change the global dtype
        >>> x = paddle.static.data(name='x', shape=[3, 2, 1])

        # Creates a variable with changeable batch size -1.
        # Users can feed data of any batch size into y,
        # but size of each data sample has to be [2, 1]
        >>> y = paddle.static.data(name='y', shape=[-1, 2, 1], dtype='float32')

        >>> z = x + y

        # In this example, we will feed x and y with np-ndarray "1"
        # and fetch z, like implementing "1 + 1 = 2" in PaddlePaddle
        >>> feed_data = np.ones(shape=[3, 2, 1], dtype=np.float32)

        >>> exe = paddle.static.Executor(paddle.framework.CPUPlace())
        >>> out = exe.run(paddle.static.default_main_program(),
        ...             feed={
        ...                 'x': feed_data,
        ...                 'y': feed_data
        ...             },
        ...             fetch_list=[z.name])

        # np-ndarray of shape=[3, 2, 1], dtype=float32, whose elements are 2
        >>> print(out)
        [array([[[2.],
                [2.]],
               [[2.],
                [2.]],
               [[2.],
                [2.]]], dtype=float32)]

c                 $   [         R                  R                  R                  5       n U R	                  5       R
                  n[        U5      S:X  a  g U H8  nUR                  5       S:w  d  M  [         R                  R                  U5          g    g )Nr   z
pd_op.data)	paddlepirr   default_main_programglobal_blockopslennamer   )r)   r+   ops      r"   _reset_data_op_insertion_point,data.<locals>._reset_data_op_insertion_point   sh    %zzCCE"//155s8q=BwwyL(

..r2 r$   datar-   shapeNr   zIOnly -1 can be used in shape to indicate unknown dimension, but received T)r-   r2   dtypetypestop_gradient	lod_levelis_dataneed_check_feedFLAGS_enable_pir_in_executorout)r2   r4   placer-   )r5   inputsoutputsattrs)r1   )!r   localsr	   bytesr   listtupleranger,   
isinstanceint
ValueErrorr'   get_default_dtyper   r   r(   r   r
   r   _pir_opsr1   Placer   create_global_variableVarDescVarTypeDENSE_TENSORosenvirongetr#   	append_op)r-   r2   r4   r7   r/   helperiir_dtypeprev_insertion_pointr;   is_pir_modes              r"   r1   r1   :   s   X ,68,FtVeS\62uge}f5KE3u:8EHeh$$A%(b.[\a\d[ef 	  }((*}}(H--zzAA%HH:<&(oo""4$**,G01


'
'\\!!.. ( 	C **..!?FK[!!0vx0%!5!566.u5ECL		 	 
	
 Jr$   c                      \ rS rSrSr   S         SS jjrS rSS jr\SSS jj5       r	\ S     SS jj5       r
SS	 jrSS
 jrS rSS jrSS jrSS jrSrg)	InputSpec   a  
InputSpec describes the signature information of the model input, such as ``shape`` , ``dtype`` , ``name`` .

This interface is often used to specify input tensor information of models in high-level API.
It's also used to specify the tensor information for each input parameter of the forward function
decorated by `@paddle.jit.to_static`.

Args:
    shape (tuple(integers)|list[integers]): List|Tuple of integers
        declaring the shape. You can set "None" or -1 at a dimension
        to indicate the dimension can be of any size. For example,
        it is useful to set changeable batch size as "None" or -1.
    dtype (np.dtype|str, optional): The type of the data. Supported
        dtype: bool, float16, float32, float64, int8, int16, int32, int64,
        uint8. Default: float32.
    name (str): The name/alias of the variable, see :ref:`api_guide_Name`
        for more details.
    stop_gradient (bool, optional): A boolean that mentions whether gradient should flow. Default is False, means don't stop calculate gradients.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> from paddle.static import InputSpec

        >>> input = InputSpec([None, 784], 'float32', 'x')
        >>> label = InputSpec([None, 1], 'int64', 'label')

        >>> print(input)
        InputSpec(shape=(-1, 784), dtype=paddle.float32, name=x, stop_gradient=False)

        >>> print(label)
        InputSpec(shape=(-1, 1), dtype=paddle.int64, name=label, stop_gradient=False)
Nc                    U R                  U5      U l        Ub0  [        U[        R                  [
        45      (       a  [        U5      nX l        X0l        X@l        g N)	_verifyr2   rE   npr4   r   r
   r-   r6   )selfr2   r4   r-   r6   s        r"   __init__InputSpec.__init__   sI     \\%(
%"((C11259
	*r$   c                T    [        U R                  U R                  U R                  S9$ )Nr2   r4   )r1   r-   r2   r4   r_   s    r"   _create_feed_layerInputSpec._create_feed_layer   s    DIITZZtzzBBr$   c           
         [        U 5      R                   SU R                   SU R                   SU R                   SU R
                   S3
$ )Nz(shape=z, dtype=z, name=z, stop_gradient=))r5   __name__r2   r4   r-   r6   rd   s    r"   __repr__InputSpec.__repr__  sb    t*%%&gdjj\$**WUYU^U^T__opt  qC  qC  pD  DE  F  	Fr$   c                8   [        U[        [        R                  R                  [
        R                  R                  45      (       a1  U " UR                  UR                  U=(       d    UR                  5      $ [        S[        U5      R                   S35      e)a;  
Generates a InputSpec based on the description of input tensor.

Args:
    tensor(Tensor): the source tensor to generate a InputSpec instance

Returns:
    A InputSpec instance generated from Tensor.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> from paddle.static import InputSpec

        >>> paddle.disable_static()

        >>> x = paddle.ones([2, 2], dtype="float32")
        >>> x_spec = InputSpec.from_tensor(x, name='x')
        >>> print(x_spec)
        InputSpec(shape=(2, 2), dtype=paddle.float32, name=x, stop_gradient=False)

z0Input `tensor` should be a Tensor, but received .)rE   r   r   eagerr   r'   r(   Valuer2   r4   r-   rG   r5   ri   )clstensorr-   s      r"   from_tensorInputSpec.from_tensor  sq    2 fx):):FJJ<L<LMNNv||V\\43F6;;GGB4<CXCXBYYZ[ r$   c                >    U " UR                   UR                  U5      $ )a  
Generates a InputSpec based on the description of input np.ndarray.

Args:
    tensor(Tensor): the source numpy ndarray to generate a InputSpec instance

Returns:
    A InputSpec instance generated from Tensor.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from paddle.static import InputSpec

        >>> x = np.ones([2, 2], np.float32)
        >>> x_spec = InputSpec.from_numpy(x, name='x')
        >>> print(x_spec)
        InputSpec(shape=(2, 2), dtype=paddle.float32, name=x, stop_gradient=False)

rc   )rp   ndarrayr-   s      r"   
from_numpyInputSpec.from_numpy$  s    2 7=='--66r$   c                Z   [        U[        [        45      (       a0  [        U5      S:w  a  [	        SU S[        U5       S35      eUS   nO7[        U[
        5      (       d"  [        S[        U5      R                   S35      eU/[        U R                  5      Qn[        U5      U l	        U $ )a  
Inserts `batch_size` in front of the `shape`.

Args:
    batch_size(int): the inserted integer value of batch size.

Returns:
    The original InputSpec instance by inserting `batch_size` in front of `shape`.

Examples:
    .. code-block:: python

        >>> from paddle.static import InputSpec

        >>> x_spec = InputSpec(shape=[64], dtype='float32', name='x')
        >>> x_spec.batch(4)
        >>> print(x_spec)
        InputSpec(shape=(4, 64), dtype=paddle.float32, name=x, stop_gradient=False)

   zLength of batch_size: z shall be 1, but received rm   r   z.type(batch_size) shall be `int`, but received )
rE   rB   rC   r,   rG   rF   	TypeErrorr5   ri   r2   )r_   
batch_size	new_shapes      r"   batchInputSpec.batch?  s    * j4-00:!# ,ZL8RSVWaSbRccde  $AJJ,,@jAQAZAZ@[[\]   3$tzz"23	9%
r$   c                    [        U R                  5      S:X  a  [        S5      eU R                  U R                  SS 5      U l        U $ )a  
Removes the first element of `shape`.

Returns:
    The original InputSpec instance by removing the first element of `shape` .

Examples:
    .. code-block:: python

        >>> from paddle.static import InputSpec

        >>> x_spec = InputSpec(shape=[4, 64], dtype='float32', name='x')
        >>> x_spec.unbatch()
        >>> print(x_spec) # InputSpec(shape=(64,), dtype=paddle.float32, name=x)
        InputSpec(shape=(64,), dtype=paddle.float32, name=x, stop_gradient=False)

r   z8Not support to unbatch a InputSpec when len(shape) == 0.ry   N)r,   r2   rG   r]   rd   s    r"   unbatchInputSpec.unbatchd  sE    $ tzz?aJ  \\$**QR.1
r$   c           
     X   [        U[        [        45      (       d"  [        S[	        U5      R
                   S35      e[        U5       HT  u  p#Ub=  [        U[        5      (       d(  [        SU S[	        U5      R
                   SU S35      eUb  US:  d  MP  SX'   MV     [        U5      $ )z9
Verifies the input shape and modifies `None` into `-1`.
zJType of `shape` in InputSpec should be one of (tuple, list), but received rm   zshape[z$] should be an `int`, but received `z`:r3   )	rE   rB   rC   rz   r5   ri   	enumeraterF   rG   )r_   r2   rT   eles       r"   r]   InputSpec._verify~  s     %$//\]abg]h]q]q\rrst   &FA!#s++$ #GS	HZHZG[[]^a]bbcd  {cBh ' U|r$   c                l    [        [        U R                  5      U R                  U R                  45      $ r\   )hashrC   r2   r4   r6   rd   s    r"   __hash__InputSpec.__hash__  s)     U4::&

D4F4FGHHr$   c                t   ^ ^ / SQn[        T 5      [        T5      L =(       a    [        UU 4S jU 5       5      $ )N)r2   r4   r-   r6   c              3  V   >#    U  H  n[        TU5      [        TU5      :H  v   M      g 7fr\   )getattr).0attrotherr_   s     r"   	<genexpr>#InputSpec.__eq__.<locals>.<genexpr>  s'      1
DIDGD$75$#77Es   &))r5   all)r_   r   slotss   `` r"   __eq__InputSpec.__eq__  s6    ;DzT%[( 
S 1
DI1
 .
 	
r$   c                    X:X  + $ r\    )r_   r   s     r"   __ne__InputSpec.__ne__  s      r$   )r4   r-   r2   r6   )float32NF)
r2   r   r4   r   r-   
str | Noner6   boolreturnNone)r   r   r\   )rq   r   r-   r   r   r   )ru   znpt.NDArray[Any]r-   r   r   r   )r{   zint | Size1r   r   )r   r   )r   rF   )r   r   r   r   r   r   )ri   
__module____qualname____firstlineno____doc__r`   re   rj   classmethodrr   rv   r}   r   r]   r   r   r   __static_attributes__r   r$   r"   rY   rY      s    !L %#++ + 	+
 + 
+$CF  > ;?7&7.87	7 74#J4(I"
!r$   rY   c                    [        XU5      $ )a  
x(Tensor): input Tensor.
index(Scalar|Tuple|List|Tensor): Where should be set value.
value(Scalar|Tensor): The value which is going to be set.

[How to write index?]
1. ':' -> slice(),
   (1) a[:]=v -> setitem(a, slice(None,None,None), v)
   (2) a[1::2] -> setitem(a, slice(1,None,2), v)

2. if there are multiple indexes for axes, use TUPLE (Not LIST) to pack them.
   (1) a[1, 2]=v -> setitem(a, (1, 2), v)
   (2) a[[1,2],[2,3]]=v -> setitem(a, ([1,2],[2,3]), v)
   (3) a[1,:, 3] = v -> setitem(a, (1, slice(None,None,None),3), v)
   (4) a[1, ..., 2]=v -> setitem(a, (1, ..., 2), v)

3. You can always use TUPLE as index input, even there is only one index.
   (1) a[Tensor([10,10])]=v -> setitem(a, (Tensor([10,10]),), v)
   (2) a[1] = v -> setitem(a, (1,), v)
r   )xindexvalues      r"   setitemr     s    2 1U++r$   r   )Nr   )
r-   r   r2   r   r4   zDTypeLike | Noner7   rF   r   zpaddle.Tensor)r   r   r   r   r   r   r   r   )+
__future__r   rO   typingr   r   numpyr^   numpy.typingnpttyping_extensionsr   r'   paddle.baser   r   paddle.base.data_feederr	   paddle.base.frameworkr
   r   r   paddle.base.layer_helperr   paddle.base.libpaddler   paddle.base.libpaddle.pirr   r   base.variable_indexr   r   paddle._typingr   r   r   r   r   __all__r#   r1   rY   r   r   r$   r"   <module>r      s    # 	 %   "  & . 
 1 *
 2  A  #	J
JJ J 	J
 J JZb! b!J,,, , 	,r$   