
    6bi!                     f    S r SSKrSSKJs  Jr  SSKJr  SSK	J
r
  \
" S5       " S S\5      5       rg)zContains the Reshape layer.    N)Layer)keras_exportzkeras.layers.Reshapec                   J   ^  \ rS rSrSrU 4S jrS rS rS rU 4S jr	Sr
U =r$ )	Reshape   a  Layer that reshapes inputs into the given shape.

Input shape:
  Arbitrary, although all dimensions in the input shape must be known/fixed.
  Use the keyword argument `input_shape` (tuple of integers, does not
  include the samples/batch size axis) when using this layer as the first
  layer in a model.

Output shape:
  `(batch_size,) + target_shape`

Example:

>>> # as first layer in a Sequential model
>>> model = tf.keras.Sequential()
>>> model.add(tf.keras.layers.Reshape((3, 4), input_shape=(12,)))
>>> # model.output_shape == (None, 3, 4), `None` is the batch size.
>>> model.output_shape
(None, 3, 4)

>>> # as intermediate layer in a Sequential model
>>> model.add(tf.keras.layers.Reshape((6, 2)))
>>> model.output_shape
(None, 6, 2)

>>> # also supports shape inference using `-1` as dimension
>>> model.add(tf.keras.layers.Reshape((-1, 2, 2)))
>>> model.output_shape
(None, 3, 2, 2)
c                 F   > [         TU ]  " S0 UD6  [        U5      U l        g)zCreates a `tf.keras.layers.Reshape`  layer instance.

Args:
  target_shape: Target shape. Tuple of integers, does not include the
    samples dimension (batch size).
  **kwargs: Any additional layer keyword arguments.
N )super__init__tupletarget_shape)selfr   kwargs	__class__s      _/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/reshaping/reshape.pyr   Reshape.__init__<   s"     	"6"!,/    c                 H   [        U5      nSR                  X5      nSu  pE[        U5       H%  u  pgUS:  a  Uc  UnM  [        SU S35      eXG-  nM'     [        R
                  " U[        S9nUb!  US:X  d  X-  S:w  a  [        U5      eX-  X%'   U$ X:w  a  [        U5      eU$ )ae  Find and replace a missing dimension in an output shape.

This is a near direct port of the internal Numpy function
`_fix_unknown_dimension` in `numpy/core/src/multiarray/shape.c`

Args:
  input_shape: Shape of array being reshaped
  output_shape: Desired shape of the array with at most a single -1
    which indicates a dimension that should be derived from the input
    shape.

Returns:
  The new output shape with a -1 replaced with its computed value.

Raises:
  ValueError: If the total array size of the output_shape is
  different than the input_shape, or more than one unknown dimension
  is specified.
zNtotal size of new array must be unchanged, input_shape = {}, output_shape = {})   Nr   zTThere must be at most one unknown dimension in output_shape. Received: output_shape=.)dtype)listformat	enumerate
ValueErrornpprodint)	r   input_shapeoutput_shapemsgknownunknownindexdimoriginals	            r   _fix_unknown_dimensionReshape._fix_unknown_dimensionG   s    ( L)228&3 	 !#L1JEQw?#G$@@L~QP 
  2 77;c2zX-2 o%$,$5L!  S/!r   c                 "   [         R                  " U5      R                  5       nS USS  ;   a&  US   /nU[        S U R                   5       5      -  nO'US   /nX R                  USS  U R                  5      -  n[         R                  " U5      $ )Nr   r   c              3   4   #    U  H  oS :w  a  UOSv   M     g7f)Nr	   ).0ss     r   	<genexpr>/Reshape.compute_output_shape.<locals>.<genexpr>~   s      "0A1"W$&0As   )tfTensorShapeas_listr   r   r'   )r   r   r    s      r   compute_output_shapeReshape.compute_output_shapey   s    nn[199;;qr?"'N+LE "040A0A"  L (N+L77AB!2!2 L ~~l++r   c                    [         R                  " U[         R                  " U5      S   4U R                  -   5      n[         R                  " 5       (       d*  UR                  U R                  UR                  5      5        U$ )Nr   )r0   reshapeshaper   executing_eagerly	set_shaper3   )r   inputsresults      r   callReshape.call   sa    FRXXf%5a%8$:T=N=N$NO##%% T66v||DEr   c                    > SU R                   0n[        TU ]	  5       n[        [	        UR                  5       5      [	        UR                  5       5      -   5      $ )Nr   )r   r
   
get_configdictr   items)r   configbase_configr   s      r   r?   Reshape.get_config   sI     $"3"34g(*D**,-V\\^0DDEEr   )r   )__name__
__module____qualname____firstlineno____doc__r   r'   r3   r<   r?   __static_attributes____classcell__)r   s   @r   r   r      s)    >	00d,F Fr   r   )rI   numpyr   tensorflow.compat.v2compatv2r0   tf_keras.src.engine.base_layerr    tensorflow.python.util.tf_exportr   r   r	   r   r   <module>rR      sD    "  ! ! 0 : $%xFe xF &xFr   