
    x-j                     6    d dl ZddlmZ ddlmZ g Zd Zd ZdS )    N   )core)DataToDenseTensorConverterc                 n   t          | t          j                  r#t          t	          j        |           ||          S t          | t                    rt          |t          |          g t          j	        j
        j                  }g }| D ]9}|                    t          |                     |                    |           :|g|k    s
J d            t	          j        |j                  }|                    g |j        dR           }t          j                    }|                    ||           |                    |           |S t          | t          j                  r@t          j                    }|                    | |           |                    |           |S t)          d          )a  
    Create a DenseTensor from a numpy array, list or existing DenseTensor.

    The implementation is as follows:

    1. Check whether the length-based LoD, i.e., :code:`recursive_seq_lens`
       is valid.

    2. Convert :code:`recursive_seq_lens` to a offset-based LoD.

    3. Based on :code:`place` , copy the :code:`data` from a numpy array, list
       or existing DenseTensor to CPU or GPU device.

    4. Set offset-based LoD to the output DenseTensor.

    Suppose we want to create a DenseTensor to hold data for word sequences,
    where each word is represented by an integer. If we want to create
    a DenseTensor to represent two sentences, one of 2 words, and one of 3 words.

    Then :code:`data` would be a numpy array of integers with shape (5, 1).
    :code:`recursive_seq_lens` would be [[2, 3]], indicating the word number
    in each sentence. This length-based :code:`recursive_seq_lens` [[2, 3]]
    would be converted to offset-based LoD [[0, 2, 5]] inside the function
    call.


    Args:
        data (numpy.ndarray|list|DenseTensor): a numpy array, a list or ad DenseTensor
                holding the data to be copied.
        recursive_seq_lens (list[list[int]]): a list of lists indicating the
                length-based LoD info.
        place (CPUPlace|CUDAPlace): CPU or GPU place indicating where the data
                in the created DenseTensor will be stored.

    Returns:
         A DenseTensor with tensor data and recursive_seq_lens info.

    Examples:

        .. code-block:: python

            >>> import paddle.base as base
            >>> import numpy as np

            >>> t = base.create_lod_tensor(np.ndarray([5, 30]), [[2, 3]], base.CPUPlace())
    )place	lod_levelshapedtypez(data and recursive_seq_lens do not matchr   z<data should be either a DenseTensor, a Numpy array or a list)
isinstancer   DenseTensorcreate_lod_tensornparraylistr   lenVarDescVarTypeFP32appendfeeddatareshaper	   setset_recursive_sequence_lengthsndarray	TypeError)r   recursive_seq_lensr   	converternew_recursive_seq_lensseqarrtensors           V/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/base/lod_tensor.pyr   r      s   ^ $()) '
 $1CUKKK	D$		 %
 /,--,&+	
 
 
	 "$ 	  	 C"))#c((333NN3&'+====6 >== hy~&&
 kk/CI/q//**!##

3--.@AAA	D"*	%	% 
!##

4--.@AAAJ
 
 	
    c                     t          |t                    s
J d            t          | d                   g|}t          j                            |||                              d          }t          || |          S )aL  
        :api_attr: Static Graph

    Create a DenseTensor containing random integers.

    The implementation is as follows:

    1. Obtain the shape of output DenseTensor based on :code:`recursive_seq_lens`
       and :code:`base_shape` . The first dimension of the shape is the total
       length of sequences, while the other dimensions are the same as
       :code:`base_shape` .

    2. Create a numpy array of random integers, and parse the created numpy
       array as parameter :code:`data` of :ref:`api_paddle_base_create_lod_tensor` to
       create the output DenseTensor.

    Suppose we want to create a DenseTensor to hold data for 2 sequences, where
    the dimension of the sequences are [2, 30] and [3, 30] respectively.
    The :code:`recursive_seq_lens` would be [[2, 3]], and :code:`base_shape`
    would be [30] (the other dimensions excluding the sequence length).
    Therefore, the shape of the output DenseTensor would be [5, 30], where
    the first dimension 5 is the total lengths of the sequences, and the
    other dimensions are :code:`base_shape`.

    Args:
        recursive_seq_lens (list[list[int]]): a list of lists indicating the
                length-based LoD info.
        base_shape (list[int]): the shape of the output DenseTensor excluding
                the first dimension.
        place (CPUPlace|CUDAPlace): CPU or GPU place indicating where
                the data in the created DenseTensor will be stored.
        low (int): the lower bound of the random integers.
        high (int): the upper bound of the random integers.

    Returns:
        A DenseTensor with tensor data and recursive_seq_lens info, whose data
        is inside [low, high].

    Examples:

        .. code-block:: pycon

            >>> import paddle.base as base

            >>> t = base.create_random_int_lodtensor(
            ...     recursive_seq_lens=[[2, 3]],
            ...     base_shape=[30],
            ...     place=base.CPUPlace(),
            ...     low=0,
            ...     high=10,
            ... )
            >>> print(t.shape())
            paddle.Size([5, 30])
    zbase_shape should be a listint64)r   r   sumr   randomrandom_integersastyper   )r   
base_shaper   lowhighoverall_shaper   s          r#   create_random_int_lodtensorr0   p   sy    r j$''FF)FFF'+B/00>:>M9$$S$>>EEgNNDT#5u===r$   )	numpyr    r   data_feederr   __all__r   r0    r$   r#   <module>r6      sh              3 3 3 3 3 3
V
 V
 V
r>> >> >> >> >>r$   