parameters: (op, grad)
return_statement: return indices_grad + values_grad
docstring: Gradients for DynamicStitch.
docstring_summary: Gradients for DynamicStitch.
docstring_tokens: Gradients for DynamicStitch .
function: def _DynamicStitchGrads(op, grad):
    """Gradients for DynamicStitch."""
  
    num_values = len(op.inputs) // 2
    indices_grad = [None] * num_values
  
    def AsInt32(x):
      return (x if op.inputs[0].dtype == dtypes.int32 else
              math_ops.cast(x, dtypes.int32))
    inputs = [AsInt32(op.inputs[i]) for i in xrange(num_values)]
    if isinstance(grad, ops.IndexedSlices):
      output_shape = array_ops.shape(op.outputs[0])
      output_rows = output_shape[0]
      grad = math_ops.unsorted_segment_sum(grad.values, grad.indices, output_rows)
    values_grad = [array_ops.gather(grad, inp) for inp in inputs]
    return indices_grad + values_grad
function_tokens: def _DynamicStitchGrads ( op , grad ) : num_values = len ( op . inputs ) // 2 indices_grad = [ None ] * num_values def AsInt32 ( x ) : return ( x if op . inputs [ 0 ] . dtype == dtypes . int32 else math_ops . cast ( x , dtypes . int32 ) ) inputs = [ AsInt32 ( op . inputs [ i ] ) for i in xrange ( num_values ) ] if isinstance ( grad , ops . IndexedSlices ) : output_shape = array_ops . shape ( op . outputs [ 0 ] ) output_rows = output_shape [ 0 ] grad = math_ops . unsorted_segment_sum ( grad . values , grad . indices , output_rows ) values_grad = [ array_ops . gather ( grad , inp ) for inp in inputs ] return indices_grad + values_grad