
    AVh>                        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  ej                  d      d	        Z
 ej                  d
       ej                  d      d               Z ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d        ej                  d       y)z4Gradients for operators defined in data_flow_ops.py.    )dtypes)indexed_slices)ops)	array_ops)data_flow_ops)math_opsDynamicPartitionc                    | j                   d   }| j                   d   }| j                  d      }t        j                  |      }t        j                  t        j                  t        j                  |            |      }t        j                  |||      }t        j                  ||      }t        j                  |t        j                  |            }|dgS )zGradients for DynamicPartition.r      num_partitionsN)inputsget_attrr   shapereshaper   rangereduce_prodr   dynamic_partitionparallel_dynamic_stitch)	opgradsdataindicesr   prefix_shapeoriginal_indicespartitioned_indicesreconstructeds	            T/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/data_flow_grad.py_DynamicPartitionGradsr      s     
1$IIaL';;/0.),&&nnX)),78,H%771778K8=?-##M9??43HI-
	    DynamicStitchParallelDynamicStitchc                     t         j                        dz  }dg|z  } fd}t        |      D cg c]  } | j                  |          }}t        |t        j
                        rRt        j                   j                  d         }|d   }t        j                  |j                  |j                  |      }|D 	cg c]  }	t        j                  ||	       }
}	||
z   S c c}w c c}	w )z6Gradients for DynamicStitch and ParallelDynamicStitch.   Nc                     j                   d   j                  t        j                  k(  r| S t	        j
                  | t        j                        S )Nr   )r   dtyper   int32r   cast)xr   s    r   AsInt32z$_DynamicStitchGrads.<locals>.AsInt324   s;    1##v||3A ,MM!V\\*,r   r   )lenr   r   
isinstancer   IndexedSlicesr   r   outputsr   unsorted_segment_sumvaluesr   gather)r   grad
num_valuesindices_gradr)   ir   output_shapeoutput_rowsinpvalues_grads   `          r   _DynamicStitchGradsr9   ,   s    
 299~"**$,, ,1+<=aGBIIaL!=&=n223??2::a=1Lq/K((dllKPD8>?!!$,?+?		## >
 @s   C$ C)QueueQueueEnqueueQueueEnqueueManyQueueDequeueQueueDequeueManyQueueDequeueUpTo
QueueClose	QueueSizeStack	StackPushStackPop
StackCloseGetSessionHandleGetSessionHandleV2GetSessionTensorDeleteSessionTensorN)__doc__tensorflow.python.frameworkr   r   r   tensorflow.python.opsr   r   r   RegisterGradientr   r9   NotDifferentiable r   r   <module>rP      s~    ; . 6 + + / * () *" o&-.$ / '$&   g    n %   ( )   n %   ( )   ( )   l #   k "   g    k "   j !   l #   ( )   * +   ( )   + ,r   