MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / rank_internal

Function rank_internal

tensorflow/python/ops/array_ops.py:609–630  ·  view source on GitHub ↗

Returns the rank of a tensor. Args: input: A `Tensor` or `SparseTensor`. name: A name for the operation (optional). optimize: if true, encode the rank as a constant when possible. Returns: A `Tensor` of type `int32`.

(input, name=None, optimize=True)

Source from the content-addressed store, hash-verified

607
608
609def rank_internal(input, name=None, optimize=True):
610 # pylint: disable=redefined-builtin
611 """Returns the rank of a tensor.
612
613 Args:
614 input: A `Tensor` or `SparseTensor`.
615 name: A name for the operation (optional).
616 optimize: if true, encode the rank as a constant when possible.
617
618 Returns:
619 A `Tensor` of type `int32`.
620 """
621 with ops.name_scope(name, "Rank", [input]) as name:
622 if isinstance(
623 input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
624 return gen_array_ops.size(input.dense_shape, name=name)
625 else:
626 input_tensor = ops.convert_to_tensor(input)
627 input_shape = input_tensor.get_shape()
628 if optimize and input_shape.ndims is not None:
629 return constant(input_shape.ndims, dtypes.int32, name=name)
630 return gen_array_ops.rank(input, name=name)
631
632
633_SLICE_TYPE_ERROR = (

Callers 1

rankFunction · 0.85

Calls 5

constantFunction · 0.90
name_scopeMethod · 0.45
sizeMethod · 0.45
get_shapeMethod · 0.45
rankMethod · 0.45

Tested by

no test coverage detected