
    6bi                          S r SSKJs  Jr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  \" S5       " S	 S
\
5      5       r\" S5      SS j5       rg)z7Layer that computes the dot product between two inputs.    N)backend)base_layer_utils)_Merge)tf_utils)keras_exportzkeras.layers.Dotc                      ^  \ rS rSrSrS
U 4S jjr\R                  S 5       rS r	\R                  S 5       r
SS jrU 4S jrS	rU =r$ )Dot   a8  Layer that computes a dot product between samples in two tensors.

E.g. if applied to a list of two tensors `a` and `b` of shape
`(batch_size, n)`, the output will be a tensor of shape `(batch_size, 1)`
where each entry `i` will be the dot product between
`a[i]` and `b[i]`.

>>> x = np.arange(10).reshape(1, 5, 2)
>>> print(x)
[[[0 1]
  [2 3]
  [4 5]
  [6 7]
  [8 9]]]
>>> y = np.arange(10, 20).reshape(1, 2, 5)
>>> print(y)
[[[10 11 12 13 14]
  [15 16 17 18 19]]]
>>> tf.keras.layers.Dot(axes=(1, 2))([x, y])
<tf.Tensor: shape=(1, 2, 2), dtype=int64, numpy=
array([[[260, 360],
        [320, 445]]])>

>>> x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))
>>> x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))
>>> dotted = tf.keras.layers.Dot(axes=1)([x1, x2])
>>> dotted.shape
TensorShape([5, 1])


c                   > [         TU ]  " S
0 UD6  [        U[        5      (       d  [        U[        [
        45      (       d  [        SU 35      e[        U5      S:w  a  [        SU 35      e[        US   [        5      (       a  [        US   [        5      (       d  [        SU 35      eXl	        X l
        SU l        SU l        g	)a  Initializes a layer that computes the element-wise dot product.

  >>> x = np.arange(10).reshape(1, 5, 2)
  >>> print(x)
  [[[0 1]
    [2 3]
    [4 5]
    [6 7]
    [8 9]]]
  >>> y = np.arange(10, 20).reshape(1, 2, 5)
  >>> print(y)
  [[[10 11 12 13 14]
    [15 16 17 18 19]]]
  >>> tf.keras.layers.Dot(axes=(1, 2))([x, y])
  <tf.Tensor: shape=(1, 2, 2), dtype=int64, numpy=
  array([[[260, 360],
          [320, 445]]])>

Args:
  axes: Integer or tuple of integers,
    axis or axes along which to take the dot product. If a tuple, should
    be two integers corresponding to the desired axis from the first
    input and the desired axis from the second input, respectively. Note
    that the size of the two selected axes must match.
  normalize: Whether to L2-normalize samples along the
    dot product axis before taking the dot product.
    If set to True, then the output of the dot product
    is the cosine proximity between the two samples.
  **kwargs: Standard layer keyword arguments.
zPInvalid type for argument `axes`: it should be a list or an int. Received: axes=   zSInvalid format for argument `axes`: it should contain two elements. Received: axes=r      zUInvalid format for argument `axes`: list elements should be integers. Received: axes=TFN )super__init__
isinstanceintlisttuple	TypeErrorlen
ValueErroraxes	normalizesupports_masking_reshape_required)selfr   r   kwargs	__class__s       Y/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/merging/dot.pyr   Dot.__init__?   s    > 	"6"$$$dT5M2288<v?  4yA~ 004v7  d1gs++:d1gs3K3K 337&:  	" $!&    c                    [        US   [        5      (       a  [        U5      S:w  a  [        SU 35      eUS   nUS   nUb  Uc  g [        U R                  [
        5      (       aR  U R                  S:  a1  U R                  [        U5      -  U R                  [        U5      -  /nOU R                  /S-  nOU R                  nX$S      X4S      :w  a-  [        SX$S       SUS    SX4S       SUS    SU S	U 35      eg )
Nr   r   LA `Dot` layer should be called on a list of 2 inputs. Received: input_shape=r   z'Incompatible input shapes: axis values z
 (at axis z) != z). Full input shapes: z, )r   r   r   r   r   r   )r   input_shapeshape1shape2r   s        r   build	Dot.buildt   s#    +a.%00C4D4I))47  QQ>V^dii%%yy1}		CK/S[1HI		{Q99Dq'?f!Wo-%1g/z$q'%q'?#:d1gY 7&&,XRx9  .r!   c                    [         R                  " XR                  5        [        U5      S:w  a  [	        SU 35      eUS   nUS   n[        U R                  [        5      (       ah  U R                  S:  aG  U R                  [        R                  " U5      -  U R                  [        R                  " U5      -  /nOU R                  /S-  nO/ n[        [        U R                  5      5       Hm  nU R                  U   S:  a9  UR                  U R                  U   [        R                  " X   5      -  5        MO  UR                  U R                  U   5        Mo     U R                  (       a@  [        R                  R                  X$S   S9n[        R                  R                  X4S   S9n[        R                   " X#U5      nU$ )Nr   zEA `Dot` layer should be called on exactly 2 inputs. Received: inputs=r   r   )axis)r   no_ragged_supportnamer   r   r   r   r   r   ndimrangeappendr   tflinalgl2_normalize	batch_dot)r   inputsx1x2r   ioutputs          r   _merge_functionDot._merge_function   sh   **699=v;!$$*8-  AYAYdii%%yy1}IIR 00IIR 00
 		{QD3tyy>*99Q<!#KK		!w||FI/F FGKK		!-	 +
 >>''a'9B''a'9B""240r!   c                 ^   [        U[        [        45      (       a  [        U5      S:w  a  [	        SU 35      e[        US   5      n[        US   5      n[        U R
                  [        5      (       aR  U R
                  S:  a1  U R
                  [        U5      -  U R
                  [        U5      -  /nOU R
                  /S-  nOU R
                  nUR                  US   5        UR                  US   5        UR                  S5        X#-   n[        U5      S:X  a  US/-  n[        U5      $ )Nr   r#   r   r   )r   r   r   r   r   r   r   pop)r   r$   r%   r&   r   output_shapes         r   compute_output_shapeDot.compute_output_shape   s   +t}55[9IQ9N))47  k!n%k!n%dii%%yy1}		CK/S[1HI		{Q99D

47

47

1|!QCL\""r!   c                     g Nr   )r   r4   masks      r   compute_maskDot.compute_mask   s    r!   c                    > U R                   U R                  S.n[        TU ]  5       n[	        [        UR                  5       5      [        UR                  5       5      -   5      $ )Nr   r   )r   r   r   
get_configdictr   items)r   configbase_configr   s      r   rG   Dot.get_config   sP    II
 g(*D**,-V\\^0DDEEr!   )r   r   r   r   FrA   )__name__
__module____qualname____firstlineno____doc__r   r   shape_type_conversionr'   r9   r>   rC   rG   __static_attributes____classcell__)r   s   @r   r	   r	      sY    @3'j ## $4< ### $#.F Fr!   r	   zkeras.layers.dotc                 (    [        SXS.UD6" U 5      $ )a!  Functional interface to the `Dot` layer.

Args:
    inputs: A list of input tensors (at least 2).
    axes: Integer or tuple of integers,
        axis or axes along which to take the dot product.
    normalize: Whether to L2-normalize samples along the
        dot product axis before taking the dot product.
        If set to True, then the output of the dot product
        is the cosine proximity between the two samples.
    **kwargs: Standard layer keyword arguments.

Returns:
    A tensor, the dot product of the samples from the inputs.
rF   r   )r	   )r4   r   r   r   s       r   dotrW      s    " 8D88@@r!   rM   )rR   tensorflow.compat.v2compatv2r0   tf_keras.srcr   tf_keras.src.enginer   &tf_keras.src.layers.merging.base_merger   tf_keras.src.utilsr    tensorflow.python.util.tf_exportr   r	   rW   r   r!   r   <module>r`      sg    > " !   0 9 ' :  !pF& pF "pFf  !A "Ar!   