parameters: (value, expected_rank)
docstring: Check the rank of Tensor `value`, via shape inference and assertions.
  
    Args:
      value: A Tensor, possibly with shape associated shape information.
      expected_rank: int32 scalar (optionally a `Tensor`).
  
    Returns:
      new_value: A Tensor matching `value`.  Accessing this tensor tests
        assertions on its rank.  If expected_rank is not a `Tensor`, then
        new_value's shape's rank has been set.
  
    Raises:
      ValueError: if `expected_rank` is not a `Tensor` and the rank of `value`
        is known and is not equal to `expected_rank`.
docstring_summary: Check the rank of Tensor `value`, via shape inference and assertions.
docstring_tokens: Check the rank of Tensor value via shape inference and assertions .
function: def _check_rank(value, expected_rank):
    """Check the rank of Tensor `value`, via shape inference and assertions.
  
    Args:
      value: A Tensor, possibly with shape associated shape information.
      expected_rank: int32 scalar (optionally a `Tensor`).
  
    Returns:
      new_value: A Tensor matching `value`.  Accessing this tensor tests
        assertions on its rank.  If expected_rank is not a `Tensor`, then
        new_value's shape's rank has been set.
  
    Raises:
      ValueError: if `expected_rank` is not a `Tensor` and the rank of `value`
        is known and is not equal to `expected_rank`.
    """
    assert isinstance(value, ops.Tensor)
    with ops.control_dependencies([
        control_flow_ops.Assert(
            math_ops.equal(expected_rank, array_ops.rank(value)), [
                string_ops.string_join([
                    "Rank of tensor %s should be: " % value.name,
                    string_ops.as_string(expected_rank), ", shape received:"
                ]), array_ops.shape(value)
            ])
    ]):
      new_value = array_ops.identity(value, name="rank_checked")
      if isinstance(expected_rank, ops.Tensor):
        expected_rank_value = tensor_util.constant_value(expected_rank)
        if expected_rank_value is not None:
          expected_rank = int(expected_rank_value)
      if not isinstance(expected_rank, ops.Tensor):
        try:
          new_value.set_shape(new_value.get_shape().with_rank(expected_rank))
        except ValueError as e:
          raise ValueError("Rank check failed for %s: %s" % (value.name, str(e)))
      return new_value
function_tokens: def _check_rank ( value , expected_rank ) : assert isinstance ( value , ops . Tensor ) with ops . control_dependencies ( [ control_flow_ops . Assert ( math_ops . equal ( expected_rank , array_ops . rank ( value ) ) , [ string_ops . string_join ( [ "Rank of tensor %s should be: " % value . name , string_ops . as_string ( expected_rank ) , ", shape received:" ] ) , array_ops . shape ( value ) ] ) ] ) : new_value = array_ops . identity ( value , name = "rank_checked" ) if isinstance ( expected_rank , ops . Tensor ) : expected_rank_value = tensor_util . constant_value ( expected_rank ) if expected_rank_value is not None : expected_rank = int ( expected_rank_value ) if not isinstance ( expected_rank , ops . Tensor ) : try : new_value . set_shape ( new_value . get_shape ( ) . with_rank ( expected_rank ) ) except ValueError as e : raise ValueError ( "Rank check failed for %s: %s" % ( value . name , str ( e ) ) ) return new_value