
    2Vhl                     D    d dl Zd dlmZ  eddg      	 	 	 	 	 dd       Zy)    N)keras_exportzkeras.utils.pad_sequencesz*keras.preprocessing.sequence.pad_sequencesc           	      P   t        | d      st        d      t        |       }g }d}d}	| D ]N  }
	 |j                  t        |
             |	r/t        |
      r$t	        j
                  |
      j                  dd }d}	P |t	        j                  |      }t	        j                  |t        j                        xs$ t	        j                  |t        j                        }t        |t              r%|t        ur|st        d	| d
t        |       d      t	        j                  ||f|z   ||      }
t!        |       D ]  \  }}t        |      s|dk(  r|| d }n|dk(  r|d| }nt        d| d      t	        j
                  ||      }|j                  dd |k7  r!t        d|j                  dd  d| d|       |dk(  r||
|dt        |      f<   |dk(  r||
|t        |       df<   t        d| d       |
S # t        $ r}t        dt        |
             |d}~ww xY w)a  Pads sequences to the same length.

    This function transforms a list (of length `num_samples`)
    of sequences (lists of integers)
    into a 2D NumPy array of shape `(num_samples, num_timesteps)`.
    `num_timesteps` is either the `maxlen` argument if provided,
    or the length of the longest sequence in the list.

    Sequences that are shorter than `num_timesteps`
    are padded with `value` until they are `num_timesteps` long.

    Sequences longer than `num_timesteps` are truncated
    so that they fit the desired length.

    The position where padding or truncation happens is determined by
    the arguments `padding` and `truncating`, respectively.
    Pre-padding or removing values from the beginning of the sequence is the
    default.

    >>> sequence = [[1], [2, 3], [4, 5, 6]]
    >>> keras.utils.pad_sequences(sequence)
    array([[0, 0, 1],
           [0, 2, 3],
           [4, 5, 6]], dtype=int32)

    >>> keras.utils.pad_sequences(sequence, value=-1)
    array([[-1, -1,  1],
           [-1,  2,  3],
           [ 4,  5,  6]], dtype=int32)

    >>> keras.utils.pad_sequences(sequence, padding='post')
    array([[1, 0, 0],
           [2, 3, 0],
           [4, 5, 6]], dtype=int32)

    >>> keras.utils.pad_sequences(sequence, maxlen=2)
    array([[0, 1],
           [2, 3],
           [5, 6]], dtype=int32)

    Args:
        sequences: List of sequences (each sequence is a list of integers).
        maxlen: Optional Int, maximum length of all sequences. If not provided,
            sequences will be padded to the length of the longest individual
            sequence.
        dtype: (Optional, defaults to `"int32"`). Type of the output sequences.
            To pad sequences with variable length strings, you can use `object`.
        padding: String, "pre" or "post" (optional, defaults to `"pre"`):
            pad either before or after each sequence.
        truncating: String, "pre" or "post" (optional, defaults to `"pre"`):
            remove values from sequences larger than
            `maxlen`, either at the beginning or at the end of the sequences.
        value: Float or String, padding value. (Optional, defaults to `0.`)

    Returns:
        NumPy array with shape `(len(sequences), maxlen)`
    __len__z`sequences` must be iterable. T   NFz=`sequences` must be a list of iterables. Found non-iterable: z`dtype` z( is not compatible with `value`'s type: z;
You should set `dtype=object` for variable length strings.)dtypeprepostzTruncating type "z" not understoodzShape of sample z of sequence at position z" is different from expected shape zPadding type ")hasattr
ValueErrorlenappendnpasarrayshape	TypeErrorstrmax
issubdtypestr_
isinstanceobjecttypefull	enumerate)	sequencesmaxlenr   padding
truncatingvaluenum_sampleslengthssample_shapeflagxeis_dtype_stridxstruncs                   N/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/utils/sequence_utils.pypad_sequencesr,      sp   N 9i(899i.KGLD
  
		NN3q6"A!zz!}22126
 ~==0 BMMrww5L %%v"5lugEE{m 
 	
 	f%4e5IAI& IQ1vvghKE6!gvJE0<LMNN 

5.;;qr?l*"5;;qr?"3 45 B."  f#(Ac<SZ< $)AcCJ;= !~gY6FGHH1I2 H[  	''*1vh0 	s   AG??	H%H  H%)Nint32r	   r	   g        )numpyr   keras.src.api_exportr   r,   r       r+   <module>r1      sB     - #4 

r0   