parameters: (feature, squared=False)
return_statement: return pairwise_distances
docstring: Computes the pairwise distance matrix with numerical stability.
  
    output[i, j] = || feature[i, :] - feature[j, :] ||_2
  
    Args:
      feature: 2-D Tensor of size [number of data, feature dimension].
      squared: Boolean, whether or not to square the pairwise distances.
  
    Returns:
      pairwise_distances: 2-D Tensor of size [number of data, number of data].
docstring_summary: Computes the pairwise distance matrix with numerical stability.
docstring_tokens: Computes the pairwise distance matrix with numerical stability .
function: def pairwise_distance(feature, squared=False):
    """Computes the pairwise distance matrix with numerical stability.
  
    output[i, j] = || feature[i, :] - feature[j, :] ||_2
  
    Args:
      feature: 2-D Tensor of size [number of data, feature dimension].
      squared: Boolean, whether or not to square the pairwise distances.
  
    Returns:
      pairwise_distances: 2-D Tensor of size [number of data, number of data].
    """
    pairwise_distances_squared = math_ops.add(
        math_ops.reduce_sum(
            math_ops.square(feature),
            axis=[1],
            keep_dims=True),
        math_ops.reduce_sum(
            math_ops.square(
                array_ops.transpose(feature)),
            axis=[0],
            keep_dims=True)) - 2.0 * math_ops.matmul(
                feature, array_ops.transpose(feature))
  
    # Deal with numerical inaccuracies. Set small negatives to zero.
    pairwise_distances_squared = math_ops.maximum(pairwise_distances_squared, 0.0)
    # Get the mask where the zero distances are at.
    error_mask = math_ops.less_equal(pairwise_distances_squared, 0.0)
  
    # Optionally take the sqrt.
    if squared:
      pairwise_distances = pairwise_distances_squared
    else:
      pairwise_distances = math_ops.sqrt(
          pairwise_distances_squared + math_ops.to_float(error_mask) * 1e-16)
  
    # Undo conditionally adding 1e-16.
    pairwise_distances = math_ops.multiply(
        pairwise_distances, math_ops.to_float(math_ops.logical_not(error_mask)))
  
    num_data = array_ops.shape(feature)[0]
    # Explicitly set diagonals to zero.
    mask_offdiagonals = array_ops.ones_like(pairwise_distances) - array_ops.diag(
        array_ops.ones([num_data]))
    pairwise_distances = math_ops.multiply(pairwise_distances, mask_offdiagonals)
    return pairwise_distances
function_tokens: def pairwise_distance ( feature , squared = False ) : pairwise_distances_squared = math_ops . add ( math_ops . reduce_sum ( math_ops . square ( feature ) , axis = [ 1 ] , keep_dims = True ) , math_ops . reduce_sum ( math_ops . square ( array_ops . transpose ( feature ) ) , axis = [ 0 ] , keep_dims = True ) ) - 2.0 * math_ops . matmul ( feature , array_ops . transpose ( feature ) ) # Deal with numerical inaccuracies. Set small negatives to zero. pairwise_distances_squared = math_ops . maximum ( pairwise_distances_squared , 0.0 ) # Get the mask where the zero distances are at. error_mask = math_ops . less_equal ( pairwise_distances_squared , 0.0 ) # Optionally take the sqrt. if squared : pairwise_distances = pairwise_distances_squared else : pairwise_distances = math_ops . sqrt ( pairwise_distances_squared + math_ops . to_float ( error_mask ) * 1e-16 ) # Undo conditionally adding 1e-16. pairwise_distances = math_ops . multiply ( pairwise_distances , math_ops . to_float ( math_ops . logical_not ( error_mask ) ) ) num_data = array_ops . shape ( feature ) [ 0 ] # Explicitly set diagonals to zero. mask_offdiagonals = array_ops . ones_like ( pairwise_distances ) - array_ops . diag ( array_ops . ones ( [ num_data ] ) ) pairwise_distances = math_ops . multiply ( pairwise_distances , mask_offdiagonals ) return pairwise_distances