parameters: (x, bias, data_format=None)
return_statement: return x
docstring: Adds a bias vector to a tensor.
  
    Arguments:
        x: Tensor or variable.
        bias: Bias tensor to add.
        data_format: string, `"channels_last"` or `"channels_first"`.
  
    Returns:
        Output tensor.
  
    Raises:
        ValueError: In one of the two cases below:
                    1. invalid `data_format` argument.
                    2. invalid bias shape.
                       the bias should be either a vector or
                       a tensor with ndim(x) - 1 dimension
docstring_summary: Adds a bias vector to a tensor.
docstring_tokens: Adds a bias vector to a tensor .
function: def bias_add(x, bias, data_format=None):
    """Adds a bias vector to a tensor.
  
    Arguments:
        x: Tensor or variable.
        bias: Bias tensor to add.
        data_format: string, `"channels_last"` or `"channels_first"`.
  
    Returns:
        Output tensor.
  
    Raises:
        ValueError: In one of the two cases below:
                    1. invalid `data_format` argument.
                    2. invalid bias shape.
                       the bias should be either a vector or
                       a tensor with ndim(x) - 1 dimension
    """
    if data_format is None:
      data_format = image_data_format()
    if data_format not in {'channels_first', 'channels_last'}:
      raise ValueError('Unknown data_format ' + str(data_format))
    bias_shape = int_shape(bias)
    if len(bias_shape) != 1 and len(bias_shape) != ndim(x) - 1:
      raise ValueError(
          'Unexpected bias dimensions %d, expect to be 1 or %d dimensions' %
          (len(bias_shape), ndim(x)))
    if ndim(x) == 5:
      if data_format == 'channels_first':
        if len(bias_shape) == 1:
          x += reshape(bias, (1, bias_shape[0], 1, 1, 1))
        else:
          x += reshape(bias, (1, bias_shape[3]) + bias_shape[:3])
      elif data_format == 'channels_last':
        if len(bias_shape) == 1:
          x += reshape(bias, (1, 1, 1, bias_shape[0]))
        else:
          x += reshape(bias, (1,) + bias_shape)
    elif ndim(x) == 4:
      if data_format == 'channels_first':
        if len(bias_shape) == 1:
          x += reshape(bias, (1, bias_shape[0], 1, 1))
        else:
          x += reshape(bias, (1, bias_shape[2]) + bias_shape[:2])
      elif data_format == 'channels_last':
        if len(bias_shape) == 1:
          x = nn.bias_add(x, bias, data_format='NHWC')
        else:
          x += reshape(bias, (1,) + bias_shape)
    elif ndim(x) == 3:
      if data_format == 'channels_first':
        if len(bias_shape) == 1:
          x += reshape(bias, (1, bias_shape[0], 1))
        else:
          x += reshape(bias, (1, bias_shape[1], bias_shape[0]))
      elif data_format == 'channels_last':
        if len(bias_shape) == 1:
          x += reshape(bias, (1, 1, bias_shape[0]))
        else:
          x += reshape(bias, (1,) + bias_shape)
    else:
      x = nn.bias_add(x, bias)
    return x
function_tokens: def bias_add ( x , bias , data_format = None ) : if data_format is None : data_format = image_data_format ( ) if data_format not in { 'channels_first' , 'channels_last' } : raise ValueError ( 'Unknown data_format ' + str ( data_format ) ) bias_shape = int_shape ( bias ) if len ( bias_shape ) != 1 and len ( bias_shape ) != ndim ( x ) - 1 : raise ValueError ( 'Unexpected bias dimensions %d, expect to be 1 or %d dimensions' % ( len ( bias_shape ) , ndim ( x ) ) ) if ndim ( x ) == 5 : if data_format == 'channels_first' : if len ( bias_shape ) == 1 : x += reshape ( bias , ( 1 , bias_shape [ 0 ] , 1 , 1 , 1 ) ) else : x += reshape ( bias , ( 1 , bias_shape [ 3 ] ) + bias_shape [ : 3 ] ) elif data_format == 'channels_last' : if len ( bias_shape ) == 1 : x += reshape ( bias , ( 1 , 1 , 1 , bias_shape [ 0 ] ) ) else : x += reshape ( bias , ( 1 , ) + bias_shape ) elif ndim ( x ) == 4 : if data_format == 'channels_first' : if len ( bias_shape ) == 1 : x += reshape ( bias , ( 1 , bias_shape [ 0 ] , 1 , 1 ) ) else : x += reshape ( bias , ( 1 , bias_shape [ 2 ] ) + bias_shape [ : 2 ] ) elif data_format == 'channels_last' : if len ( bias_shape ) == 1 : x = nn . bias_add ( x , bias , data_format = 'NHWC' ) else : x += reshape ( bias , ( 1 , ) + bias_shape ) elif ndim ( x ) == 3 : if data_format == 'channels_first' : if len ( bias_shape ) == 1 : x += reshape ( bias , ( 1 , bias_shape [ 0 ] , 1 ) ) else : x += reshape ( bias , ( 1 , bias_shape [ 1 ] , bias_shape [ 0 ] ) ) elif data_format == 'channels_last' : if len ( bias_shape ) == 1 : x += reshape ( bias , ( 1 , 1 , bias_shape [ 0 ] ) ) else : x += reshape ( bias , ( 1 , ) + bias_shape ) else : x = nn . bias_add ( x , bias ) return x