
    BVh-                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddl	mZ ddlmZ dd	lmZ ddZ	 ddZddZeZd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Z d Z!y
)zCFunctions called by the generated code to execute an eager-mode op.    )text_format)
tensor_pb2)
pywrap_tfe)core)dtypes)tensor_conversion_registry)tensor_shape)compatNc                    |j                   }	 |j                          t        j                  |j                  || |||      }|S # t
        j                  $ r5}||xj                  d|z   z  c_        t        j                  |      dd}~wt        $ rN}|D 	cg c]  }	t        |	      s|	 nc c}	w }
}	|
r$t        j                  dj                  |
            |d}~ww xY w)a  Execute a TensorFlow operation.

  Args:
    op_name: Name of the TensorFlow operation (see REGISTER_OP in C++ code) to
      execute.
    num_outputs: The number of outputs of the operation to fetch. (Explicitly
      provided instead of being inferred for performance reasons).
    inputs: A list of inputs to the operation. Each entry should be a Tensor, or
      a value which can be passed to the Tensor constructor to create one.
    attrs: A tuple with alternating string attr names and attr values for this
      operation.
    ctx: The value of context.context().
    name: Customized name for the operation.

  Returns:
    List of output Tensor objects. The list is empty if there are no outputs

  Raises:
    An exception on error.
  N name: QInputs to eager execution function cannot be Keras symbolic tensors, but found {})device_nameensure_initializedr   TFE_Py_Execute_handler   _NotOkStatusExceptionmessage_status_to_exception	TypeError_is_keras_symbolic_tensor_SymbolicExceptionformat)op_namenum_outputsinputsattrsctxnamer   tensorsexkeras_symbolic_tensorss              O/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/eager/execute.pyquick_executer$      s    * +''['(.{DG 
. 
	#	# 1ii9t##i

#
#A
&D0	 )/PA3LQ3OaPPP##""(&)?"@B B Gs5   4A C!0BC!CB-(B-,0CC!c           	         |j                   }	 |j                          t        j                  |j                  || |||j
                  |      }|S # t        j                  $ r5}	||	xj                  d|z   z  c_        t        j                  |	      dd}	~	wt        $ rN}	|D 
cg c]  }
t        |
      s|
 nc c}
w }}
|r$t        j                  dj                  |            |	d}	~	ww xY w)aT  Execute a TensorFlow operation.

  Args:
    op_name: Name of the TensorFlow operation (see REGISTER_OP in C++ code) to
      execute.
    num_outputs: The number of outputs of the operation to fetch. (Explicitly
      provided instead of being inferred for performance reasons).
    inputs: A list of inputs to the operation. Each entry should be a Tensor, or
      a value which can be passed to the Tensor constructor to create one.
    attrs: A tuple with alternating string attr names and attr values for this
      operation.
    ctx: The value of context.context().
    cancellation_manager: a `CancellationManager` object that can be used to
      cancel the operation.
    name: Customized name for the operation.

  Returns:
    List of output Tensor objects. The list is empty if there are no outputs

  Raises:
    An exception on error.
  Nr   r   )r   r   r   TFE_Py_ExecuteCancelabler   _implr   r   r   r   r   r   r   r   )r   r   r   r   r   cancellation_managerr   r   r   r    r!   r"   s               r#   execute_with_cancellationr)   F   s    : +11#++{29652F2L2L2=?G  
. 
	#	# 1ii9t##i

#
#A
&D0	 )/PA3LQ3OaPPP##""(&)?"@B B Gs5   ?A C,"0BC,C'"B83B870C''C,c                 r    t        | |||||      }|j                  D ]  } || t        |      |||        |S )z6Monkey-patch to execute to enable execution callbacks.)r$   op_callbackstuple)r   r   r   r   r   r   r   callbacks           r#   execute_with_callbacksr.   z   sF    ';sDI'"" ;hWeFmUGT:; 
.    c                       y)/Import backprop if you want gradients recorded.F r2   r/   r#   must_record_gradientr3      s    	r/   c                      y)r1   Nr2   )unused_op_nameunused_inputsunused_attrsunused_outputss       r#   record_gradientr9      s     r/   c                     t        | t        j                        st        d|dt	        |       d      t        |       S )NzExpected float for argument '' not .)
isinstancer
   
real_typesr   reprfloatvarg_names     r#   
make_floatrD      s6    	Av((	)
tAw( ) )	q/r/   c           	          t        | t              rt        d|dt        |       d      	 t	        |       S # t
        t        f$ r t        d|dt        |       d      w xY w)NzExpected int for argument 'r;   r<   )r=   strr   r?   int
ValueErrorrA   s     r#   make_intrI      sd    3
tAw( ) ))q6M
i	  )
tAw( ) ))s	   
8 +A#c                     t        | t        j                        st        d|dt	        |       d      t        j
                  |       S )NzExpected string for argument 'r;   r<   )r=   r
   bytes_or_text_typesr   r?   as_bytesrA   s     r#   make_strrM      s<    	Av11	2
tAw( ) )		r/   c                 \    t        | t              st        d|dt        |       d      | S )NzExpected bool for argument 'r;   r<   )r=   boolr   r?   rA   s     r#   	make_boolrP      s,    	At	
tAw( ) )	
(r/   c           	          	 t        j                  |       j                  } | j
                  }|S # t        $ r t        d|dt	        |       d      w xY w)Nz Expected DataType for argument 'r;   r<   )r   as_dtype
base_dtyper   r?   as_datatype_enum)rB   rC   is      r#   	make_typerV      sY    )%%A !	
(	 
 )
tAw( ) ))s	   / %Ac                     	 t        j                  |       }|j                  y|j                         S # t        $ r}t        d|d|d      d}~wt        $ r}t        d|d|d      d}~ww xY w)zConvert v into a list.zError converting z to a TensorShape: r<   N)r	   as_shaper   rH   ndimsas_list)rB   rC   shaper    s       r#   
make_shaper\      su    $!!!$E [[==? 
 Q
8QO
PP	 $
# $ $$s    4 	A2AA2A--A2c                     t        | t        j                        r| S t        | t              r,t        j                         }t	        j
                  | |       |S t        dt        |       d|d      )zEnsure v is a TensorProto.zDon't know how to convert z  to a TensorProto for argument 'z'.)r=   r   TensorProtorF   r   Merger   r?   )rB   rC   pbs      r#   make_tensorra      s_    :))*H!S				!BaIAw	 r/   c                    ~| s||g fS | D ]  }t        |t        j                        r n | d   j                         | fS d}| D ]*  }t        |t        j                        s|j                  } n |og }| D ]g  }d}|'|r%t        j                  |      }|j                  |vrd}|t        j                  |||      }|j                  |       |\|j                  }i n#| D cg c]  }t        j                  ||       }}|D cg c]  }t        |      s| }	}|	r$t        j                  dj                  |	            |j                  |fS c c}w c c}w )z0Convert sequence `l` to eager same-type Tensors.Nr   )preferred_dtypez@Using symbolic output of a Keras layer during eager execution {})r=   
core_typesValue_datatype_enumdtyper   convertappendr   r   r   r   rT   )
lr   allowed_dtypesdefault_dtyper!   rg   trettensorr"   s
             r#   args_to_matching_eagerrp      s   	
-+" $aa))*$ Q4 !## % a!Z%%&gge
 ] C f 
>+33A6 <<~-&	+33um
 
jj	), BC
CA%--a7
CC
C (+K!.G.JAKK

!
!	V*+- - 
			$$ D Ls   (EEEc                     ~| D cg c]  }t        j                  |       }}|D cg c]  }|j                          }}||fS c c}w c c}w N)r   rh   rf   )valuesr   rm   rB   typess        r#   convert_to_mixed_eager_tensorsru     sQ    	6<=!))!,=!='(
)!1
)%
)	/ >
)s
   AA
c                 z   ~t        |       dkD  sJ g g}| dd D ]W  }t        |      t        | d         k7  r*t        dt        | d         t        |      | d   |fz        |j                  g        Y g }t        t        | d               D ](  }d}| D ]0  }t	        ||   t
        j                        s!||   j                  } n ||d   j                  t        j                  | d   |                |d   |   j                  }t        dt        |             D ]1  }||   j                  t        j                  | |   |   |             3 nHt        t        |             D ]1  }||   j                  t        j                  | |   |   |             3 |j                  |j                         + ||fS )z@Converts a list of same-length lists of values to eager tensors.   Nr   zDExpected list arguments to be the same length: %d != %d (%r vs. %r).)rg   )lenrH   ri   ranger=   rd   re   rg   r   rh   rT   )listsr   	lists_retrj   rt   rU   rg   js           r#   args_to_mixed_eager_tensorsr}     s   		Ua d)9 a
1vU1X
Pq]CFE!Ha012 2 R %U1X )aE 	AaD***	+!

 }l4<<U1Xa[IJl1o##eQE
# 
!!&..uQx{%H	

 SZ  
!!&..uQx{%H	

 
LL''(+), 
		r/   c                 R    t        | d      xr t        | j                  dd       dk(  S )Ngraphr   keras_graph)hasattrgetattrr   )r!   s    r#   r   r   H  s&    	G		P&$!?=!PPr/   rr   )"__doc__google.protobufr   tensorflow.core.frameworkr   tensorflow.pythonr   tensorflow.python.eagerr   tensorflow.python.frameworkr   r   r	   tensorflow.python.typesrd   tensorflow.python.utilr
   r$   r)   r.   executer3   r9   rD   rI   rM   rP   rV   r\   ra   rp   ru   r}   r   r2   r/   r#   <module>r      s    J ' 0 ( ( . B 4 6 )'` $(1h 
),
7%t&RQr/   