message: Check dtype after convert_to_tensor
diff: @@ -762,22 +762,22 @@ def cast(x, dtype, name=None):
  Raises:
  TypeError: If `x` cannot be cast to the `dtype`.
  """
  - if x.dtype.is_complex and dtype.is_floating:
  - logging.warn("Casting complex to real discards imaginary part.")
  base_type = dtypes.as_dtype(dtype).base_dtype
  with ops.name_scope(name, "Cast", [x]) as name:
  if isinstance(x, sparse_tensor.SparseTensor):
  values_cast = cast(x.values, base_type, name=name)
  - return sparse_tensor.SparseTensor(x.indices, values_cast, x.dense_shape)
  + x = sparse_tensor.SparseTensor(x.indices, values_cast, x.dense_shape)
  else:
  # TODO(josh11b): If x is not already a Tensor, we could return
  # ops.convert_to_tensor(x, dtype=dtype, ...) here, but that
  # allows some conversions that cast() can't do, e.g. casting numbers to
  # strings.
  x = ops.convert_to_tensor(x, name="x")
  - if x.dtype.base_dtype == base_type:
  + if x.dtype.base_dtype != base_type:
  + x = gen_math_ops.cast(x, base_type, name=name)
  + if x.dtype.is_complex and dtype.is_floating:
  + logging.warn("Casting complex to real discards imaginary part.")
  return x
  - return gen_math_ops.cast(x, base_type, name=name)
  @tf_export("saturate_cast")
  