parameters: (func, op_name, clazz_object=ops.Tensor)
docstring: Register operators with different tensor and scalar versions.
  
    If `clazz_object` is `SparseTensor`, assumes `func` takes `(sp_indices,
    sp_values, sp_shape, dense)` and outputs `(new_sp_values)`.
  
    Args:
      func: the operator
      op_name: name of the operator being overridden
      clazz_object: class to override for.  Either `Tensor` or `SparseTensor`.
docstring_summary: Register operators with different tensor and scalar versions.
docstring_tokens: Register operators with different tensor and scalar versions .
function: def _OverrideBinaryOperatorHelper(func, op_name, clazz_object=ops.Tensor):
    """Register operators with different tensor and scalar versions.
  
    If `clazz_object` is `SparseTensor`, assumes `func` takes `(sp_indices,
    sp_values, sp_shape, dense)` and outputs `(new_sp_values)`.
  
    Args:
      func: the operator
      op_name: name of the operator being overridden
      clazz_object: class to override for.  Either `Tensor` or `SparseTensor`.
    """
  
    def binary_op_wrapper(x, y):
      with ops.name_scope(None, op_name, [x, y]) as name:
        if not isinstance(y, sparse_tensor.SparseTensor):
          try:
            y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
          except TypeError:
            # If the RHS is not a tensor, it might be a tensor aware object
            # that can implement the operator with knowledge of itself
            # and the tensor.
            if hasattr(type(y), "__r%s__" % op_name):
              return NotImplemented
            else:
              raise
        return func(x, y, name=name)
  
    def binary_op_wrapper_sparse(sp_x, y):
      with ops.name_scope(None, op_name, [sp_x, y]) as name:
        y = ops.convert_to_tensor(y, dtype=sp_x.dtype.base_dtype, name="y")
        return sparse_tensor.SparseTensor(sp_x.indices,
                                          func(
                                              sp_x.indices,
                                              sp_x.values,
                                              sp_x.dense_shape,
                                              y,
                                              name=name), sp_x.dense_shape)
  
    def r_binary_op_wrapper(y, x):
      with ops.name_scope(None, op_name, [x, y]) as name:
        x = ops.convert_to_tensor(x, dtype=y.dtype.base_dtype, name="x")
        return func(x, y, name=name)
  
    # Propagate func.__doc__ to the wrappers
    try:
      doc = func.__doc__
    except AttributeError:
      doc = None
    binary_op_wrapper.__doc__ = doc
    r_binary_op_wrapper.__doc__ = doc
    binary_op_wrapper_sparse.__doc__ = doc
  
    if clazz_object is ops.Tensor:
      clazz_object._override_operator("__%s__" % op_name, binary_op_wrapper)
      del binary_op_wrapper
      clazz_object._override_operator("__r%s__" % op_name, r_binary_op_wrapper)
      del r_binary_op_wrapper
    else:
      clazz_object._override_operator("__%s__" % op_name,
                                      binary_op_wrapper_sparse)
      del binary_op_wrapper_sparse
function_tokens: def _OverrideBinaryOperatorHelper ( func , op_name , clazz_object = ops . Tensor ) : def binary_op_wrapper ( x , y ) : with ops . name_scope ( None , op_name , [ x , y ] ) as name : if not isinstance ( y , sparse_tensor . SparseTensor ) : try : y = ops . convert_to_tensor ( y , dtype = x . dtype . base_dtype , name = "y" ) except TypeError : # If the RHS is not a tensor, it might be a tensor aware object # that can implement the operator with knowledge of itself # and the tensor. if hasattr ( type ( y ) , "__r%s__" % op_name ) : return NotImplemented else : raise return func ( x , y , name = name ) def binary_op_wrapper_sparse ( sp_x , y ) : with ops . name_scope ( None , op_name , [ sp_x , y ] ) as name : y = ops . convert_to_tensor ( y , dtype = sp_x . dtype . base_dtype , name = "y" ) return sparse_tensor . SparseTensor ( sp_x . indices , func ( sp_x . indices , sp_x . values , sp_x . dense_shape , y , name = name ) , sp_x . dense_shape ) def r_binary_op_wrapper ( y , x ) : with ops . name_scope ( None , op_name , [ x , y ] ) as name : x = ops . convert_to_tensor ( x , dtype = y . dtype . base_dtype , name = "x" ) return func ( x , y , name = name ) # Propagate func.__doc__ to the wrappers try : doc = func . __doc__ except AttributeError : doc = None binary_op_wrapper . __doc__ = doc r_binary_op_wrapper . __doc__ = doc binary_op_wrapper_sparse . __doc__ = doc if clazz_object is ops . Tensor : clazz_object . _override_operator ( "__%s__" % op_name , binary_op_wrapper ) del binary_op_wrapper clazz_object . _override_operator ( "__r%s__" % op_name , r_binary_op_wrapper ) del r_binary_op_wrapper else : clazz_object . _override_operator ( "__%s__" % op_name , binary_op_wrapper_sparse ) del binary_op_wrapper_sparse