
    BVhy                     .    d Z ddlZddlmZ d Zd Zd Zy)z$A library of common shape functions.    N)tensor_shapec                    t        t        t        j                  t        | j                        t        |j                        t        j                  d                        }g }|D ]  \  }}|j                  |j                  l|j                  !|j                  dkD  r|j                  |       L|j                  !|j                  dkD  r|j                  |       y|j                  d       |j                  dk(  r|j                  |       |j                  dk(  r|j                  |       |j                  |j                  k(  r"|j                  |j                  |              y |S )a  Helper functions for is_broadcast_compatible and broadcast_shape.

  Args:
    shape_x: A `TensorShape`
    shape_y: A `TensorShape`

  Returns:
    Returns None if the shapes are not broadcast compatible,
    a list of the broadcast dimensions otherwise.
     )	fillvalueN)
reversedlist	itertoolszip_longestdimsr   	Dimensionvalueappend
merge_with)shape_xshape_ybroadcasted_dimsreturn_dimsdim_xdim_ys         Y/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/framework/common_shapes.py_broadcast_shape_helperr      s6    



w||$w||$$..q1345 +( nue{{ekk1 
	 U[[1_5!;;"u{{Q5!4 						# ))%0112 
    c                 P    | j                   |j                   yt        | |      duS )zReturns True if `shape_x` and `shape_y` are broadcast compatible.

  Args:
    shape_x: A `TensorShape`
    shape_y: A `TensorShape`

  Returns:
    True if a shape exists that both `shape_x` and `shape_y` can be broadcasted
    to.  False otherwise.
  NF)ndimsr   )r   r   s     r   is_broadcast_compatibler   G   s,     ]]gmm3	 '	2$	>>r   c                     | j                   |j                   t        j                         S t        | |      }|t	        d|  d| d      t        j
                  |      S )a  Returns the broadcasted shape between `shape_x` and `shape_y`.

  Args:
    shape_x: A `TensorShape`
    shape_y: A `TensorShape`

  Returns:
    A `TensorShape` representing the broadcasted shape.

  Raises:
    ValueError: If the two shapes can not be broadcasted.
  zIncompatible shapes for broadcasting. Two shapes are compatible if for each dimension pair they are either equal or one of them is 1. Received: z and .)r   r   unknown_shaper   
ValueErrorTensorShape)r   r   r   s      r   broadcast_shaper!   W   sq     ]]gmm3%%'''9+
 " #*%y; < < 
	!	!+	..r   )__doc__r	   tensorflow.python.frameworkr   r   r   r!    r   r   <module>r%      s     +  4/d? /r   